Commit: 57d9b81388cccdeb36e3bfcdc8edae9ea99cd089
Author: Antonio Vazquez
Date:   Thu Jun 28 12:11:20 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB57d9b81388cccdeb36e3bfcdc8edae9ea99cd089

Cleanup and code reorganization

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

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_fx.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 6ba517dd369..c5cb911bd71 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -55,25 +55,12 @@ extern char datatoc_gpencil_simple_mix_frag_glsl[];
 extern char datatoc_gpencil_point_vert_glsl[];
 extern char datatoc_gpencil_point_geom_glsl[];
 extern char datatoc_gpencil_point_frag_glsl[];
-extern char datatoc_gpencil_gaussian_blur_frag_glsl[];
-extern char datatoc_gpencil_wave_frag_glsl[];
-extern char datatoc_gpencil_pixel_frag_glsl[];
-extern char datatoc_gpencil_swirl_frag_glsl[];
-extern char datatoc_gpencil_flip_frag_glsl[];
-extern char datatoc_gpencil_light_frag_glsl[];
 extern char datatoc_gpencil_background_frag_glsl[];
 extern char datatoc_gpencil_paper_frag_glsl[];
 extern char datatoc_gpencil_edit_point_vert_glsl[];
 extern char datatoc_gpencil_edit_point_geom_glsl[];
 extern char datatoc_gpencil_edit_point_frag_glsl[];
 
-extern char datatoc_gpencil_fx_blur_frag_glsl[];
-extern char datatoc_gpencil_fx_flip_frag_glsl[];
-extern char datatoc_gpencil_fx_light_frag_glsl[];
-extern char datatoc_gpencil_fx_pixel_frag_glsl[];
-extern char datatoc_gpencil_fx_swirl_frag_glsl[];
-extern char datatoc_gpencil_fx_wave_frag_glsl[];
-
 /* *********** STATIC *********** */
 static GPENCIL_e_data e_data = {NULL}; /* Engine data */
 
@@ -219,47 +206,6 @@ static void GPENCIL_create_shaders(void)
        }
 }
 
