[Bf-blender-cvs] [62a8d9fb12c] greasepencil-object: Create a shading group by stroke

Antonio Vazquez noreply at git.blender.org
Sun May 21 16:30:15 CEST 2017


Commit: 62a8d9fb12c10ea16f1b345883f62f82322e3282
Author: Antonio Vazquez
Date:   Sun May 21 13:20:28 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB62a8d9fb12c10ea16f1b345883f62f82322e3282

Create a shading group by stroke

As the drawing order is very important in 2D, each stroke must use its own shading group and don't share with others or the drawing order is missing and the layer system does not work.

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.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 bb1e8933a67..38b2bf0bbe6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -277,19 +277,6 @@ DRWShadingGroup *DRW_gpencil_shgroup_drawing_fill_create(DRWPass *pass, GPUShade
 	return grp;
 }
 
-/* find shader group */
-static int DRW_gpencil_shgroup_find(GPENCIL_Storage *storage, PaletteColor *palcolor)
-{
-	for (int i = 0; i < storage->pal_id; ++i) {
-		if (storage->materials[i] == palcolor) {
-			return i;
-		}
-	}
-
-	/* not found */
-	return -1;
-}
-
 /* add fill shading group to pass */
 static void gpencil_add_fill_shgroup(GpencilBatchCache *cache, DRWShadingGroup *fillgrp, 
 	bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps, 
@@ -406,16 +393,17 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
 		if (gpencil_can_draw_stroke(rv3d, gpf, gps) == false) {
 			continue;
 		}
-		/* try to find shader group or create a new one */
+
+		/* limit the number of shading groups */
+		if (stl->storage->pal_id >= MAX_GPENCIL_MAT) {
+			continue;
+		}
+
 		if (gps->totpoints > 1) {
-			int id = DRW_gpencil_shgroup_find(stl->storage, gps->palcolor);
-			if (id == -1) {
-				id = stl->storage->pal_id;
-				stl->storage->materials[id] = gps->palcolor;
-				stl->storage->shgrps_fill[id] = DRW_gpencil_shgroup_fill_create(vedata, psl->stroke_pass, e_data->gpencil_fill_sh, gpd, gps->palcolor, id);
-				stl->storage->shgrps_stroke[id] = DRW_gpencil_shgroup_stroke_create(vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, gpd);
-				++stl->storage->pal_id;
-			}
+			int id = stl->storage->pal_id;
+			stl->storage->shgrps_fill[id] = DRW_gpencil_shgroup_fill_create(vedata, psl->stroke_pass, e_data->gpencil_fill_sh, gpd, gps->palcolor, id);
+			stl->storage->shgrps_stroke[id] = DRW_gpencil_shgroup_stroke_create(vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, gpd);
+			++stl->storage->pal_id;
 
 			fillgrp = stl->storage->shgrps_fill[id];
 			strokegrp = stl->storage->shgrps_stroke[id];
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 3eec7b5db71..1a35acb8bfb 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -130,7 +130,6 @@ static void GPENCIL_cache_init(void *vedata)
 		stl->storage->pal_id = 0;
 		memset(stl->storage->shgrps_fill, 0, sizeof(DRWShadingGroup *) * MAX_GPENCIL_MAT);
 		memset(stl->storage->shgrps_stroke, 0, sizeof(DRWShadingGroup *) * MAX_GPENCIL_MAT);
-		memset(stl->storage->materials, 0, sizeof(PaletteColor *) * MAX_GPENCIL_MAT);
 		stl->g_data->shgrps_point_volumetric = DRW_gpencil_shgroup_point_volumetric_create(psl->stroke_pass, e_data.gpencil_volumetric_sh);
 
 		state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 96735435c69..c9cb7256528 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -28,7 +28,7 @@
 
 #include "GPU_batch.h"
 
-#define MAX_GPENCIL_MAT 512 
+#define MAX_GPENCIL_MAT 65536
 #define GPENCIL_MIN_BATCH_SLOTS_CHUNK 8
 
  /* *********** LISTS *********** */
@@ -38,7 +38,6 @@ typedef struct GPENCIL_Storage {
 	int t_flip[MAX_GPENCIL_MAT];
 	int t_clamp[MAX_GPENCIL_MAT];
 	int fill_style[MAX_GPENCIL_MAT];
-	PaletteColor *materials[MAX_GPENCIL_MAT];
 	DRWShadingGroup *shgrps_fill[MAX_GPENCIL_MAT];
 	DRWShadingGroup *shgrps_stroke[MAX_GPENCIL_MAT];
 	float unit_matrix[4][4];




More information about the Bf-blender-cvs mailing list