[Bf-blender-cvs] [086a45f0b76] greasepencil-refactor: Cleanup: GPencil: Move shader static variable to gpencil_shader.c

Clément Foucault noreply at git.blender.org
Fri Jan 10 16:56:56 CET 2020


Commit: 086a45f0b76916dee5222999cbc0c1536eca6de2
Author: Clément Foucault
Date:   Fri Jan 10 16:56:08 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB086a45f0b76916dee5222999cbc0c1536eca6de2

Cleanup: GPencil: Move shader static variable to gpencil_shader.c

===================================================================

M	source/blender/draw/engines/gpencil/gpencil_antialiasing.c
M	source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_shader.c
M	source/blender/draw/engines/gpencil/gpencil_shader_fx.c

===================================================================

diff --git a/source/blender/draw/engines/gpencil/gpencil_antialiasing.c b/source/blender/draw/engines/gpencil/gpencil_antialiasing.c
index 8e0ef370ab0..f53746b922b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_antialiasing.c
+++ b/source/blender/draw/engines/gpencil/gpencil_antialiasing.c
@@ -95,7 +95,7 @@ void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
     /* Stage 1: Edge detection. */
     DRW_PASS_CREATE(psl->smaa_edge_ps, DRW_STATE_WRITE_COLOR);
 
-    GPUShader *sh = GPENCIL_shader_antialiasing(&en_data, 0);
+    GPUShader *sh = GPENCIL_shader_antialiasing(0);
     grp = DRW_shgroup_create(sh, psl->smaa_edge_ps);
     DRW_shgroup_uniform_texture(grp, "colorTex", pd->color_tx);
     DRW_shgroup_uniform_texture(grp, "revealTex", pd->reveal_tx);
@@ -108,7 +108,7 @@ void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
     /* Stage 2: Blend Weight/Coord. */
     DRW_PASS_CREATE(psl->smaa_weight_ps, DRW_STATE_WRITE_COLOR);
 
-    GPUShader *sh = GPENCIL_shader_antialiasing(&en_data, 1);
+    GPUShader *sh = GPENCIL_shader_antialiasing(1);
     grp = DRW_shgroup_create(sh, psl->smaa_weight_ps);
     DRW_shgroup_uniform_texture(grp, "edgesTex", pd->smaa_edge_tx);
     DRW_shgroup_uniform_texture(grp, "areaTex", txl->smaa_area_tx);
@@ -123,7 +123,7 @@ void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
     /* TODO merge it with the main composite pass. */
     DRW_PASS_CREATE(psl->smaa_resolve_ps, DRW_STATE_WRITE_COLOR);
 
-    GPUShader *sh = GPENCIL_shader_antialiasing(&en_data, 2);
+    GPUShader *sh = GPENCIL_shader_antialiasing(2);
     grp = DRW_shgroup_create(sh, psl->smaa_resolve_ps);
     DRW_shgroup_uniform_texture(grp, "blendTex", pd->smaa_weight_tx);
     DRW_shgroup_uniform_texture(grp, "colorTex", pd->color_tx);
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index 26a91e27160..e18512af565 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -153,7 +153,7 @@ GPENCIL_tLayer *gpencil_layer_cache_add(GPENCIL_PrivateData *pd, Object *ob, bGP
     DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL | DRW_STATE_BLEND_MUL;
     tgp_layer->blend_ps = DRW_pass_create("GPencil Mask Layer", state);
 
-    GPUShader *sh = GPENCIL_shader_layer_mask_get(&en_data);
+    GPUShader *sh = GPENCIL_shader_layer_mask_get();
     DRWShadingGroup *grp = DRW_shgroup_create(sh, tgp_layer->blend_ps);
     DRW_shgroup_uniform_int_copy(grp, "isFirstPass", true);
     DRW_shgroup_uniform_float_copy(grp, "maskOpacity", gpl->opacity);
@@ -200,7 +200,7 @@ GPENCIL_tLayer *gpencil_layer_cache_add(GPENCIL_PrivateData *pd, Object *ob, bGP
 
     tgp_layer->blend_ps = DRW_pass_create("GPencil Blend Layer", state);
 
-    GPUShader *sh = GPENCIL_shader_layer_blend_get(&en_data);
+    GPUShader *sh = GPENCIL_shader_layer_blend_get();
     DRWShadingGroup *grp = DRW_shgroup_create(sh, tgp_layer->blend_ps);
     DRW_shgroup_uniform_int_copy(grp, "blendMode", gpl->blend_mode);
     DRW_shgroup_uniform_float_copy(grp, "blendOpacity", gpl->opacity);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 06b4db49e32..0003cc251e1 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -52,16 +52,6 @@
 
 #include "UI_resources.h"
 
-extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
-
-extern char datatoc_common_colormanagement_lib_glsl[];
-extern char datatoc_common_view_lib_glsl[];
-
-/* *********** STATIC *********** */
-GPENCIL_e_data en_data = {NULL}; /* Engine data */
-/* TODO remove this. This is only to avoid loads of warnings in other files. */
-#define e_data en_data
-
 /* *********** FUNCTIONS *********** */
 
 void GPENCIL_engine_init(void *ved)
@@ -141,41 +131,6 @@ void GPENCIL_engine_init(void *ved)
   }
 }
 
