Commit: 8e8d93eb86109988db44730a0107e9da9e870328
Author: Antonioya
Date:   Wed Aug 15 16:07:16 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB8e8d93eb86109988db44730a0107e9da9e870328

GP: Redesign logic of drawing engine for object instance support

The initial design assumed that there was only one object for each unique name, 
but that was not the case when instances were created.

Now, instances are supported and speed has been greatly improved when 
repetitions are used.

As a result of this change, the option to create objects has been removed in 
the Instances modifier. This option was strange and was also against Blender's 
design rules, since a modifier should never create objects. The old 
functionality of the modifier can be achieved with instances.

Also, several memory leakage problems that were not previously detected have 
been eliminated, and especially in the grid and in the drawing process

Onion Skin is not supported in multi-user datablocks.  Support this, makes 
incompatible with instances. We need find a solution in the long term, but now 
it's better keep disabled and make instances work. Anyway, the new instances 
makes unnecessary to use muli-user datablocks.

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

M       release/scripts/startup/bl_ui/properties_data_gpencil.py
M       release/scripts/startup/bl_ui/properties_data_modifier.py
M       source/blender/blenkernel/intern/library.c
M       source/blender/draw/engines/gpencil/gpencil_cache_utils.c
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
M       source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M       source/blender/editors/object/object_add.c
M       source/blender/gpencil_modifiers/intern/MOD_gpencilinstance.c
M       source/blender/makesdna/DNA_gpencil_modifier_types.h
M       source/blender/makesdna/DNA_gpencil_types.h
M       source/blender/makesrna/intern/rna_gpencil_modifier.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_gpencil.py 
b/release/scripts/startup/bl_ui/properties_data_gpencil.py
index 90dc86a20bb..effa527e6db 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -266,7 +266,10 @@ class DATA_PT_gpencil_onionpanel(Panel):
 
         layout = self.layout
         layout.use_property_split = True
-        layout.enabled = gpd.use_onion_skinning
+        layout.enabled = gpd.use_onion_skinning and gpd.users <= 1
+
+        if gpd.use_onion_skinning and gpd.users > 1:
+            layout.label("Multiuser datablock not supported", icon='ERROR')
 
         GreasePencilOnionPanel.draw_settings(layout, gpd)
 
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index f865a7f7226..45af80c0a62 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1843,7 +1843,6 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, 
Panel):
 
         col = layout.column()
         col.prop(md, "count")
-        col.prop(md, "use_make_objects")
 
         split = layout.split()
         col = split.column()
diff --git a/source/blender/blenkernel/intern/library.c 
b/source/blender/blenkernel/intern/library.c
index d81dddb2b98..08d68f4a480 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -785,6 +785,14 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, 
PropertyRNA *prop)
                                RNA_property_pointer_set(ptr, prop, idptr);
                                RNA_property_update(C, ptr, prop);
 
+                               /* tag grease pencil datablock and disable 
onion */
+                               if (GS(id->name) == ID_GD) {
+                                       DEG_id_tag_update(id, OB_RECALC_OB | 
OB_RECALC_DATA);
+                                       DEG_id_tag_update(newid, OB_RECALC_OB | 
OB_RECALC_DATA);
+                                       bGPdata *gpd = (bGPdata *)newid;
+                                       gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
+                               }
+
                                return true;
                        }
                }
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c 
b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index e8bb27b2724..4c427a672d2 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -37,9 +37,44 @@
 
 #include "draw_cache_impl.h"
 
+static bool gpencil_check_ob_duplicated(tGPencilObjectCache *cache_array, int 
gp_cache_used, Object *ob)
+{
+       if (gp_cache_used == 0) {
+               return false;
+       }
+
+       for (int i = 0; i < gp_cache_used + 1; i++) {
+               tGPencilObjectCache *cache_elem = &cache_array[i];
+               if (STREQ(cache_elem->ob_name, ob->id.name) &&
+                       (cache_elem->is_dup_ob == false))
+               {
+                       return true;
+               }
+       }
+       return false;
+}
+
+static bool gpencil_check_datablock_duplicated(tGPencilObjectCache 
*cache_array, int gp_cache_used,
+                                                                       Object 
*ob, bGPdata *gpd)
+{
+       if (gp_cache_used == 0) {
+               return false;
+       }
+
+       for (int i = 0; i < gp_cache_used + 1; i++) {
+               tGPencilObjectCache *cache_elem = &cache_array[i];
+               if (!STREQ(cache_elem->ob_name, ob->id.name) &&
+                       (cache_elem->gpd == gpd))
+               {
+                       return true;
+               }
+       }
+       return false;
+}
+
  /* add a gpencil object to cache to defer drawing */
 tGPencilObjectCache *gpencil_object_cache_add(
-        tGPencilObjectCache *cache_array, Object *ob, bool is_temp,
+        tGPencilObjectCache *cache_array, Object *ob,
         int *gp_cache_size, int *gp_cache_used)
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -61,16 +96,26 @@ tGPencilObjectCache *gpencil_object_cache_add(
                }
                cache_array = p;
        }