-static void GPENCIL_create_fx_shaders(void)
-{
-       /* fx shaders (all in screen space) */
-       if (!e_data.gpencil_fx_blur_sh) {
-               e_data.gpencil_fx_blur_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_blur_frag_glsl, NULL);
-       }
-       if (!e_data.gpencil_fx_flip_sh) {
-               e_data.gpencil_fx_flip_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_flip_frag_glsl, NULL);
-       }
-       if (!e_data.gpencil_fx_light_sh) {
-               e_data.gpencil_fx_light_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_light_frag_glsl, NULL);
-       }
-       if (!e_data.gpencil_fx_pixel_sh) {
-               e_data.gpencil_fx_pixel_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_pixel_frag_glsl, NULL);
-       }
-       if (!e_data.gpencil_fx_swirl_sh) {
-               e_data.gpencil_fx_swirl_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_swirl_frag_glsl, NULL);
-       }
-       if (!e_data.gpencil_fx_wave_sh) {
-               e_data.gpencil_fx_wave_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_wave_frag_glsl, NULL);
-       }
-}
-
-static void GPENCIL_create_fx_passes(GPENCIL_PassList *psl)
-{
-       DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND |
-                                        DRW_STATE_WRITE_DEPTH | 
DRW_STATE_DEPTH_LESS;
-       /* FX passes */
-       psl->fx_blur_pass = DRW_pass_create("GPencil FX Blur Pass", state);
-
-       psl->fx_flip_pass = DRW_pass_create("GPencil FX Flip Pass", state);
-
-       psl->fx_light_pass = DRW_pass_create("GPencil FX Light Pass", state);
-
-       psl->fx_pixel_pass = DRW_pass_create("GPencil FX Pixel Pass", state);
-
-       psl->fx_swirl_pass = DRW_pass_create("GPencil FX Swirl Pass", state);
-
-       psl->fx_wave_pass = DRW_pass_create("GPencil FX Wave Pass", state);
-}
-
 void GPENCIL_engine_init(void *vedata)
 {
        GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
@@ -278,7 +224,7 @@ void GPENCIL_engine_init(void *vedata)
 
        /* create shaders */
        GPENCIL_create_shaders();
-       GPENCIL_create_fx_shaders();
+       GPENCIL_create_fx_shaders(&e_data);
 
        /* blank texture used if no texture defined for fill shader */
        if (!e_data.gpencil_blank_texture) {
@@ -302,12 +248,7 @@ static void GPENCIL_engine_free(void)
        DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
 
        /* effects */
-       DRW_SHADER_FREE_SAFE(e_data.gpencil_fx_blur_sh);
-       DRW_SHADER_FREE_SAFE(e_data.gpencil_fx_flip_sh);
-       DRW_SHADER_FREE_SAFE(e_data.gpencil_fx_light_sh);
-       DRW_SHADER_FREE_SAFE(e_data.gpencil_fx_pixel_sh);
-       DRW_SHADER_FREE_SAFE(e_data.gpencil_fx_swirl_sh);
-       DRW_SHADER_FREE_SAFE(e_data.gpencil_fx_wave_sh);
+       GPENCIL_delete_fx_shaders(&e_data);
 }
 
 void GPENCIL_cache_init(void *vedata)
@@ -446,7 +387,7 @@ void GPENCIL_cache_init(void *vedata)
                DRW_shgroup_uniform_int(mix_shgrp, "tonemapping", 
&stl->storage->tonemapping, 1);
 
                /* mix pass no blend used to copy between passes. A separated 
pass is required
-                * because if the mix pass is used, the acumulation of blend 
degrade the colors.
+                * because if mix_pass is used, the acumulation of blend 
degrade the colors.
                 *
                 * This pass is used too to take the snapshot used for 
background_pass. This image
                 * will be used as the background while the user is drawing.
@@ -460,7 +401,7 @@ void GPENCIL_cache_init(void *vedata)
 
                /* Painting session pass (used only to speedup while the user 
is drawing )
                 * This pass is used to show the snapshot of the current grease 
pencil strokes captured
-                * when the user starts to draw.
+                * when the user starts to draw (see comments above).
                 * In this way, the previous strokes don't need to be redraw 
and the drawing process
                 * is far to agile.
                 */
@@ -471,7 +412,7 @@ void GPENCIL_cache_init(void *vedata)
                DRW_shgroup_uniform_texture_ref(background_shgrp, 
"strokeDepth", &e_data.background_depth_tx);
 
                /* pass for drawing paper (only if viewport)
-                * In render, the v3d is null
+                * In render, the v3d is null so the paper is disabled
                 * The paper is way to isolate the drawing in complex scene and 
to have a cleaner
                 * drawing area.
                 */
@@ -496,7 +437,7 @@ void GPENCIL_cache_init(void *vedata)
                        DRW_shgroup_uniform_int(paper_shgrp, "uselines", 
&stl->storage->uselines, 1);
                }
 
-               /* effects passes */
+               /* create effects passes */
                GPENCIL_create_fx_passes(psl);
        }
 }
@@ -575,12 +516,11 @@ void GPENCIL_cache_finish(void *vedata)
                        if (stl->storage->is_render == true) {
                                gpd->flag |= GP_DATA_CACHE_IS_DIRTY;
                        }
-                       /* FX pass */
+                       /* FX passses */
                        tGPencilObjectCache *cache = 
&stl->g_data->gp_object_cache[i];
-                       if ((!is_multiedit) && (ob->shader_fx.first)) {
+                       if (!is_multiedit) {
                                DRW_gpencil_fx_prepare(&e_data, vedata, cache);
                        }
-
                }
        }
 }
@@ -596,8 +536,8 @@ static int gpencil_object_cache_compare_zdepth(const void 
*a1, const void *a2)
        return 0;
 }
 
