From 7cdd5ed7bd228d46b5eecc3355b01d00f26d1ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 30 May 2019 00:36:54 +0200 Subject: 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. --- source/blender/draw/intern/draw_manager.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source/blender/draw/intern/draw_manager.c') diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 8897d14c5fd..bfb38a12fa9 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -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; -- cgit v1.2.3