[Bf-blender-cvs] [c825dc6b86f] greasepencil-object: GPencil: Fix problem with first stroke color

Antonio Vazquez noreply at git.blender.org
Mon Feb 24 09:52:23 CET 2020


Commit: c825dc6b86fb387b70943671b0de6126473bf829
Author: Antonio Vazquez
Date:   Mon Feb 24 09:50:09 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rBc825dc6b86fb387b70943671b0de6126473bf829

GPencil: Fix problem with first stroke color

When use a new material, the color only changed after first stroke. This was related to the tag of the depsgraph that is done only at the end of drawing due perfromance and fast response.

Now, the value is copied to the runtime data.

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

M	source/blender/draw/intern/draw_cache_impl_gpencil.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h

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

diff --git a/source/blender/draw/intern/draw_cache_impl_gpencil.c b/source/blender/draw/intern/draw_cache_impl_gpencil.c
index 06fe14b1c72..0d913c49e58 100644
--- a/source/blender/draw/intern/draw_cache_impl_gpencil.c
+++ b/source/blender/draw/intern/draw_cache_impl_gpencil.c
@@ -511,7 +511,6 @@ bGPDstroke *DRW_cache_gpencil_sbuffer_stroke_data_get(Object *ob)
   return gpd->runtime.sbuffer_gps;
 }
 
-/* gpd is original ID. */
 static void gpencil_sbuffer_stroke_ensure(bGPdata *gpd, bool do_stroke, bool do_fill)
 {
   tGPspoint *tpoints = gpd->runtime.sbuffer;
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index f829aa586a9..8e09da60580 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -164,7 +164,7 @@ typedef struct tGPDprimitive {
   /** current GP datablock */
   struct bGPdata *gpd;
   /** current material */
-  struct Material *mat;
+  struct Material *material;
   /** current brush */
   struct Brush *brush;
 
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index ad074c00644..5060f3ed87d 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -742,7 +742,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
     }
 
     /* Set vertex colors for buffer. */
-    ED_gpencil_sbuffer_vertex_color_set(p->depsgraph, p->ob, p->scene->toolsettings, p->brush);
+    ED_gpencil_sbuffer_vertex_color_set(
+        p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material);
 
     /* get pointer to destination point */
     pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used);
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index db8a90fd48c..4102904a311 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -123,7 +123,8 @@ static void gp_session_validatebuffer(tGPDprimitive *p)
   gpd->runtime.sbuffer_sflag |= GP_STROKE_3DSPACE;
 
   /* Set vertex colors for buffer. */
-  ED_gpencil_sbuffer_vertex_color_set(p->depsgraph, p->ob, p->scene->toolsettings, p->brush);
+  ED_gpencil_sbuffer_vertex_color_set(
+      p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material);
 
   if (ELEM(p->type, GP_STROKE_BOX, GP_STROKE_CIRCLE)) {
     gpd->runtime.sbuffer_sflag |= GP_STROKE_CYCLIC;
@@ -136,9 +137,9 @@ static void gp_init_colors(tGPDprimitive *p)
   Brush *brush = p->brush;
 
   /* use brush material */
-  p->mat = BKE_gpencil_object_material_ensure_from_active_input_brush(p->bmain, p->ob, brush);
+  p->material = BKE_gpencil_object_material_ensure_from_active_input_brush(p->bmain, p->ob, brush);
 
-  gpd->runtime.matid = BKE_object_material_slot_find_index(p->ob, p->mat);
+  gpd->runtime.matid = BKE_object_material_slot_find_index(p->ob, p->material);
   gpd->runtime.sbuffer_brush = brush;
 }
 
@@ -1170,7 +1171,7 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
   tgpi->gpd->runtime.tot_cp_points = 0;
 
   /* getcolor info */
-  tgpi->mat = BKE_gpencil_object_material_ensure_from_active_input_toolsettings(
+  tgpi->material = BKE_gpencil_object_material_ensure_from_active_input_toolsettings(
       bmain, tgpi->ob, ts);
 
   /* set parameters */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index a97a363dc12..5523a5aae16 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2530,14 +2530,13 @@ void ED_gpencil_point_vertex_color_set(ToolSettings *ts, Brush *brush, bGPDspoin
   }
 }
 
-void ED_gpencil_sbuffer_vertex_color_set(Depsgraph *depsgraph,
-                                         Object *ob,
-                                         ToolSettings *ts,
-                                         Brush *brush)
+void ED_gpencil_sbuffer_vertex_color_set(
+    Depsgraph *depsgraph, Object *ob, ToolSettings *ts, Brush *brush, Material *material)
 {
   bGPdata *gpd = (bGPdata *)ob->data;
   Object *ob_eval = (Object *)DEG_get_evaluated_id(depsgraph, &ob->id);
   bGPdata *gpd_eval = (bGPdata *)ob_eval->data;
+  MaterialGPencilStyle *gp_style = material->gp_style;
 
   float vertex_color[4];
   copy_v3_v3(vertex_color, brush->rgb);
@@ -2549,14 +2548,14 @@ void ED_gpencil_sbuffer_vertex_color_set(Depsgraph *depsgraph,
     copy_v4_v4(gpd->runtime.vert_color_fill, vertex_color);
   }
   else {
-    zero_v4(gpd->runtime.vert_color_fill);
+    copy_v4_v4(gpd->runtime.vert_color_fill, gp_style->fill_rgba);
   }
   /* Copy stroke vertex color. */
   if (GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush)) {
     copy_v4_v4(gpd->runtime.vert_color, vertex_color);
   }
   else {
-    zero_v4(gpd->runtime.vert_color);
+    copy_v4_v4(gpd->runtime.vert_color, gp_style->stroke_rgba);
   }
 
   /* Copy to eval data because paint operators don't tag refresh until end for speedup painting. */
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 623c97ccb4f..584d0fff3a5 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -293,7 +293,8 @@ void ED_gpencil_point_vertex_color_set(struct ToolSettings *ts,
 void ED_gpencil_sbuffer_vertex_color_set(struct Depsgraph *depsgraph,
                                          struct Object *ob,
                                          struct ToolSettings *ts,
-                                         struct Brush *brush);
+                                         struct Brush *brush,
+                                         struct Material *material);
 
 bool ED_gpencil_stroke_check_collision(struct GP_SpaceConversion *gsc,
                                        struct bGPDstroke *gps,



More information about the Bf-blender-cvs mailing list