-/* prepare a texture with full viewport for fast drawing */
-static void gpencil_prepare_fast_drawing(GPENCIL_StorageList *stl, 
DefaultFramebufferList *dfbl, GPENCIL_FramebufferList *fbl, DRWPass *pass, 
float clearcol[4])
+/* prepare a texture with full viewport screenshot for fast drawing */
+static void gpencil_prepare_fast_drawing(GPENCIL_StorageList *stl, 
DefaultFramebufferList *dfbl, GPENCIL_FramebufferList *fbl, DRWPass *pass, 
const float clearcol[4])
 {
        if (stl->g_data->session_flag & (GP_DRW_PAINT_IDLE | 
GP_DRW_PAINT_FILLING)) {
                GPU_framebuffer_bind(fbl->background_fb);
@@ -645,7 +585,7 @@ void GPENCIL_draw_scene(void *ved)
 
        int init_grp, end_grp;
        tGPencilObjectCache *cache;
-       float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+       const float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
 
        const DRWContextState *draw_ctx = DRW_context_state_get();
        View3D *v3d = draw_ctx->v3d;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h 
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 4278fa7073a..0acb86a5702 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -347,6 +347,10 @@ struct GpencilBatchCache *gpencil_batch_cache_get(struct 
Object *ob, int cfra);
 void gpencil_instance_modifiers(struct GPENCIL_StorageList *stl, struct Object 
*ob);
 
 /* effects */
+void GPENCIL_create_fx_shaders(struct GPENCIL_e_data *e_data);
+void GPENCIL_delete_fx_shaders(struct GPENCIL_e_data *e_data);
+void GPENCIL_create_fx_passes(struct GPENCIL_PassList *psl);
+
 void DRW_gpencil_fx_prepare(
        struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata,
        struct tGPencilObjectCache *cache);
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c 
b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index e609b4f58f4..f01d37af42c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -41,6 +41,13 @@
 
 #include "gpencil_engine.h"
 
+extern char datatoc_gpencil_fx_blur_frag_glsl[];
+extern char datatoc_gpencil_fx_flip_frag_glsl[];
+extern char datatoc_gpencil_fx_light_frag_glsl[];
+extern char datatoc_gpencil_fx_pixel_frag_glsl[];
+extern char datatoc_gpencil_fx_swirl_frag_glsl[];
+extern char datatoc_gpencil_fx_wave_frag_glsl[];
+
 /* verify if this fx is active */
 static bool effect_is_active(Object *ob, ShaderFxData *fx, bool is_render)
 {
@@ -421,6 +428,61 @@ static void DRW_gpencil_fx_wave(
 
 /* ************************************************************** */
 
+/* create all FX shaders */
+void GPENCIL_create_fx_shaders(GPENCIL_e_data *e_data)
+{
+       /* fx shaders (all in screen space) */
+       if (!e_data->gpencil_fx_blur_sh) {
+               e_data->gpencil_fx_blur_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_blur_frag_glsl, NULL);
+       }
+       if (!e_data->gpencil_fx_flip_sh) {
+               e_data->gpencil_fx_flip_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_flip_frag_glsl, NULL);
+       }
+       if (!e_data->gpencil_fx_light_sh) {
+               e_data->gpencil_fx_light_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_light_frag_glsl, NULL);
+       }
+       if (!e_data->gpencil_fx_pixel_sh) {
+               e_data->gpencil_fx_pixel_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_pixel_frag_glsl, NULL);
+       }
+       if (!e_data->gpencil_fx_swirl_sh) {
+               e_data->gpencil_fx_swirl_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_swirl_frag_glsl, NULL);
+       }
+       if (!e_data->gpencil_fx_wave_sh) {
+               e_data->gpencil_fx_wave_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_wave_frag_glsl, NULL);
+       }
+}
+
+/* free FX shaders */
+void GPENCIL_delete_fx_shaders(GPENCIL_e_data *e_data)
+{
+       DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_blur_sh);
+       DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_flip_sh);
+       DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_light_sh);
+       DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_pixel_sh);
+       DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_swirl_sh);
+       DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_wave_sh);
+}
+
+/* create all passes used by FX */
+void GPE

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to