Draw Manager: replace varargs with a pointer array
authorCampbell Barton <ideasman42@gmail.com>
Tue, 11 Apr 2017 11:19:23 +0000 (21:19 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 11 Apr 2017 11:20:18 +0000 (21:20 +1000)
Allows to ensure correct number of args

source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_manager.c

index 7475e562833dccf479a393da517c891298fb7899..a19e0c71155b995e7959207058464c06bfd2b9c4 100644 (file)
@@ -211,7 +211,12 @@ DRWShadingGroup *DRW_shgroup_line_batch_create(struct GPUShader *shader, DRWPass
 
 void DRW_shgroup_free(struct DRWShadingGroup *shgroup);
 void DRW_shgroup_call_add(DRWShadingGroup *shgroup, struct Batch *geom, float (*obmat)[4]);
-void DRW_shgroup_dynamic_call_add(DRWShadingGroup *shgroup, ...);
+void DRW_shgroup_dynamic_call_add_array(DRWShadingGroup *shgroup, const void **attr, unsigned int attr_len);
+#define DRW_shgroup_dynamic_call_add(shgroup, ...) do { \
+       const void *array[] = {__VA_ARGS__}; \
+       DRW_shgroup_dynamic_call_add_array(shgroup, array, (sizeof(array) / sizeof(*array))); \
+} while (0)
+
 void DRW_shgroup_state_set(DRWShadingGroup *shgroup, DRWState state);
 void DRW_shgroup_attrib_int(DRWShadingGroup *shgroup, const char *name, int size);
 void DRW_shgroup_attrib_float(DRWShadingGroup *shgroup, const char *name, int size);
index b5ed450cb0a9f8dcfb87605ff6276458f4188bb3..1260decb071a3e7c799de3489ce2a2db9a2ae904 100644 (file)
@@ -572,20 +572,17 @@ void DRW_shgroup_call_add(DRWShadingGroup *shgroup, Batch *geom, float (*obmat)[
        BLI_addtail(&shgroup->calls, call);
 }
 
-void DRW_shgroup_dynamic_call_add(DRWShadingGroup *shgroup, ...)
+void DRW_shgroup_dynamic_call_add_array(DRWShadingGroup *shgroup, const void *attr[], unsigned int attr_len)
 {
-       va_list params;
-       int i;
        DRWInterface *interface = shgroup->interface;
-       int size = sizeof(ListBase) + sizeof(void *) * interface->attribs_count;
+       unsigned int data_size = sizeof(void *) * interface->attribs_count;
+       int size = sizeof(ListBase) + data_size;
 
        DRWDynamicCall *call = MEM_callocN(size, "DRWDynamicCall");
 
-       va_start(params, shgroup);
-       for (i = 0; i < interface->attribs_count; ++i) {
-               call->data[i] = va_arg(params, void *);
-       }
-       va_end(params);
+       BLI_assert(attr_len == interface->attribs_count);
+
+       memcpy(call->data, attr, data_size);
 
        interface->instance_count += 1;