Cleanup: remove redundant doxygen \file argument
[blender.git] / source / blender / draw / engines / gpencil / gpencil_engine.c
index 483d6a8..eff8d07 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * Copyright 2017, Blender Foundation.
- *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * Contributor(s): Antonio Vazquez
- *
+ * Copyright 2017, Blender Foundation.
  */
 
-/** \file blender/draw/engines/gpencil/gpencil_engine.c
- *  \ingroup draw
+/** \file \ingroup draw
  */
 #include "DRW_engine.h"
 #include "DRW_render.h"
 
-#include "BKE_camera.h"
 #include "BKE_object.h"
-#include "BKE_paint.h"
-#include "BKE_gpencil.h"
 #include "BKE_shader_fx.h"
 
 #include "DNA_gpencil_types.h"
@@ -36,7 +29,6 @@
 
 #include "draw_mode_engines.h"
 
-#include "UI_resources.h"
 
 #include "GPU_texture.h"
 
@@ -45,9 +37,7 @@
 #include "DEG_depsgraph_query.h"
 
 #include "ED_screen.h"
-#include "ED_gpencil.h"
 
-#include "WM_api.h"
 
 extern char datatoc_gpencil_fill_vert_glsl[];
 extern char datatoc_gpencil_fill_frag_glsl[];
@@ -90,7 +80,7 @@ void DRW_gpencil_multisample_ensure(GPENCIL_Data *vedata, int rect_w, int rect_h
                                }
                                if (txl->multisample_depth == NULL) {
                                        txl->multisample_depth = GPU_texture_create_2D_multisample(
-                                               rect_w, rect_h, GPU_DEPTH24_STENCIL8, NULL, samples, NULL);
+                                               rect_w, rect_h, GPU_DEPTH_COMPONENT24, NULL, samples, NULL);
                                }
                                GPU_framebuffer_ensure_config(
                                        &fbl->multisample_fb, {
@@ -108,65 +98,74 @@ static void GPENCIL_create_framebuffers(void *vedata)
        GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 
        /* Go full 32bits for rendering */
-       GPUTextureFormat fb_format = DRW_state_is_image_render() ? GPU_RGBA32F : GPU_RGBA16F;
+       eGPUTextureFormat fb_format = DRW_state_is_image_render() ? GPU_RGBA32F : GPU_RGBA16F;
 
        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] };
 
                /* create multiframe framebuffer for AA */
