diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-05-25 13:43:02 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-30 13:25:20 +0300 |
commit | 3bc0cb08b82b9b3de7c0e6d66317f501922b0390 (patch) | |
tree | b2b090ac635fccfd4b0fe5bf07b23988ad513a7d /source | |
parent | 7b9a0ed8c47dfef03e8b21cafae3b5438bc93415 (diff) |
DRW: Add DRW_CALL_PROCEDURAL DRWCall type.
This mimics the behaviour of DRW_shgroup_empty_tri_batch_create and will
replace it eventually.
The advantage is that it's compatible with transform feedback.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 5 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 33 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 4 |
4 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 2b2a5bd3b48..e96594de590 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -329,6 +329,7 @@ DRWShadingGroup *DRW_shgroup_empty_tri_batch_create( DRWShadingGroup *DRW_shgroup_transform_feedback_create( struct GPUShader *shader, DRWPass *pass, struct Gwn_VertBuf *tf_target); + typedef void (DRWCallGenerateFn)( DRWShadingGroup *shgroup, void (*draw_fn)(DRWShadingGroup *shgroup, struct Gwn_Batch *geom), @@ -344,6 +345,9 @@ void DRW_shgroup_instance_batch(DRWShadingGroup *shgroup, struct Gwn_Batch *batc void DRW_shgroup_free(struct DRWShadingGroup *shgroup); void DRW_shgroup_call_add(DRWShadingGroup *shgroup, struct Gwn_Batch *geom, float (*obmat)[4]); void DRW_shgroup_call_object_add(DRWShadingGroup *shgroup, struct Gwn_Batch *geom, struct Object *ob); +void DRW_shgroup_call_procedural_points_add(DRWShadingGroup *shgroup, unsigned int point_count, float (*obmat)[4]); +void DRW_shgroup_call_procedural_lines_add(DRWShadingGroup *shgroup, unsigned int line_count, float (*obmat)[4]); +void DRW_shgroup_call_procedural_triangles_add(DRWShadingGroup *shgroup, unsigned int tria_count, float (*obmat)[4]); void DRW_shgroup_call_object_add_with_callback( DRWShadingGroup *shgroup, struct Gwn_Batch *geom, struct Object *ob, DRWCallVisibilityFn *callback, void *user_data); diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 267826d2d9a..f2b941810a7 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -127,6 +127,7 @@ typedef enum { DRW_CALL_SINGLE, /* A single batch */ DRW_CALL_INSTANCES, /* Draw instances without any instancing attribs. */ DRW_CALL_GENERATE, /* Uses a callback to draw with any number of batches. */ + DRW_CALL_PROCEDURAL, /* Generate a drawcall without any Gwn_Batch. */ } DRWCallType; typedef struct DRWCall { @@ -146,6 +147,10 @@ typedef struct DRWCall { DRWCallGenerateFn *geometry_fn; void *user_data; } generate; + struct { /* type == DRW_CALL_PROCEDURAL */ + unsigned int prim_count; + Gwn_PrimType prim_type; + } procedural; }; DRWCallType type; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index b4dce47413e..2bf0d6a6b0e 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -366,6 +366,39 @@ void DRW_shgroup_call_add(DRWShadingGroup *shgroup, Gwn_Batch *geom, float (*obm BLI_LINKS_APPEND(&shgroup->calls, call); } +static void drw_shgroup_call_procedural_add_ex( + DRWShadingGroup *shgroup, Gwn_PrimType prim_type, unsigned int prim_count, float (*obmat)[4]) +{ + BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM)); + + DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls); + call->state = drw_call_state_create(shgroup, obmat, NULL); + call->type = DRW_CALL_PROCEDURAL; + call->procedural.prim_type = prim_type; + call->procedural.prim_count = prim_count; +#ifdef USE_GPU_SELECT + call->select_id = DST.select_id; +#endif + + BLI_LINKS_APPEND(&shgroup->calls, call); +} + +void DRW_shgroup_call_procedural_points_add(DRWShadingGroup *shgroup, unsigned int point_count, float (*obmat)[4]) +{ + drw_shgroup_call_procedural_add_ex(shgroup, GWN_PRIM_POINTS, point_count, obmat); +} + +void DRW_shgroup_call_procedural_lines_add(DRWShadingGroup *shgroup, unsigned int line_count, float (*obmat)[4]) +{ + drw_shgroup_call_procedural_add_ex(shgroup, GWN_PRIM_LINES, line_count, obmat); +} + +void DRW_shgroup_call_procedural_triangles_add(DRWShadingGroup *shgroup, unsigned int tria_count, float (*obmat)[4]) +{ + drw_shgroup_call_procedural_add_ex(shgroup, GWN_PRIM_TRIS, tria_count, obmat); +} + + /* These calls can be culled and are optimized for redraw */ void DRW_shgroup_call_object_add(DRWShadingGroup *shgroup, Gwn_Batch *geom, Object *ob) { diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 110691373ab..8f5dce87c2b 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -820,6 +820,7 @@ static void draw_geometry_execute_ex( DRWShadingGroup *shgroup, Gwn_Batch *geom, uint start, uint count, bool draw_instance) { /* Special case: empty drawcall, placement is done via shader, don't bind anything. */ + /* TODO use DRW_CALL_PROCEDURAL instead */ if (geom == NULL) { BLI_assert(shgroup->type == DRW_SHG_TRIANGLE_BATCH); /* Add other type if needed. */ /* Shader is already bound. */ @@ -1147,6 +1148,9 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) case DRW_CALL_GENERATE: call->generate.geometry_fn(shgroup, draw_geometry_execute, call->generate.user_data); break; + case DRW_CALL_PROCEDURAL: + GWN_draw_primitive(call->procedural.prim_type, call->procedural.prim_count); + break; default: BLI_assert(0); } |