diff options
Diffstat (limited to 'source/blender/draw/modes/paint_weight_mode.c')
-rw-r--r-- | source/blender/draw/modes/paint_weight_mode.c | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/source/blender/draw/modes/paint_weight_mode.c b/source/blender/draw/modes/paint_weight_mode.c index c083aaaae82..06f73436760 100644 --- a/source/blender/draw/modes/paint_weight_mode.c +++ b/source/blender/draw/modes/paint_weight_mode.c @@ -33,6 +33,12 @@ #include "draw_mode_engines.h" +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + /* *********** LISTS *********** */ /* All lists are per viewport specific datas. * They are all free when viewport changes engines @@ -85,26 +91,24 @@ typedef struct PAINT_WEIGHT_Data { /* *********** STATIC *********** */ -/* This keeps the references of the shading groups for - * easy access in PAINT_WEIGHT_cache_populate() */ -static DRWShadingGroup *group; - -/* If needed, contains all global/Theme colors - * Add needed theme colors / values to DRW_globals_update() and update UBO - * Not needed for constant color. */ -extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ -extern struct GlobalsUboStorage ts; /* draw_common.c */ - -/* Custom shaders : - * Add sources to source/blender/draw/modes/shaders - * init in PAINT_WEIGHT_engine_init(); - * free in PAINT_WEIGHT_engine_free(); */ -static struct GPUShader *custom_shader = NULL; - -/* 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 */ -static PAINT_WEIGHT_Data *vedata; +static struct { + /* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in PAINT_WEIGHT_engine_init(); + * free in PAINT_WEIGHT_engine_free(); */ + struct GPUShader *custom_shader; +} e_data = {NULL}; /* Engine data */ + +static struct { + /* 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 */ /* *********** FUNCTIONS *********** */ @@ -113,10 +117,10 @@ static PAINT_WEIGHT_Data *vedata; * (Optional) */ static void PAINT_WEIGHT_engine_init(void) { - vedata = DRW_viewport_engine_data_get("PaintWeightMode"); - PAINT_WEIGHT_TextureList *txl = vedata->txl; - PAINT_WEIGHT_FramebufferList *fbl = vedata->fbl; - PAINT_WEIGHT_StorageList *stl = vedata->stl; + PAINT_WEIGHT_Data *ved = DRW_viewport_engine_data_get("PaintWeightMode"); + PAINT_WEIGHT_TextureList *txl = ved->txl; + PAINT_WEIGHT_FramebufferList *fbl = ved->fbl; + PAINT_WEIGHT_StorageList *stl = ved->stl; UNUSED_VARS(txl, fbl, stl); @@ -135,8 +139,8 @@ static void PAINT_WEIGHT_engine_init(void) * tex, 2); */ - if (!custom_shader) { - custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + if (!e_data.custom_shader) { + e_data.custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); } } @@ -144,9 +148,9 @@ static void PAINT_WEIGHT_engine_init(void) * Assume that all Passes are NULL */ static void PAINT_WEIGHT_cache_init(void) { - vedata = DRW_viewport_engine_data_get("PaintWeightMode"); - PAINT_WEIGHT_PassList *psl = vedata->psl; - PAINT_WEIGHT_StorageList *stl = vedata->stl; + g_data.vedata = DRW_viewport_engine_data_get("PaintWeightMode"); + PAINT_WEIGHT_PassList *psl = g_data.vedata->psl; + PAINT_WEIGHT_StorageList *stl = g_data.vedata->stl; UNUSED_VARS(stl); @@ -157,16 +161,16 @@ static void PAINT_WEIGHT_cache_init(void) /* Create a shadingGroup using a function in draw_common.c or custom one */ /* - * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * g_data.group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); * -- or -- - * group = DRW_shgroup_create(custom_shader, psl->pass); + * g_data.group = DRW_shgroup_create(e_data.custom_shader, psl->pass); */ - group = DRW_shgroup_create(custom_shader, psl->pass); + 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(group, "color", color, 1); + DRW_shgroup_uniform_vec4(g_data.group, "color", color, 1); } } @@ -174,8 +178,8 @@ static void PAINT_WEIGHT_cache_init(void) /* Add geometry to shadingGroups. Execute for each objects */ static void PAINT_WEIGHT_cache_populate(Object *ob) { - PAINT_WEIGHT_PassList *psl = vedata->psl; - PAINT_WEIGHT_StorageList *stl = vedata->stl; + PAINT_WEIGHT_PassList *psl = g_data.vedata->psl; + PAINT_WEIGHT_StorageList *stl = g_data.vedata->stl; UNUSED_VARS(psl, stl); @@ -184,15 +188,15 @@ static void PAINT_WEIGHT_cache_populate(Object *ob) struct Batch *geom = DRW_cache_surface_get(ob); /* Add geom to a shading group */ - DRW_shgroup_call_add(group, geom, ob->obmat); + DRW_shgroup_call_add(g_data.group, geom, ob->obmat); } } /* Optional: Post-cache_populate callback */ static void PAINT_WEIGHT_cache_finish(void) { - PAINT_WEIGHT_PassList *psl = vedata->psl; - PAINT_WEIGHT_StorageList *stl = vedata->stl; + PAINT_WEIGHT_PassList *psl = g_data.vedata->psl; + PAINT_WEIGHT_StorageList *stl = g_data.vedata->stl; /* Do something here! dependant on the objects gathered */ UNUSED_VARS(psl, stl); @@ -203,7 +207,7 @@ static void PAINT_WEIGHT_draw_scene(void) { PAINT_WEIGHT_Data *ved = DRW_viewport_engine_data_get("PaintWeightMode"); PAINT_WEIGHT_PassList *psl = ved->psl; - PAINT_WEIGHT_FramebufferList *fbl = vedata->fbl; + PAINT_WEIGHT_FramebufferList *fbl = ved->fbl; /* Default framebuffer and texture */ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); |