-               if (stl->storage->multisamples > 0) {
+               if ((stl->storage->framebuffer_flag & GP_FRAMEBUFFER_MULTISAMPLE) &&
+                   (stl->storage->multisamples > 0))
+               {
                        DRW_gpencil_multisample_ensure(vedata, size[0], size[1]);
                }
 
-               /* temp textures */
-               e_data.temp_depth_tx_a = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8,
-                       &draw_engine_gpencil_type);
-               e_data.temp_color_tx_a = DRW_texture_pool_query_2D(size[0], size[1], fb_format,
-                       &draw_engine_gpencil_type);
-               GPU_framebuffer_ensure_config(
-                       &fbl->temp_fb_a, {
-                           GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_a),
-                           GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_a)
-                       });
-
-               e_data.temp_depth_tx_b = DRW_texture_pool_query_2D(
-                       size[0], size[1], GPU_DEPTH24_STENCIL8,
-                       &draw_engine_gpencil_type);
-               e_data.temp_color_tx_b = DRW_texture_pool_query_2D(
-                       size[0], size[1], fb_format,
-                       &draw_engine_gpencil_type);
-               GPU_framebuffer_ensure_config(
-                       &fbl->temp_fb_b, {
-                           GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_b),
-                           GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_b)
-                       });
-
-               /* used for rim and shadow FX effects */
-               e_data.temp_depth_tx_fx = DRW_texture_pool_query_2D(
-                       size[0], size[1], GPU_DEPTH24_STENCIL8,
-                       &draw_engine_gpencil_type);
-               e_data.temp_color_tx_fx = DRW_texture_pool_query_2D(
-                       size[0], size[1], fb_format,
-                       &draw_engine_gpencil_type);
-               GPU_framebuffer_ensure_config(
-                       &fbl->temp_fb_fx, {
-                           GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_fx),
-                           GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_fx),
-                       });
+               /* Framebufers for basic object drawing */
+               if (stl->storage->framebuffer_flag & GP_FRAMEBUFFER_BASIC) {
+                       /* temp textures for ping-pong buffers */
+                       e_data.temp_depth_tx_a = DRW_texture_pool_query_2D(
+                               size[0], size[1], GPU_DEPTH_COMPONENT24,
+                               &draw_engine_gpencil_type);
+                       e_data.temp_color_tx_a = DRW_texture_pool_query_2D(
+                               size[0], size[1], fb_format,
+                               &draw_engine_gpencil_type);
+                       GPU_framebuffer_ensure_config(
+                               &fbl->temp_fb_a, {
+                                       GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_a),
+                                       GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_a)
+                               });
+
+                       e_data.temp_depth_tx_b = DRW_texture_pool_query_2D(
+                               size[0], size[1], GPU_DEPTH_COMPONENT24,
+                               &draw_engine_gpencil_type);
+                       e_data.temp_color_tx_b = DRW_texture_pool_query_2D(
+                               size[0], size[1], fb_format,
+                               &draw_engine_gpencil_type);
+                       GPU_framebuffer_ensure_config(
+                               &fbl->temp_fb_b, {
+                                       GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_b),
+                                       GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_b)
+                               });
+
+                       /* used for FX effects and Layer blending */
+                       e_data.temp_depth_tx_fx = DRW_texture_pool_query_2D(
+                               size[0], size[1], GPU_DEPTH_COMPONENT24,
+                               &draw_engine_gpencil_type);
+                       e_data.temp_color_tx_fx = DRW_texture_pool_query_2D(
+                               size[0], size[1], fb_format,
+                               &draw_engine_gpencil_type);
+                       GPU_framebuffer_ensure_config(
+                               &fbl->temp_fb_fx, {
+                                       GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_fx),
+                                       GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_fx),
+                               });
+               }
 
                /* background framebuffer to speed up drawing process (always 16 bits) */
-               e_data.background_depth_tx = DRW_texture_pool_query_2D(
-                       size[0], size[1], GPU_DEPTH24_STENCIL8,
-                       &draw_engine_gpencil_type);
-               e_data.background_color_tx = DRW_texture_pool_query_2D(
-                       size[0], size[1], GPU_RGBA32F,
-                       &draw_engine_gpencil_type);
-               GPU_framebuffer_ensure_config(
-                       &fbl->background_fb, {
-                           GPU_ATTACHMENT_TEXTURE(e_data.background_depth_tx),
-                           GPU_ATTACHMENT_TEXTURE(e_data.background_color_tx)
-                       });
+               if (stl->storage->framebuffer_flag & GP_FRAMEBUFFER_DRAW) {
+                       e_data.background_depth_tx = DRW_texture_pool_query_2D(
+                               size[0], size[1], GPU_DEPTH_COMPONENT24,
+                               &draw_engine_gpencil_type);
+                       e_data.background_color_tx = DRW_texture_pool_query_2D(
+                               size[0], size[1], GPU_RGBA32F,
+                               &draw_engine_gpencil_type);
+                       GPU_framebuffer_ensure_config(
+                               &fbl->background_fb, {
+                                       GPU_ATTACHMENT_TEXTURE(e_data.background_depth_tx),
+                                       GPU_ATTACHMENT_TEXTURE(e_data.background_color_tx)
+                               });
+               }
        }
 }
 
@@ -249,9 +248,6 @@ void GPENCIL_engine_init(void *vedata)
 
        stl->storage->multisamples = U.gpencil_multisamples;
 
-       /* create framebuffers */
-       GPENCIL_create_framebuffers(vedata);
-
        /* create shaders */
        GPENCIL_create_shaders();
        GPENCIL_create_fx_shaders(&e_data);
@@ -284,6 +280,9 @@ static void GPENCIL_engine_free(void)
        GPU_BATCH_DISCARD_SAFE(e_data.batch_buffer_fill);
        MEM_SAFE_FREE(e_data.batch_buffer_fill);
 
+       GPU_BATCH_DISCARD_SAFE(e_data.batch_buffer_ctrlpoint);
+       MEM_SAFE_FREE(e_data.batch_buffer_ctrlpoint);
+
        GPU_BATCH_DISCARD_SAFE(e_data.batch_grid);
        MEM_SAFE_FREE(e_data.batch_grid);
 