-
        /* zero out all pointers */
        cache_elem = &cache_array[*gp_cache_used];
        memset(cache_elem, 0, sizeof(*cache_elem));
 
-       /* save object */
-       cache_elem->ob = ob;
-       cache_elem->temp_ob = is_temp;
+       cache_elem->is_dup_ob = gpencil_check_ob_duplicated(cache_array, 
*gp_cache_used, ob);
+
+       sprintf(cache_elem->ob_name, "%s", ob->id.name);
+       cache_elem->gpd = (bGPdata *)ob->data;
+
+       copy_v3_v3(cache_elem->loc, ob->loc);
+       copy_m4_m4(cache_elem->obmat, ob->obmat);
        cache_elem->idx = *gp_cache_used;
 
+       cache_elem->is_dup_onion = 
gpencil_check_datablock_duplicated(cache_array, *gp_cache_used,
+                                                                               
                                                ob, cache_elem->gpd);
+
+       /* save FXs */
+       cache_elem->pixfactor = cache_elem->gpd->pixfactor;
+       cache_elem->shader_fx = ob->shader_fx;
+
        cache_elem->init_grp = 0;
        cache_elem->end_grp = -1;
 
@@ -203,7 +248,7 @@ static void gpencil_batch_cache_init(Object *ob, int cfra)
 }
 
 /* clear cache */
