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.
This commit is contained in:
Clément Foucault 2018-10-11 15:50:46 +02:00
parent 9b692ecabd
commit 01745051de
4 changed files with 28 additions and 6 deletions

View File

@ -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; \

View File

@ -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,

View File

@ -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. */

View File

@ -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;
}
/** \} */
/* -------------------------------------------------------------------- */