diff options
Diffstat (limited to 'source/blender/draw/modes/paint_weight_mode.c')
-rw-r--r-- | source/blender/draw/modes/paint_weight_mode.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/source/blender/draw/modes/paint_weight_mode.c b/source/blender/draw/modes/paint_weight_mode.c index 00a034a87c0..3063e685149 100644 --- a/source/blender/draw/modes/paint_weight_mode.c +++ b/source/blender/draw/modes/paint_weight_mode.c @@ -76,6 +76,7 @@ typedef struct PAINT_WEIGHT_StorageList { * free with MEM_freeN() when viewport is freed. * (not per object) */ struct CustomStruct *block; + struct g_data *g_data; } PAINT_WEIGHT_StorageList; typedef struct PAINT_WEIGHT_Data { @@ -99,16 +100,11 @@ static struct { struct GPUShader *custom_shader; } e_data = {NULL}; /* Engine data */ -static struct { +typedef struct g_data { /* This keeps the references of the shading groups for * easy access in PAINT_WEIGHT_cache_populate() */ DRWShadingGroup *group; - - /* This keeps the reference of the viewport engine data because - * DRW_viewport_engine_data_get is slow and we don't want to - * call it for every object */ - PAINT_WEIGHT_Data *vedata; -} g_data = {NULL}; /* Transient data */ +} g_data; /* *********** FUNCTIONS *********** */ @@ -117,10 +113,9 @@ static struct { * (Optional) */ static void PAINT_WEIGHT_engine_init(void *vedata) { - PAINT_WEIGHT_Data *ved = DRW_viewport_engine_data_get("PaintWeightMode"); - PAINT_WEIGHT_TextureList *txl = ved->txl; + PAINT_WEIGHT_TextureList *txl = ((PAINT_WEIGHT_Data *)vedata)->txl; PAINT_WEIGHT_FramebufferList *fbl = ((PAINT_WEIGHT_Data *)vedata)->fbl; - PAINT_WEIGHT_StorageList *stl = ved->stl; + PAINT_WEIGHT_StorageList *stl = ((PAINT_WEIGHT_Data *)vedata)->stl; UNUSED_VARS(txl, fbl, stl); @@ -148,11 +143,13 @@ static void PAINT_WEIGHT_engine_init(void *vedata) * Assume that all Passes are NULL */ static void PAINT_WEIGHT_cache_init(void *vedata) { - PAINT_WEIGHT_PassList *psl = ((PAINT_WEIGHT_Data *)vedata)->psl; PAINT_WEIGHT_StorageList *stl = ((PAINT_WEIGHT_Data *)vedata)->stl; - UNUSED_VARS(stl); + if (!stl->g_data) { + /* Alloc transient pointers */ + stl->g_data = MEM_mallocN(sizeof(g_data), "g_data"); + } { /* Create a pass */ @@ -161,16 +158,16 @@ static void PAINT_WEIGHT_cache_init(void *vedata) /* Create a shadingGroup using a function in draw_common.c or custom one */ /* - * g_data.group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); * -- or -- - * g_data.group = DRW_shgroup_create(e_data.custom_shader, psl->pass); + * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass); */ - g_data.group = DRW_shgroup_create(e_data.custom_shader, psl->pass); + stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass); /* Uniforms need a pointer to it's value so be sure it's accessible at * any given time (i.e. use static vars) */ static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; - DRW_shgroup_uniform_vec4(g_data.group, "color", color, 1); + DRW_shgroup_uniform_vec4(stl->g_data->group, "color", color, 1); } } @@ -178,17 +175,14 @@ static void PAINT_WEIGHT_cache_init(void *vedata) /* Add geometry to shadingGroups. Execute for each objects */ static void PAINT_WEIGHT_cache_populate(void *vedata, Object *ob) { - PAINT_WEIGHT_PassList *psl = ((PAINT_WEIGHT_Data *)vedata)->psl; PAINT_WEIGHT_StorageList *stl = ((PAINT_WEIGHT_Data *)vedata)->stl; - UNUSED_VARS(psl, stl); - if (ob->type == OB_MESH) { /* Get geometry cache */ struct Batch *geom = DRW_cache_surface_get(ob); /* Add geom to a shading group */ - DRW_shgroup_call_add(g_data.group, geom, ob->obmat); + DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat); } } |