Cleanup: Remove DRWCallType

This simplify the rendering logic.
This commit is contained in:
2019-05-11 19:16:46 +02:00
parent ed3f05aca9
commit 0e5da91f0a
3 changed files with 36 additions and 62 deletions

View File

@@ -124,40 +124,15 @@ typedef struct DRWCallState {
float ob_random;
} DRWCallState;
typedef enum {
/** A single batch. */
DRW_CALL_SINGLE,
/** Like single but only draw a range of vertices/indices. */
DRW_CALL_RANGE,
/** Draw instances without any instancing attributes. */
DRW_CALL_INSTANCES,
/** Generate a drawcall without any #GPUBatch. */
DRW_CALL_PROCEDURAL,
} DRWCallType;
typedef struct DRWCall {
struct DRWCall *next;
DRWCallState *state;
union {
struct { /* type == DRW_CALL_SINGLE */
GPUBatch *geometry;
} single;
struct { /* type == DRW_CALL_RANGE */
GPUBatch *geometry;
uint start, count;
} range;
struct { /* type == DRW_CALL_INSTANCES */
GPUBatch *geometry;
uint count;
} instances;
struct { /* type == DRW_CALL_PROCEDURAL */
GPUBatch *geometry;
uint vert_count;
} procedural;
};
GPUBatch *batch;
uint vert_first;
uint vert_count;
uint inst_count;
DRWCallType type;
#ifdef USE_GPU_SELECT
int select_id;
#endif
@@ -198,9 +173,11 @@ struct DRWUniform {
typedef enum {
DRW_SHG_NORMAL,
DRW_SHG_POINT_BATCH,
DRW_SHG_LINE_BATCH,
DRW_SHG_TRIANGLE_BATCH,
DRW_SHG_INSTANCE,
DRW_SHG_INSTANCE_EXTERNAL,
DRW_SHG_FEEDBACK_TRANSFORM,

View File

@@ -459,8 +459,10 @@ void DRW_shgroup_call_add(DRWShadingGroup *shgroup, GPUBatch *geom, float (*obma
BLI_LINKS_APPEND(&shgroup->calls, call);
call->state = drw_call_state_create(shgroup, obmat, NULL);
call->type = DRW_CALL_SINGLE;
call->single.geometry = geom;
call->batch = geom;
call->vert_first = 0;
call->vert_count = 0; /* Auto from batch. */
call->inst_count = 0;
#ifdef USE_GPU_SELECT
call->select_id = DST.select_id;
#endif
@@ -477,10 +479,10 @@ void DRW_shgroup_call_range_add(
BLI_LINKS_APPEND(&shgroup->calls, call);
call->state = drw_call_state_create(shgroup, obmat, NULL);
call->type = DRW_CALL_RANGE;
call->range.geometry = geom;
call->range.start = v_sta;
call->range.count = v_count;
call->batch = geom;
call->vert_first = v_sta;
call->vert_count = v_count;
call->inst_count = 0;
#ifdef USE_GPU_SELECT
call->select_id = DST.select_id;
#endif
@@ -497,9 +499,10 @@ static void drw_shgroup_call_procedural_add_ex(DRWShadingGroup *shgroup,
BLI_LINKS_APPEND(&shgroup->calls, call);
call->state = drw_call_state_object(shgroup, obmat, NULL);
call->type = DRW_CALL_PROCEDURAL;
call->procedural.geometry = geom;
call->procedural.vert_count = vert_count;
call->batch = geom;
call->vert_first = 0;
call->vert_count = vert_count;
call->inst_count = 0;
#ifdef USE_GPU_SELECT
call->select_id = DST.select_id;
#endif
@@ -544,8 +547,10 @@ void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup,
call->state = drw_call_state_object(shgroup, ob->obmat, ob);
/* NOTE this will disable culling for the whole object. */
call->state->flag |= (bypass_culling) ? DRW_CALL_BYPASS_CULLING : 0;
call->type = DRW_CALL_SINGLE;
call->single.geometry = geom;
call->batch = geom;
call->vert_first = 0;
call->vert_count = 0; /* Auto from batch. */
call->inst_count = 0;
#ifdef USE_GPU_SELECT
call->select_id = DST.select_id;
#endif
@@ -566,8 +571,10 @@ void DRW_shgroup_call_object_add_with_callback(DRWShadingGroup *shgroup,
call->state = drw_call_state_object(shgroup, ob->obmat, ob);
call->state->visibility_cb = callback;
call->state->user_data = user_data;
call->type = DRW_CALL_SINGLE;
call->single.geometry = geom;
call->batch = geom;
call->vert_first = 0;
call->vert_count = 0; /* Auto from batch. */
call->inst_count = 0;
#ifdef USE_GPU_SELECT
call->select_id = DST.select_id;
#endif
@@ -585,9 +592,10 @@ void DRW_shgroup_call_instances_add(DRWShadingGroup *shgroup,
BLI_LINKS_APPEND(&shgroup->calls, call);
call->state = drw_call_state_create(shgroup, obmat, NULL);
call->type = DRW_CALL_INSTANCES;
call->instances.geometry = geom;
call->instances.count = count;
call->batch = geom;
call->vert_first = 0;
call->vert_count = 0; /* Auto from batch. */
call->inst_count = count;
#ifdef USE_GPU_SELECT
call->select_id = DST.select_id;
#endif

View File

@@ -1265,23 +1265,12 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
GPU_SELECT_LOAD_IF_PICKSEL_CALL(call);
draw_geometry_prepare(shgroup, call);
switch (call->type) {
case DRW_CALL_SINGLE:
draw_geometry_execute(shgroup, call->single.geometry, 0, 0, false);
break;
case DRW_CALL_RANGE:
draw_geometry_execute(
shgroup, call->range.geometry, call->range.start, call->range.count, false);
break;
case DRW_CALL_INSTANCES:
draw_geometry_execute(shgroup, call->instances.geometry, 0, call->instances.count, true);
break;
case DRW_CALL_PROCEDURAL:
draw_geometry_execute(
shgroup, call->procedural.geometry, 0, call->procedural.vert_count, false);
break;
default:
BLI_assert(0);
/* TODO revisit when DRW_SHG_INSTANCE and the like is gone. */
if (call->inst_count == 0) {
draw_geometry_execute(shgroup, call->batch, call->vert_first, call->vert_count, false);
}
else {
draw_geometry_execute(shgroup, call->batch, 0, call->inst_count, true);
}
}
/* Reset state */