DRW: Add unit_state to avoid lots of DRWCallState duplication
A lot of drawcalls don't use the object's properties and don't need a dedicated DRWCallState. We allocate a unique one at the begining and use it for all calls that uses the default unit matrix.
This commit is contained in:
@@ -587,6 +587,29 @@ static void drw_context_state_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
static DRWCallState *draw_unit_state_create(void)
|
||||
{
|
||||
DRWCallState *state = BLI_memblock_alloc(DST.vmempool->states);
|
||||
state->flag = 0;
|
||||
state->matflag = 0;
|
||||
|
||||
unit_m4(state->model);
|
||||
unit_m4(state->modelinverse);
|
||||
|
||||
copy_v3_fl(state->orcotexfac[0], 0.0f);
|
||||
copy_v3_fl(state->orcotexfac[1], 1.0f);
|
||||
|
||||
state->ob_index = 0;
|
||||
state->ob_random = 0.0f;
|
||||
|
||||
/* TODO(fclem) get rid of this. */
|
||||
state->culling = BLI_memblock_alloc(DST.vmempool->cullstates);
|
||||
state->culling->bsphere.radius = -1.0f;
|
||||
state->culling->user_data = NULL;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
/* It also stores viewport variable to an immutable place: DST
|
||||
* This is because a cache uniform only store reference
|
||||
* to its value. And we don't want to invalidate the cache
|
||||
@@ -634,6 +657,9 @@ static void drw_viewport_var_init(void)
|
||||
DST.vmempool->images = BLI_memblock_create(sizeof(GPUTexture *));
|
||||
}
|
||||
|
||||
/* Alloc default unit state */
|
||||
DST.unit_state = draw_unit_state_create();
|
||||
|
||||
DST.idatalist = GPU_viewport_instance_data_list_get(DST.viewport);
|
||||
DRW_instance_data_list_reset(DST.idatalist);
|
||||
}
|
||||
@@ -646,6 +672,8 @@ static void drw_viewport_var_init(void)
|
||||
|
||||
DST.default_framebuffer = NULL;
|
||||
DST.vmempool = NULL;
|
||||
|
||||
DST.unit_state = NULL;
|
||||
}
|
||||
|
||||
DST.primary_view_ct = 0;
|
||||
|
||||
@@ -283,6 +283,8 @@ typedef struct DRWManager {
|
||||
ViewportMemoryPool *vmempool;
|
||||
DRWInstanceDataList *idatalist;
|
||||
DRWInstanceData *object_instance_data[MAX_INSTANCE_DATA_SIZE];
|
||||
/* Default Unit model matrix state without culling. */
|
||||
DRWCallState *unit_state;
|
||||
/* State of the object being evaluated if already allocated. */
|
||||
DRWCallState *ob_state;
|
||||
struct DupliObject *dupli_source;
|
||||
|
||||
@@ -396,15 +396,10 @@ static DRWCallState *drw_call_state_create(DRWShadingGroup *shgroup, float (*obm
|
||||
state->matflag = 0;
|
||||
|
||||
/* Matrices */
|
||||
if (obmat != NULL) {
|
||||
copy_m4_m4(state->model, obmat);
|
||||
copy_m4_m4(state->model, obmat);
|
||||
|
||||
if (ob && (ob->transflag & OB_NEG_SCALE)) {
|
||||
state->flag |= DRW_CALL_NEGSCALE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
unit_m4(state->model);
|
||||
if (ob && (ob->transflag & OB_NEG_SCALE)) {
|
||||
state->flag |= DRW_CALL_NEGSCALE;
|
||||
}
|
||||
|
||||
drw_call_state_update_matflag(state, shgroup, ob);
|
||||
@@ -435,8 +430,8 @@ static DRWCallState *drw_call_state_object(DRWShadingGroup *shgroup, float (*obm
|
||||
{
|
||||
if (ob == NULL) {
|
||||
if (obmat == NULL) {
|
||||
/* TODO return unitmat state. */
|
||||
return drw_call_state_create(shgroup, obmat, ob);
|
||||
BLI_assert(DST.unit_state);
|
||||
return DST.unit_state;
|
||||
}
|
||||
else {
|
||||
return drw_call_state_create(shgroup, obmat, ob);
|
||||
|
||||
Reference in New Issue
Block a user