-static void GPENCIL_engine_free(void)
-{
-  /* only free custom shaders, builtin shaders are freed in blender close */
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_fill_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_stroke_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_point_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_edit_point_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_line_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_fullscreen_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_simple_fullscreen_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_blend_fullscreen_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_background_sh);
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_paper_sh);
-
-  for (int i = 0; i < 3; i++) {
-    DRW_SHADER_FREE_SAFE(e_data.antialiasing_sh[i]);
-  }
-  DRW_SHADER_FREE_SAFE(e_data.gpencil_sh);
-  DRW_SHADER_FREE_SAFE(e_data.composite_sh);
-  DRW_SHADER_FREE_SAFE(e_data.layer_blend_sh);
-  DRW_SHADER_FREE_SAFE(e_data.layer_mask_sh);
-  DRW_SHADER_FREE_SAFE(e_data.depth_merge_sh);
-
-  DRW_SHADER_FREE_SAFE(e_data.fx_blur_sh);
-  DRW_SHADER_FREE_SAFE(e_data.fx_colorize_sh);
-  DRW_SHADER_FREE_SAFE(e_data.fx_composite_sh);
-  DRW_SHADER_FREE_SAFE(e_data.fx_glow_sh);
-  DRW_SHADER_FREE_SAFE(e_data.fx_pixel_sh);
-  DRW_SHADER_FREE_SAFE(e_data.fx_rim_sh);
-  DRW_SHADER_FREE_SAFE(e_data.fx_shadow_sh);
-  DRW_SHADER_FREE_SAFE(e_data.fx_transform_sh);
-
-  GPU_VERTBUF_DISCARD_SAFE(e_data.quad);
-}
-
 void GPENCIL_cache_init(void *ved)
 {
   GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
@@ -257,7 +212,7 @@ void GPENCIL_cache_init(void *ved)
     DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM;
     DRW_PASS_CREATE(psl->composite_ps, state);
 
-    GPUShader *sh = GPENCIL_shader_composite_get(&e_data);
+    GPUShader *sh = GPENCIL_shader_composite_get();
     grp = DRW_shgroup_create(sh, psl->composite_ps);
     DRW_shgroup_uniform_texture_ref(grp, "colorBuf", &pd->color_tx);
     DRW_shgroup_uniform_texture_ref(grp, "revealBuf", &pd->reveal_tx);
@@ -268,7 +223,7 @@ void GPENCIL_cache_init(void *ved)
     DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
     DRW_PASS_CREATE(psl->merge_depth_ps, state);
 
-    GPUShader *sh = GPENCIL_shader_depth_merge_get(&e_data);
+    GPUShader *sh = GPENCIL_shader_depth_merge_get();
     grp = DRW_shgroup_create(sh, psl->merge_depth_ps);
     DRW_shgroup_uniform_texture_ref(grp, "depthBuf", &pd->depth_tx);
     DRW_shgroup_uniform_bool(grp, "strokeOrder3d", &pd->is_stroke_order_3d, 1);
@@ -399,7 +354,7 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
   iter->ubo_lights = (use_lights) ? iter->pd->global_light_pool->ubo :
                                     iter->pd->shadeless_light_pool->ubo;
 
-  struct GPUShader *sh = GPENCIL_shader_geometry_get(&en_data);
+  struct GPUShader *sh = GPENCIL_shader_geometry_get();
   iter->grp = DRW_shgroup_create(sh, tgp_layer->geom_ps);
   DRW_shgroup_uniform_block_persistent(iter->grp, "gpLightBlock", iter->ubo_lights);
   DRW_shgroup_uniform_block(iter->grp, "gpMaterialBlock", iter->ubo_mat);
@@ -882,6 +837,11 @@ void GPENCIL_draw_scene(void *ved)
   }
 }
 
