Commit: 637b0154ad0080c6266d4b6ae2e24ffcddb4953b
Author: Antonio Vazquez
Date:   Wed Apr 4 15:54:29 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB637b0154ad0080c6266d4b6ae2e24ffcddb4953b

Cleanup: Create shaders in a separate function

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

M       source/blender/draw/engines/gpencil/gpencil_engine.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 1cae05abc8c..9c1566a2d67 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -79,86 +79,31 @@ extern char datatoc_gpencil_dof_frag_glsl[];
 static GPENCIL_e_data e_data = {NULL}; /* Engine data */
 
 /* *********** FUNCTIONS *********** */
-
-static void GPENCIL_engine_init(void *vedata)
+static void GPENCIL_create_shaders(void)
 {
-       GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
-       GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
-       const DRWContextState *draw_ctx = DRW_context_state_get();
-       View3D *v3d = draw_ctx->v3d;
-       RegionView3D *rv3d = draw_ctx->rv3d;
-
-       /* Go full 32bits for rendering */
-       DRWTextureFormat fb_format = DRW_state_is_image_render() ? 
DRW_TEX_RGBA_32 : DRW_TEX_RGBA_16;
-
-       if (DRW_state_is_fbo()) {
-               const float *viewport_size = DRW_viewport_size_get();
-               const int size[2] = { (int)viewport_size[0], 
(int)viewport_size[1] };
-
-               /* temp framebuffer to store all stroke drawing before sending 
to default or used
-                * by vfx shaders as initial input
-                */
-               e_data.temp_depth_tx = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_DEPTH_24_STENCIL_8,
-                                                                               
                                 &draw_engine_object_type);
-               e_data.temp_color_tx = DRW_texture_pool_query_2D(size[0], 
size[1], fb_format,
-                                                                               
                                 &draw_engine_object_type);
-               GPU_framebuffer_ensure_config(&fbl->temp_fb, {
-                       GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx),
-                       GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx)
-               });
-
-               /* vfx (ping-pong textures) */
-               e_data.vfx_depth_tx_a = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_DEPTH_24_STENCIL_8,
-                       &draw_engine_object_type);
-               e_data.vfx_color_tx_a = DRW_texture_pool_query_2D(size[0], 
size[1], fb_format,
-                       &draw_engine_object_type);
-               GPU_framebuffer_ensure_config(&fbl->vfx_fb_a, {
-                       GPU_ATTACHMENT_TEXTURE(e_data.vfx_depth_tx_a),
-                       GPU_ATTACHMENT_TEXTURE(e_data.vfx_color_tx_a)
-               });
-
-               e_data.vfx_depth_tx_b = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_DEPTH_24_STENCIL_8,
-                       &draw_engine_object_type);
-               e_data.vfx_color_tx_b = DRW_texture_pool_query_2D(size[0], 
size[1], fb_format,
-                       &draw_engine_object_type);
-               GPU_framebuffer_ensure_config(&fbl->vfx_fb_b, {
-                       GPU_ATTACHMENT_TEXTURE(e_data.vfx_depth_tx_b),
-                       GPU_ATTACHMENT_TEXTURE(e_data.vfx_color_tx_b)
-               });
-
-               /* painting framebuffer to speed up drawing process (always 16 
bits) */
-               e_data.painting_depth_tx = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_DEPTH_24_STENCIL_8,
-                       &draw_engine_object_type);
-               e_data.painting_color_tx = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_RGBA_16,
-                       &draw_engine_object_type);
-               GPU_framebuffer_ensure_config(&fbl->painting_fb, {
-                       GPU_ATTACHMENT_TEXTURE(e_data.painting_depth_tx),
-                       GPU_ATTACHMENT_TEXTURE(e_data.painting_color_tx)
-               });
-       }
        /* normal fill shader */
        if (!e_data.gpencil_fill_sh) {
                e_data.gpencil_fill_sh = DRW_shader_create(
-                       datatoc_gpencil_fill_vert_glsl, NULL,
-                       datatoc_gpencil_fill_frag_glsl, NULL);
+                       datatoc_gpencil_fill_vert_glsl, NULL,
+                       datatoc_gpencil_fill_frag_glsl, NULL);
        }
 
        /* normal stroke shader using geometry to display lines (line mode) */
        if (!e_data.gpencil_stroke_sh) {
                e_data.gpencil_stroke_sh = DRW_shader_create(
-                       datatoc_gpencil_stroke_vert_glsl,
-                       datatoc_gpencil_stroke_geom_glsl,
-                       datatoc_gpencil_stroke_frag_glsl,
-                       NULL);
+                       datatoc_gpencil_stroke_vert_glsl,
+                       datatoc_gpencil_stroke_geom_glsl,
+                       datatoc_gpencil_stroke_frag_glsl,
+                       NULL);
        }
