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
This commit is contained in:
parent
984cd552f0
commit
8f05a547d5
|
@ -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))
|
||||
|
||||
|
|
Loading…
Reference in New Issue