-static void gpencil_batch_cache_clear(GpencilBatchCache *cache, bGPdata *gpd)
+static void gpencil_batch_cache_clear(GpencilBatchCache *cache)
 {
        if (!cache) {
                return;
@@ -213,10 +258,6 @@ static void gpencil_batch_cache_clear(GpencilBatchCache 
*cache, bGPdata *gpd)
                return;
        }
 
-       if (G.debug_value >= 664) {
-               printf("gpencil_batch_cache_clear: %s\n", gpd->id.name);
-       }
-
        if (cache->cache_size > 0) {
                for (int i = 0; i < cache->cache_size; i++) {
                        GPU_BATCH_DISCARD_SAFE(cache->batch_stroke[i]);
@@ -245,7 +286,7 @@ GpencilBatchCache *gpencil_batch_cache_get(Object *ob, int 
cfra)
 
                GpencilBatchCache *cache = gpencil_batch_get_element(ob);
                if (cache) {
-                       gpencil_batch_cache_clear(cache, gpd);
+                       gpencil_batch_cache_clear(cache);
                        BLI_ghash_remove(gpd->runtime.batch_cache_data, 
ob->id.name, NULL, NULL);
                }
                gpencil_batch_cache_init(ob, cfra);
@@ -283,7 +324,7 @@ void DRW_gpencil_batch_cache_free(bGPdata *gpd)
        while (!BLI_ghashIterator_done(ihash)) {
                GpencilBatchCache *cache = (GpencilBatchCache 
*)BLI_ghashIterator_getValue(ihash);
                if (cache) {
-                       gpencil_batch_cache_clear(cache, gpd);
+                       gpencil_batch_cache_clear(cache);
                }
                BLI_ghashIterator_step(ihash);
        }
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 83a52e077ca..2102f255f75 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -52,12 +52,11 @@
 
 /* Helper to add stroke point to vbo */
 static void gpencil_set_stroke_point(
-        GPUVertBuf *vbo, float matrix[4][4], const bGPDspoint *pt, int idx,
+        GPUVertBuf *vbo, const bGPDspoint *pt, int idx,
         uint pos_id, uint color_id,
         uint thickness_id, uint uvdata_id, short thickness,
         const float ink[4])
 {
-       float viewfpt[3];
 
        float alpha = ink[3] * pt->strength;
        CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f);
@@ -71,7 +70,6 @@ static void gpencil_set_stroke_point(
        GPU_vertbuf_attr_set(vbo, uvdata_id, idx, uvdata);
 
        /* the thickness of the stroke must be affected by zoom, so a pixel 
scale is calculated */
-       mul_v3_m4v3(viewfpt, matrix, &pt->x);
        float thick = max_ff(pt->pressure * thickness, 1.0f);
        GPU_vertbuf_attr_set(vbo, thickness_id, idx, &thick);
 
@@ -132,7 +130,7 @@ GPUBatch *DRW_gpencil_get_point_geom(bGPDstroke *gps, short 
thickness, const flo
 }
 
 /* create batch geometry data for stroke shader */
-GPUBatch *DRW_gpencil_get_stroke_geom(bGPDframe *gpf, bGPDstroke *gps, short 
thickness, const float ink[4])
+GPUBatch *DRW_gpencil_get_stroke_geom(bGPDstroke *gps, short thickness, const 
float ink[4])
 {
        bGPDspoint *points = gps->points;
        int totpoints = gps->totpoints;
@@ -159,20 +157,20 @@ GPUBatch *DRW_gpencil_get_stroke_geom(bGPDframe *gpf, 
bGPDstroke *gps, short thi
                if (i == 0) {
                        if (gps->flag & GP_STROKE_CYCLIC && totpoints > 2) {
                                gpencil_set_stroke_point(
-                                       vbo, gpf->runtime.viewmatrix, 
&points[totpoints - 1], idx,
+                                       vbo, &points[totpoints - 1], idx,
                                        pos_id, color_id, thickness_id, 
uvdata_id, thickness, ink);
                                idx++;
                        }
                        else {
                                gpencil_set_stroke_point(
-                                       vbo, gpf->runtime.viewmatrix, 
&points[1], idx,
+                                       vbo, &points[1], idx,
                                        pos_id, color_id, thickness_id, 
uvdata_id, thickness, ink);
                                idx++;
                        }
                }
                /* set point */
                gpencil_set_stroke_point(
-                       vbo, gpf->runtime.viewmatrix, pt, idx,
+                       vbo, pt, idx,
                        pos_id, color_id, thickness_id, uvdata_id, thickness, 
ink);
                idx++;
        }
@@ -180,19 +178,19 @@ GPUBatch *DRW_gpencil_get_stroke_geom(bGPDframe *gpf, 
bGPDstroke *gps, short thi
        if (gps->flag & GP_STROKE_CYCLIC && totpoints > 2) {
                /* draw line to first point to complete the cycle */
                gpencil_set_stroke_point(
-                       vbo, gpf->runtime.viewmatrix, &points[0], idx,
+                       vbo, &points[0], idx,
                        pos_id, color_id, thickness_id, uvdata_id, thickness, 
ink);
                idx++;
                /* now add adjacency point (not drawn) */
                gpencil_set_stroke_point(
-                       vbo, gpf->runtime.viewmatrix, &points[1], idx,
+                       vbo, &points[1], idx,
                        pos_id, color_id, thickness_id, uvdata_id, thickness, 
ink);
                idx++;
        }
        /* last adjacency point (not drawn) */
        else {
                gpencil_set_stroke_point(
-                       vbo, gpf->runtime.viewmatrix, &points[totpoints - 2], 
idx,
+                       vbo, &points[totpoints - 2], idx,
                        pos_id, color_id, thickness_id, uvdata_id, thickness, 
ink);
        }
 
@@ -200,7 +198,7 @@ GPUBatch *DRW_gpencil_get_stroke_geom(bGPDframe *gpf, 
bGPDstroke *gps, short thi
 }
 
 /* create batch geometry data for current buffer stroke shader */
-GPUBatch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, float matrix[4][4], 
short thickness)
+GPUBatch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, short thickness)
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
        Scene *scene = draw_ctx->scene;
@@ -244,19 +242,19 @@ GPUBatch *DRW_gpencil_get_buffer_stroke_geom(bGPdata 
*gpd, float matrix[4][4], s
                        if (totpoints > 1) {
                                ED_gpencil_tpoint_to_point(ar, origin, 
&points[1], &pt2);
                                gpencil_set_stroke_point(
-                                       vbo, matrix, &pt2, idx,
+                                       vbo, &pt2, idx,
                                        pos_id, color_id, thickness_id, 
uvdata_id, thickness, gpd->runtime.scolor);
                        }
                        else {
                                gpencil_set_stroke_point(
-                                       vbo, matrix, &pt, idx,
+                                       vbo, &pt, idx,
                                        pos_id, color_id, thickness_id, 
uvdata_id, thickness, gpd->runtime.scolor);
                        }
                        idx++;
                }
                /* set point */

@@ 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