[Bf-blender-cvs] [4d51bfecdbb] greasepencil-refactor: GPencil: Refactor: Fix onion overlay toggle

Clément Foucault noreply at git.blender.org
Wed Jan 1 03:58:47 CET 2020


Commit: 4d51bfecdbb45bb40b98c785b3b199273a05cec3
Author: Clément Foucault
Date:   Wed Jan 1 03:58:05 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB4d51bfecdbb45bb40b98c785b3b199273a05cec3

GPencil: Refactor: Fix onion overlay toggle

This make the assumption that the onion skins are always needed when.
This as a performance impact that will be fixed later.

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index d166857d86c..457965f050c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -198,6 +198,11 @@ static void gpencil_batches_ensure(Object *ob, GpencilBatchCache *cache)
     /* Should be discarded together. */
     BLI_assert(cache->vbo == NULL && cache->ibo == NULL);
     BLI_assert(cache->stroke_batch == NULL && cache->stroke_batch == NULL);
+    /* TODO/PERF: Could be changed to only do it if needed.
+     * For now it's simpler to assume we always need it
+     * since multiple viewport could or could not need it.
+     * Ideally we should have a dedicated onion skin geom batch. */
+    bool do_onion = true;
 
     /* First count how many vertices and triangles are needed for the whole object. */
     gpIterData iter = {
@@ -207,7 +212,7 @@ static void gpencil_batches_ensure(Object *ob, GpencilBatchCache *cache)
         .vert_len = 1, /* Start at 1 for the gl_InstanceID trick to work (see vert shader). */
         .tri_len = 0,
     };
-    gpencil_object_visible_stroke_iter(ob, NULL, gp_object_verts_count_cb, &iter);
+    gpencil_object_visible_stroke_iter(ob, NULL, gp_object_verts_count_cb, &iter, do_onion);
 
     /* Create VBO. */
     GPUVertFormat *format = gpencil_stroke_format();
@@ -219,7 +224,7 @@ static void gpencil_batches_ensure(Object *ob, GpencilBatchCache *cache)
     GPU_indexbuf_init(&iter.ibo, GPU_PRIM_TRIS, iter.tri_len, iter.vert_len);
 
     /* Fill buffers with data. */