+static void GPENCIL_engine_free(void)
+{
+  GPENCIL_shader_free();
+}
+
 static const DrawEngineDataSize GPENCIL_data_size = DRW_VIEWPORT_DATA_SIZE(GPENCIL_Data);
 
 DrawEngineType draw_engine_gpencil_type = {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index bd307b92d91..bbf7c2d6723 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -313,49 +313,6 @@ typedef struct GPENCIL_PrivateData {
 
 } GPENCIL_PrivateData;
 
-typedef struct GPENCIL_e_data {
-  /* SMAA antialiasing */
-  struct GPUShader *antialiasing_sh[3];
-  /* GPencil Object rendering */
-  struct GPUShader *gpencil_sh;
-  /* Final Compositing over rendered background. */
-  struct GPUShader *composite_sh;
-  /* All layer blend types in one shader! */
-  struct GPUShader *layer_blend_sh;
-  /* To blend masked layer with other layers. */
-  struct GPUShader *layer_mask_sh;
-  /* Merge the final object depth to the depth buffer. */
-  struct GPUShader *depth_merge_sh;
-  /* Effects. */
-  struct GPUShader *fx_composite_sh;
-  struct GPUShader *fx_colorize_sh;
-  struct GPUShader *fx_blur_sh;
-  struct GPUShader *fx_glow_sh;
-  struct GPUShader *fx_pixel_sh;
-  struct GPUShader *fx_rim_sh;
-  struct GPUShader *fx_shadow_sh;
-  struct GPUShader *fx_transform_sh;
-
-  /* general drawing shaders */
-  struct GPUShader *gpencil_fill_sh;
-  struct GPUShader *gpencil_stroke_sh;
-  struct GPUShader *gpencil_point_sh;
-  struct GPUShader *gpencil_edit_point_sh;
-  struct GPUShader *gpencil_line_sh;
-  struct GPUShader *gpencil_drawing_fill_sh;
-  struct GPUShader *gpencil_fullscreen_sh;
-  struct GPUShader *gpencil_simple_fullscreen_sh;
-  struct GPUShader *gpencil_blend_fullscreen_sh;
-  struct GPUShader *gpencil_background_sh;
-  struct GPUShader *gpencil_paper_sh;
-
-  /* Dummy vbos. */
-  struct GPUVertBuf *quad;
-
-} GPENCIL_e_data; /* Engine data */
-
-extern GPENCIL_e_data en_data;
-
 /* Runtime data for GPU and evaluated frames after applying modifiers */
 typedef struct GpencilBatchCache {
   /** Cache is dirty */
@@ -389,20 +346,22 @@ GPENCIL_LightPool *gpencil_light_pool_create(GPENCIL_PrivateData *pd, Object *ob
 void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObject *tgp_ob);
 
 /* Shaders */
-struct GPUShader *GPENCIL_shader_antialiasing(GPENCIL_e_data *e_data, int stage);
-struct GPUShader *GPENCIL_shader_geometry_get(GPENCIL_e_data *e_data);
-struct GPUShader *GPENCIL_shader_composite_get(GPENCIL_e_data *e_data);
-struct GPUShader *GPENCIL_shader_layer_blend_get(GPENCIL_e_data *e_data);
-struct GPUShader *GPENCIL_shader_layer_mask_get(GPENCIL_e_data *e_data);
-struct GPUShader *GPENCIL_shader_depth_merge_get(GPENCIL_e_data *e_data);
-struct GPUShader *GPENCIL_shader_fx_blur_get(GPENCIL_e_data *e_data);
-struct GPUShader *GPENCIL_shader_fx_colorize_get(GPENCIL_e_data *e_data);
-struct GPUShader *GPENCIL_shader_fx_composite_get(GPENCIL_e_data *e_data);
-struct GPUShader *GPENCIL_shader_fx_transform_get(GPENCIL_e_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list