[Bf-blender-cvs] [01745051de7] blender2.8: DRW: Add DRW_shgroup_create_sub to create children shgroup

Clément Foucault noreply at git.blender.org
Fri Oct 12 16:51:32 CEST 2018


Commit: 01745051de735c37a2d817c1a58fda4585b77698
Author: Clément Foucault
Date:   Thu Oct 11 15:50:46 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB01745051de735c37a2d817c1a58fda4585b77698

DRW: Add DRW_shgroup_create_sub to create children shgroup

This makes is easy to create nested drawcalls that will inherit all the
parents properties. This is usefull if only a few uniforms changes for that
drawcall.

===================================================================

M	source/blender/blenlib/BLI_link_utils.h
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_manager.h
M	source/blender/draw/intern/draw_manager_data.c

===================================================================

diff --git a/source/blender/blenlib/BLI_link_utils.h b/source/blender/blenlib/BLI_link_utils.h
index 5322547ac08..7a1a13a6b31 100644
--- a/source/blender/blenlib/BLI_link_utils.h
+++ b/source/blender/blenlib/BLI_link_utils.h
@@ -47,6 +47,15 @@
 	(list)->last = link; \
 } (void)0
 
+/* Use for inserting after a certain element. */
+#define BLI_LINKS_INSERT_AFTER(list, node, link)  { \
+	if ((node)->next == NULL) { \
+		(list)->last = link; \
+	} \
+	(link)->next = (node)->next; \
+	(node)->next = link; \
+} (void)0
+
 #define BLI_LINKS_FREE(list)  { \
 	while (list) { \
 		void *next = list->next; \
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 77b8cdacb47..17304dde802 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -325,6 +325,7 @@ struct GPUVertFormat *DRW_shgroup_instance_format_array(const DRWInstanceAttribF
 } while (0)
 
 DRWShadingGroup *DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass);
+DRWShadingGroup *DRW_shgroup_create_sub(DRWShadingGroup *shgroup);
 DRWShadingGroup *DRW_shgroup_material_create(struct GPUMaterial *material, DRWPass *pass);
 DRWShadingGroup *DRW_shgroup_material_instance_create(
         struct GPUMaterial *material, DRWPass *pass, struct GPUBatch *geom, struct Object *ob,
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index bba98f5e102..c8a7816c402 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -263,12 +263,10 @@ struct DRWShadingGroup {
 	int objectinfo;
 	uint16_t matflag; /* Matrices needed, same as DRWCall.flag */
 
+	DRWPass *pass_parent; /* backlink to pass we're in */
 #ifndef NDEBUG
 	char attribs_count;
 #endif
-#if !defined(NDEBUG) || defined(USE_GPU_SELECT)
-	DRWPass *pass_parent; /* backlink to pass we're in */
-#endif
 #ifdef USE_GPU_SELECT
 	GPUVertBuf *inst_selectid;
 	int override_selectid; /* Override for single object instances. */
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index f0dbf138e50..3823d081adc 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -768,10 +768,7 @@ static DRWShadingGroup *drw_shgroup_create_ex(struct GPUShader *shader, DRWPass
 	shgroup->instance_geom = NULL;
 	shgroup->instance_vbo = NULL;
 #endif
-
-#if !defined(NDEBUG) || defined(USE_GPU_SELECT)
 	shgroup->pass_parent = pass;
-#endif
 
 	return shgroup;
 }
@@ -1035,6 +1032,23 @@ bool DRW_shgroup_is_empty(DRWShadingGroup *shgroup)
 	return true;
 }
 
+DRWShadingGroup *DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
+{
+	/* Remove this assertion if needed but implement the other cases first! */
+	BLI_assert(shgroup->type == DRW_SHG_NORMAL);
+
+	DRWShadingGroup *shgroup_new = BLI_mempool_alloc(DST.vmempool->shgroups);
+
+	*shgroup_new = *shgroup;
+	shgroup_new->uniforms = NULL; /* Not sure about that.. Should we copy them instead? */
+	shgroup_new->calls.first = NULL;
+	shgroup_new->calls.last = NULL;
+
+	BLI_LINKS_INSERT_AFTER(&shgroup->pass_parent->shgroups, shgroup, shgroup_new);
+
+	return shgroup;
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */



More information about the Bf-blender-cvs mailing list