-    gpencil_object_visible_stroke_iter(ob, NULL, gpencil_stroke_iter_cb, &iter);
+    gpencil_object_visible_stroke_iter(ob, NULL, gpencil_stroke_iter_cb, &iter, do_onion);
 
     /* Finish the IBO. */
     cache->ibo = GPU_indexbuf_build(&iter.ibo);
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 85d8e828c46..7270c257e52 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -60,18 +60,12 @@
  *
  * \{ */
 
-void gpencil_object_visible_stroke_iter(Object *ob,
-                                        gpIterCb layer_cb,
-                                        gpIterCb stroke_cb,
-                                        void *thunk)
+void gpencil_object_visible_stroke_iter(
+    Object *ob, gpIterCb layer_cb, gpIterCb stroke_cb, void *thunk, bool do_onion)
 {
   bGPdata *gpd = (bGPdata *)ob->data;
-  const bool main_onion = true; /* TODO */  // stl->storage->is_main_onion;
-  const bool playing = false; /* TODO */    // stl->storage->is_playing;
-  const bool overlay = true; /* TODO */     // stl->storage->is_main_overlay;
-  const bool do_onion = ((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0) && overlay && main_onion &&
-                        !playing && gpencil_onion_active(gpd);
-  const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
+  const bool is_multiedit = GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
+  const bool is_onion = do_onion && ((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0);
 
   /* Onion skinning. */
   const bool onion_mode_abs = (gpd->onion_mode == GP_ONION_MODE_ABSOLUTE);
@@ -90,13 +84,13 @@ void gpencil_object_visible_stroke_iter(Object *ob,
     bGPDframe *act_gpf = gpl->actframe;
     bGPDframe *sta_gpf = act_gpf;
     bGPDframe *end_gpf = act_gpf ? act_gpf->next : NULL;
-    const bool is_onion = (do_onion && (gpl->onion_flag & GP_LAYER_ONIONSKIN));
+
     if (gpl->flag & GP_LAYER_HIDE) {
       idx_eval++;
       continue;
     }
 
-    if (is_onion) {
+    if (is_onion && (gpl->onion_flag & GP_LAYER_ONIONSKIN)) {
       if (act_gpf) {
         bGPDframe *last_gpf = gpl->frames.last;
 
@@ -153,7 +147,7 @@ void gpencil_object_visible_stroke_iter(Object *ob,
       }
     }
     else {
-      act_gpf = &ob->runtime.gpencil_evaluated_frames[idx_eval];
+      /* Bypass multiedit/onion skinning. */
       end_gpf = sta_gpf = NULL;
     }
 
@@ -176,6 +170,9 @@ void gpencil_object_visible_stroke_iter(Object *ob,
       }
     }
     /* Draw Active frame on top. */
+    /* Use evaluated frame (with modifiers for active stroke)/ */
+    act_gpf = &ob->runtime.gpencil_evaluated_frames[idx_eval];
+    act_gpf->runtime.onion_id = 0;
     if (act_gpf) {
       if (layer_cb) {
         layer_cb(gpl, act_gpf, NULL, thunk);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 900216751c8..e664e474583 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -449,6 +449,13 @@ static void GPENCIL_cache_init_new(void *ved)
   const DRWContextState *draw_ctx = DRW_context_state_get();
   pd->cfra = (int)DEG_get_ctime(draw_ctx->depsgraph);
 
+  const bool hide_overlay = ((draw_ctx->v3d->flag2 & V3D_HIDE_OVERLAYS) != 0);
+  const bool show_onion = ((draw_ctx->v3d->gp_flag & V3D_GP_SHOW_ONION_SKIN) != 0);
+  const bool playing = (draw_ctx->evil_C != NULL) ?
+                           ED_screen_animation_playing(CTX_wm_manager(draw_ctx->evil_C)) != NULL :
+                           false;
+  pd->do_onion = show_onion && !hide_overlay && !playing;
+
   {
     DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM;
     DRW_PASS_CREATE(psl->composite_ps, state);
@@ -861,7 +868,6 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
                                     bGPDstroke *UNUSED(gps),
                                     void *thunk)
 {
-  DRWShadingGroup *grp;
   gpIterPopulateData *iter = (gpIterPopulateData *)thunk;
   bGPdata *gpd = (bGPdata *)iter->ob->data;
 
@@ -1008,7 +1014,7 @@ static void GPENCIL_cache_populate_new(void *ved, Object *ob)
     iter.tex_stroke = txl->dummy_texture;
 
     gpencil_object_visible_stroke_iter(
-        ob, gp_layer_cache_populate, gp_stroke_cache_populate, &iter);
+        ob, gp_layer_cache_populate, gp_stroke_cache_populate, &iter, pd->do_onion);
 
     gpencil_vfx_cache_populate(vedata, ob, iter.tgp_ob);
   }
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 020d6e5de66..ffe821f4f3c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -490,6 +490,8 @@ typedef struct GPENCIL_PrivateData {
   float dof_params[2];
   /* Used for DoF Setup. */
   Object *camera;
+  /* Display onion skinning */
+  bool do_onion;
 } GPENCIL_PrivateData;
 
 /* flags for fast drawing support */
@@ -631,10 +633,8 @@ typedef void (*gpIterCb)(struct bGPDlayer *layer,
                          struct bGPDstroke *stroke,
                          void *thunk);
 
-void gpencil_object_visible_stroke_iter(Object *ob,
-                                        gpIterCb layer_cb,
-                                        gpIterCb stroke_cb,
-                                        void *thunk);
+void gpencil_object_visible_stroke_iter(
+    Object *ob, gpIterCb layer_cb, gpIterCb stroke_cb, void *thunk, bool do_onion);
 
 /* general drawing functions */
 struct DRWShadingGroup *gpencil_shgroup_stroke_create(struct GPENCIL_e_data *e_data,



More information about the Bf-blender-cvs mailing list