-       
+
        /* dot/rectangle mode for normal strokes using geometry */
        if (!e_data.gpencil_point_sh) {
                e_data.gpencil_point_sh = DRW_shader_create(
-                       datatoc_gpencil_point_vert_glsl,
-                       datatoc_gpencil_point_geom_glsl,
-                       datatoc_gpencil_point_frag_glsl,
-                       NULL);
+                       datatoc_gpencil_point_vert_glsl,
+                       datatoc_gpencil_point_geom_glsl,
+                       datatoc_gpencil_point_frag_glsl,
+                       NULL);
        }
        /* used for edit points or strokes with one point only */
        if (!e_data.gpencil_edit_point_sh) {
@@ -211,6 +156,69 @@ static void GPENCIL_engine_init(void *vedata)
                e_data.gpencil_paper_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_paper_frag_glsl, NULL);
        }
 
+}
+
+
+static void GPENCIL_engine_init(void *vedata)
+{
+       GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+       GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
+       const DRWContextState *draw_ctx = DRW_context_state_get();
+       View3D *v3d = draw_ctx->v3d;
+       RegionView3D *rv3d = draw_ctx->rv3d;
+
+       /* Go full 32bits for rendering */
+       DRWTextureFormat fb_format = DRW_state_is_image_render() ? 
DRW_TEX_RGBA_32 : DRW_TEX_RGBA_16;
+
+       if (DRW_state_is_fbo()) {
+               const float *viewport_size = DRW_viewport_size_get();
+               const int size[2] = { (int)viewport_size[0], 
(int)viewport_size[1] };
+
+               /* temp framebuffer to store all stroke drawing before sending 
to default or used
+                * by vfx shaders as initial input
+                */
+               e_data.temp_depth_tx = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_DEPTH_24_STENCIL_8,
+                                                                               
                                 &draw_engine_object_type);
+               e_data.temp_color_tx = DRW_texture_pool_query_2D(size[0], 
size[1], fb_format,
+                                                                               
                                 &draw_engine_object_type);
+               GPU_framebuffer_ensure_config(&fbl->temp_fb, {
+                       GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx),
+                       GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx)
+               });
+
+               /* vfx (ping-pong textures) */
+               e_data.vfx_depth_tx_a = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_DEPTH_24_STENCIL_8,
+                       &draw_engine_object_type);
+               e_data.vfx_color_tx_a = DRW_texture_pool_query_2D(size[0], 
size[1], fb_format,
+                       &draw_engine_object_type);
+               GPU_framebuffer_ensure_config(&fbl->vfx_fb_a, {
+                       GPU_ATTACHMENT_TEXTURE(e_data.vfx_depth_tx_a),
+                       GPU_ATTACHMENT_TEXTURE(e_data.vfx_color_tx_a)
+               });
+
+               e_data.vfx_depth_tx_b = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_DEPTH_24_STENCIL_8,
+                       &draw_engine_object_type);
+               e_data.vfx_color_tx_b = DRW_texture_pool_query_2D(size[0], 
size[1], fb_format,
+                       &draw_engine_object_type);
+               GPU_framebuffer_ensure_config(&fbl->vfx_fb_b, {
+                       GPU_ATTACHMENT_TEXTURE(e_data.vfx_depth_tx_b),
+                       GPU_ATTACHMENT_TEXTURE(e_data.vfx_color_tx_b)
+               });
+
+               /* painting framebuffer to speed up drawing process (always 16 
bits) */
+               e_data.painting_depth_tx = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_DEPTH_24_STENCIL_8,
+                       &draw_engine_object_type);
+               e_data.painting_color_tx = DRW_texture_pool_query_2D(size[0], 
size[1], DRW_TEX_RGBA_16,
+                       &draw_engine_object_type);
+               GPU_framebuffer_ensure_config(&fbl->painting_fb, {
+                       GPU_ATTACHMENT_TEXTURE(e_data.painting_depth_tx),
+                       GPU_ATTACHMENT_TEXTURE(e_data.painting_color_tx)
+               });
+       }
+
+       /* create shaders */
+       GPENCIL_create_shaders();
+
        if (!stl->storage) {
                stl->storage = MEM_callocN(sizeof(GPENCIL_Storage), 
"GPENCIL_Storage");
        }

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

Reply via email to