DRW: Add DRW_shgroup_call_procedural_indirect()

Replaces `DRW_shgroup_call_procedural_triangles_indirect`.
This makes the indirect drawing more flexible.
Not all primitive types are supported but it is just a matter of adding
them.
This commit is contained in:
Clément Foucault
2022-08-02 20:35:35 +02:00
parent 9a52f1f720
commit 24a0015dbd
4 changed files with 45 additions and 7 deletions

View File

@@ -454,9 +454,10 @@ void DRW_shgroup_call_compute_indirect(DRWShadingGroup *shgroup, GPUStorageBuf *
void DRW_shgroup_call_procedural_points(DRWShadingGroup *sh, Object *ob, uint point_count);
void DRW_shgroup_call_procedural_lines(DRWShadingGroup *sh, Object *ob, uint line_count);
void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *sh, Object *ob, uint tri_count);
void DRW_shgroup_call_procedural_triangles_indirect(DRWShadingGroup *shgroup,
Object *ob,
GPUStorageBuf *indirect_buf);
void DRW_shgroup_call_procedural_indirect(DRWShadingGroup *shgroup,
GPUPrimType primitive_type,
Object *ob,
GPUStorageBuf *indirect_buf);
/**
* \warning Only use with Shaders that have `IN_PLACE_INSTANCES` defined.
* TODO: Should be removed.

View File

@@ -90,6 +90,7 @@ static struct DRWShapeCache {
GPUBatch *drw_procedural_verts;
GPUBatch *drw_procedural_lines;
GPUBatch *drw_procedural_tris;
GPUBatch *drw_procedural_tri_strips;
GPUBatch *drw_cursor;
GPUBatch *drw_cursor_only_circle;
GPUBatch *drw_fullscreen_quad;
@@ -208,6 +209,21 @@ GPUBatch *drw_cache_procedural_triangles_get(void)
return SHC.drw_procedural_tris;
}
GPUBatch *drw_cache_procedural_triangle_strips_get()
{
if (!SHC.drw_procedural_tri_strips) {
/* TODO(fclem): get rid of this dummy VBO. */
GPUVertFormat format = {0};
GPU_vertformat_attr_add(&format, "dummy", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
GPU_vertbuf_data_alloc(vbo, 1);
SHC.drw_procedural_tri_strips = GPU_batch_create_ex(
GPU_PRIM_TRI_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO);
}
return SHC.drw_procedural_tri_strips;
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@@ -693,6 +693,7 @@ void drw_resource_buffer_finish(DRWData *vmempool);
GPUBatch *drw_cache_procedural_points_get(void);
GPUBatch *drw_cache_procedural_lines_get(void);
GPUBatch *drw_cache_procedural_triangles_get(void);
GPUBatch *drw_cache_procedural_triangle_strips_get(void);
void drw_uniform_attrs_pool_update(struct GHash *table,
struct GPUUniformAttrList *key,

View File

@@ -1056,11 +1056,31 @@ void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *shgroup, Object *ob,
drw_shgroup_call_procedural_add_ex(shgroup, geom, ob, tri_count * 3);
}
void DRW_shgroup_call_procedural_triangles_indirect(DRWShadingGroup *shgroup,
Object *ob,
GPUStorageBuf *indirect_buf)
void DRW_shgroup_call_procedural_indirect(DRWShadingGroup *shgroup,
GPUPrimType primitive_type,
Object *ob,
GPUStorageBuf *indirect_buf)
{
struct GPUBatch *geom = drw_cache_procedural_triangles_get();
struct GPUBatch *geom = NULL;
switch (primitive_type) {
case GPU_PRIM_POINTS:
geom = drw_cache_procedural_points_get();
break;
case GPU_PRIM_LINES:
geom = drw_cache_procedural_lines_get();
break;
case GPU_PRIM_TRIS:
geom = drw_cache_procedural_triangles_get();
break;
case GPU_PRIM_TRI_STRIP:
geom = drw_cache_procedural_triangle_strips_get();
break;
default:
BLI_assert_msg(0,
"Unsupported primitive type in DRW_shgroup_call_procedural_indirect. Add new "
"one as needed.");
break;
}
if (G.f & G_FLAG_PICKSEL) {
drw_command_set_select_id(shgroup, NULL, DST.select_id);
}