[Bf-blender-cvs] [8f05a547d53] master: BMesh: Add additional attribute access macros
Martijn Versteegh
noreply at git.blender.org
Fri Apr 22 17:36:23 CEST 2022
Commit: 8f05a547d539feb4a8da35ee15239fa46ff38083
Author: Martijn Versteegh
Date: Fri Apr 22 10:35:17 2022 -0500
Branches: master
https://developer.blender.org/rB8f05a547d539feb4a8da35ee15239fa46ff38083
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
===================================================================
M source/blender/bmesh/bmesh_class.h
===================================================================
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))
More information about the Bf-blender-cvs
mailing list