Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMartijn Versteegh <Baardaap>2022-04-22 18:35:17 +0300
committerHans Goudey <h.goudey@me.com>2022-04-22 18:35:44 +0300
commit8f05a547d539feb4a8da35ee15239fa46ff38083 (patch)
tree39bbe158a425cfcdd5c048a93ebafb08dc8a760c /source
parent984cd552f0033c674b3cef6ec55d1facdcb81c2d (diff)
BMesh: Add additional attribute access macros
Add macros to get/set boolean attributes, to set float2/float3 attributes and to get float2/float3 attributes via pointer access. Needed for D14365 and further generic attribute integration. Differential Revision: https://developer.blender.org/D14708
Diffstat (limited to 'source')
-rw-r--r--source/blender/bmesh/bmesh_class.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h
index b9491a4913b..3e405064c5a 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -506,6 +506,18 @@ typedef bool (*BMLoopPairFilterFunc)(const BMLoop *, const BMLoop *, void *user_
#define BM_ELEM_CD_GET_INT(ele, offset) \
(BLI_assert(offset != -1), *((int *)((char *)(ele)->head.data + (offset))))
+#define BM_ELEM_CD_SET_BOOL(ele, offset, f) \
+ { \
+ CHECK_TYPE_NONCONST(ele); \
+ BLI_assert(offset != -1); \
+ *((bool *)((char *)(ele)->head.data + (offset))) = (f); \
+ } \
+ (void)0
+
+#define BM_ELEM_CD_GET_BOOL(ele, offset) \
+ (BLI_assert(offset != -1), *((bool *)((char *)(ele)->head.data + (offset))))
+
+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define BM_ELEM_CD_GET_VOID_P(ele, offset) \
(BLI_assert(offset != -1), \
@@ -530,6 +542,68 @@ typedef bool (*BMLoopPairFilterFunc)(const BMLoop *, const BMLoop *, void *user_
#define BM_ELEM_CD_GET_FLOAT(ele, offset) \
(BLI_assert(offset != -1), *((float *)((char *)(ele)->head.data + (offset))))
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+
+# define BM_ELEM_CD_GET_FLOAT_P(ele, offset) \
+ (BLI_assert(offset != -1), \
+ _Generic(ele, \
+ GENERIC_TYPE_ANY((float *)POINTER_OFFSET((ele)->head.data, offset), \
+ _BM_GENERIC_TYPE_ELEM_NONCONST), \
+ GENERIC_TYPE_ANY((const float *)POINTER_OFFSET((ele)->head.data, offset), \
+ _BM_GENERIC_TYPE_ELEM_CONST)))
+
+
+# define BM_ELEM_CD_GET_FLOAT2_P(ele, offset) \
+ (BLI_assert(offset != -1), \
+ _Generic(ele, \
+ GENERIC_TYPE_ANY((float (*)[2])POINTER_OFFSET((ele)->head.data, offset), \
+ _BM_GENERIC_TYPE_ELEM_NONCONST), \
+ GENERIC_TYPE_ANY((const float (*)[2])POINTER_OFFSET((ele)->head.data, offset), \
+ _BM_GENERIC_TYPE_ELEM_CONST)))
+
+# define BM_ELEM_CD_GET_FLOAT3_P(ele, offset) \
+ (BLI_assert(offset != -1), \
+ _Generic(ele, \
+ GENERIC_TYPE_ANY((float (*)[3])POINTER_OFFSET((ele)->head.data, offset), \
+ _BM_GENERIC_TYPE_ELEM_NONCONST), \
+ GENERIC_TYPE_ANY((const float (*)[3])POINTER_OFFSET((ele)->head.data, offset), \
+ _BM_GENERIC_TYPE_ELEM_CONST)))
+
+
+#else
+
+# define BM_ELEM_CD_GET_FLOAT_P(ele, offset) \
+ (BLI_assert(offset != -1), (float *)((char *)(ele)->head.data + (offset)))
+
+# define BM_ELEM_CD_GET_FLOAT2_P(ele, offset) \
+ (BLI_assert(offset != -1), (float (*)[2])((char *)(ele)->head.data + (offset)))
+
+# define BM_ELEM_CD_GET_FLOAT3_P(ele, offset) \
+ (BLI_assert(offset != -1), (float (*)[3])((char *)(ele)->head.data + (offset)))
+
+#endif
+
+
+
+#define BM_ELEM_CD_SET_FLOAT2(ele, offset, f) \
+ { \
+ CHECK_TYPE_NONCONST(ele); \
+ BLI_assert(offset != -1); \
+ ((float *)((char *)(ele)->head.data + (offset)))[0] = (f)[0]; \
+ ((float *)((char *)(ele)->head.data + (offset)))[1] = (f)[1]; \
+ } \
+ (void)0
+
+#define BM_ELEM_CD_SET_FLOAT3(ele, offset, f) \
+ { \
+ CHECK_TYPE_NONCONST(ele); \
+ BLI_assert(offset != -1); \
+ ((float *)((char *)(ele)->head.data + (offset)))[0] = (f)[0]; \
+ ((float *)((char *)(ele)->head.data + (offset)))[1] = (f)[1]; \
+ ((float *)((char *)(ele)->head.data + (offset)))[2] = (f)[2]; \
+ } \
+ (void)0
+
#define BM_ELEM_CD_GET_FLOAT_AS_UCHAR(ele, offset) \
(BLI_assert(offset != -1), (uchar)(BM_ELEM_CD_GET_FLOAT(ele, offset) * 255.0f))