@@ -550,7 +549,7 @@ static void gpencil_add_draw_data(void *vedata, Object *ob)
 void GPENCIL_cache_populate(void *vedata, Object *ob)
 {
        /* object must be visible */
-       if (!DRW_object_is_visible_in_active_context(ob)) {
+       if (!(DRW_object_visibility_in_active_context(ob) & OB_VISIBLE_SELF)) {
                return;
        }
 
@@ -563,6 +562,10 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
        if (ob->type == OB_GPENCIL && ob->data) {
                bGPdata *gpd = (bGPdata *)ob->data;
 
+               /* enable multisample and basic framebuffer creation */
+               stl->storage->framebuffer_flag |= GP_FRAMEBUFFER_MULTISAMPLE;
+               stl->storage->framebuffer_flag |= GP_FRAMEBUFFER_BASIC;
+
                /* when start/stop animation the cache must be set as dirty to reset all data */
                if (stl->storage->reset_cache) {
                        gpd->flag |= GP_DATA_CACHE_IS_DIRTY;
@@ -612,16 +615,27 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
                        }
 
                        DRW_shgroup_call_add(
-                               stl->g_data->shgrps_grid,
-                               e_data.batch_grid,
-                               stl->storage->grid_matrix);
+                               stl->g_data->shgrps_grid,
+                               e_data.batch_grid,
+                               stl->storage->grid_matrix);
                }
        }
 }
 
 void GPENCIL_cache_finish(void *vedata)
 {
+       GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+
+       /* draw particles */
        DRW_gpencil_populate_particles(&e_data, vedata);
+
+       if (stl->g_data->session_flag & (GP_DRW_PAINT_IDLE | GP_DRW_PAINT_FILLING)) {
+               stl->storage->framebuffer_flag |= GP_FRAMEBUFFER_DRAW;
+       }
+
+       /* create framebuffers */
+       GPENCIL_create_framebuffers(vedata);
+
 }
 
 /* helper function to sort inverse gpencil objects using qsort */
@@ -719,6 +733,8 @@ void GPENCIL_draw_scene(void *ved)
        Object *obact = draw_ctx->obact;
        const bool playing = stl->storage->is_playing;
        const bool is_render = stl->storage->is_render;
+       bGPdata *gpd_act = (obact) && (obact->type == OB_GPENCIL) ? (bGPdata *)obact->data : NULL;
+       const bool is_edit = GPENCIL_ANY_EDIT_MODE(gpd_act);
 
        /* paper pass to display a comfortable area to draw over complex scenes with geometry */
        if ((!is_render) && (obact) && (obact->type == OB_GPENCIL)) {
@@ -804,9 +820,9 @@ void GPENCIL_draw_scene(void *ved)
                                                        GPU_framebuffer_bind(fbl->temp_fb_fx);
                                                        GPU_framebuffer_clear_color_depth(fbl->temp_fb_fx, clearcol, 1.0f);
                                                        gpencil_draw_pass_range(
-                                                               fbl, stl, psl, txl, fbl->temp_fb_fx,
-                                                               init_shgrp, end_shgrp,
-                                                               is_last);
+                                                               fbl, stl, psl, txl, fbl->temp_fb_fx,
+                                                               init_shgrp, end_shgrp,
+                                                               is_last);
 
                                                        /* Blend A texture and FX texture */
                                                        GPU_framebuffer_bind(fbl->temp_fb_b);
@@ -833,9 +849,9 @@ void GPENCIL_draw_scene(void *ved)
                                        }
                                        /* last group */
                                        gpencil_draw_pass_range(
-                                               fbl, stl, psl, txl, fbl->temp_fb_a,
-                                               init_shgrp, end_shgrp,
-                                               true);
+                                               fbl, stl, psl, txl, fbl->temp_fb_a,
+                                               init_shgrp, end_shgrp,
+                                               true);
                                }
 
                                /* Current buffer drawing */
@@ -875,7 +891,7 @@ void GPENCIL_draw_scene(void *ved)
                                }
                        }
                        /* edit points */
-                       if ((!is_render) && (!playing)) {
+                       if ((!is_render) && (!playing) && (is_edit)) {
                                DRW_draw_pass(psl->edit_pass);
                        }
                }