[Bf-blender-cvs] [a0caa9e6b17] greasepencil-refactor: Cleanup: GPencil: Move GP_MATERIAL_BUFFER_LEN define to a common place

Clément Foucault noreply at git.blender.org
Tue Jan 7 15:31:22 CET 2020


Commit: a0caa9e6b17f843449a3d9be14dfa3c663001a75
Author: Clément Foucault
Date:   Mon Jan 6 11:34:20 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBa0caa9e6b17f843449a3d9be14dfa3c663001a75

Cleanup: GPencil: Move GP_MATERIAL_BUFFER_LEN define to a common place

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_draw_data.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_shader.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
M	source/blender/makesdna/DNA_gpencil_types.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 84ae3f02137..cb2ae1db374 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -129,7 +129,7 @@ static void gpencil_buffer_add_point(
   vert->v_rot = cosf(pt->uv_rot) * signf(pt->uv_rot);
   vert->thickness = max_ff(0.0f, gps->thickness * pt->pressure) * (round_cap1 ? 1.0 : -1.0);
   /* Tag endpoint material to -1 so they get discarded by vertex shader. */
-  vert->mat = (is_endpoint) ? -1 : (gps->mat_nr % GPENCIL_MATERIAL_BUFFER_LEN);
+  vert->mat = (is_endpoint) ? -1 : (gps->mat_nr % GP_MATERIAL_BUFFER_LEN);
 }
 
 static void gpencil_buffer_add_stroke(gpStrokeVert *verts, const bGPDstroke *gps)
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index c22b43716f9..12941fab42a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -115,7 +115,7 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
 
   GPENCIL_MaterialPool *pool = matpool;
   for (int i = 0; i < ob->totcol; i++) {
-    int mat_id = (i % GPENCIL_MATERIAL_BUFFER_LEN);
+    int mat_id = (i % GP_MATERIAL_BUFFER_LEN);
     if ((i > 0) && (mat_id == 0)) {
       pool->next = gpencil_material_pool_add(pd);
       pool = pool->next;
@@ -216,11 +216,11 @@ void gpencil_material_resources_get(GPENCIL_MaterialPool *first_pool,
                                     GPUUniformBuffer **r_ubo_mat)
 {
   GPENCIL_MaterialPool *matpool = first_pool;
-  int pool_id = mat_id / GPENCIL_MATERIAL_BUFFER_LEN;
+  int pool_id = mat_id / GP_MATERIAL_BUFFER_LEN;
   for (int i = 0; i < pool_id; i++) {
     matpool = matpool->next;
   }
-  mat_id = mat_id % GPENCIL_MATERIAL_BUFFER_LEN;
+  mat_id = mat_id % GP_MATERIAL_BUFFER_LEN;
   *r_ubo_mat = matpool->ubo;
   if (r_tex_fill) {
     *r_tex_fill = matpool->tex_fill[mat_id];
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index e410ea6cc0f..8d4d835dfe8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -23,6 +23,8 @@
 #ifndef __GPENCIL_ENGINE_H__
 #define __GPENCIL_ENGINE_H__
 
+#include "DNA_gpencil_types.h"
+
 #include "GPU_batch.h"
 
 extern DrawEngineType draw_engine_gpencil_type;
@@ -56,10 +58,6 @@ struct GPUVertFormat;
 
 #define GP_IS_CAMERAVIEW ((rv3d != NULL) && (rv3d->persp == RV3D_CAMOB && v3d->camera))
 
-/* TODO(fclem) grow this number back when grouping different objects' material together
- * is implemented. */
-#define GPENCIL_MATERIAL_BUFFER_LEN 16
-
 /* UBO structure. Watch out for padding. Must match GLSL declaration. */
 typedef struct gpMaterial {
   float stroke_color[4];
@@ -169,12 +167,12 @@ typedef struct GPENCIL_MaterialPool {
   /* Linklist. */
   struct GPENCIL_MaterialPool *next;
   /* GPU representatin of materials. */
-  gpMaterial mat_data[GPENCIL_MATERIAL_BUFFER_LEN];
+  gpMaterial mat_data[GP_MATERIAL_BUFFER_LEN];
   /* Matching ubo. */
   struct GPUUniformBuffer *ubo;
   /* Texture per material. NULL means none. */
-  struct GPUTexture *tex_fill[GPENCIL_MATERIAL_BUFFER_LEN];
-  struct GPUTexture *tex_stroke[GPENCIL_MATERIAL_BUFFER_LEN];
+  struct GPUTexture *tex_fill[GP_MATERIAL_BUFFER_LEN];
+  struct GPUTexture *tex_stroke[GP_MATERIAL_BUFFER_LEN];
 } GPENCIL_MaterialPool;
 
 typedef struct GPENCIL_LightPool {
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader.c b/source/blender/draw/engines/gpencil/gpencil_shader.c
index 802498ebf26..7f11de84f5c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader.c
@@ -102,7 +102,7 @@ struct GPUShader *GPENCIL_shader_geometry_get(GPENCIL_e_data *e_data)
             },
         .defs =
             (const char *[]){
-                "#define GPENCIL_MATERIAL_BUFFER_LEN " STRINGIFY(GPENCIL_MATERIAL_BUFFER_LEN) "\n",
+                "#define GP_MATERIAL_BUFFER_LEN " STRINGIFY(GP_MATERIAL_BUFFER_LEN) "\n",
                 "#define GPENCIL_LIGHT_BUFFER_LEN " STRINGIFY(GPENCIL_LIGHT_BUFFER_LEN) "\n",
                 NULL,
             },
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
index 00a83b8e214..089442ed666 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -57,11 +57,11 @@ struct gpLight {
 #define GP_LIGHT_TYPE_SUN 2.0
 #define GP_LIGHT_TYPE_AMBIENT 3.0
 
-#ifdef GPENCIL_MATERIAL_BUFFER_LEN
+#ifdef GP_MATERIAL_BUFFER_LEN
 
 layout(std140) uniform gpMaterialBlock
 {
-  gpMaterial materials[GPENCIL_MATERIAL_BUFFER_LEN];
+  gpMaterial materials[GP_MATERIAL_BUFFER_LEN];
 };
 
 #endif
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 0ae3f2ff1b9..ba3a6f6e0b7 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -36,6 +36,10 @@ struct MDeformVert;
 #define GP_DEFAULT_GRID_LINES 4
 #define GP_MAX_INPUT_SAMPLES 10
 
+/* TODO(fclem) grow this number back when grouping different objects' material together
+ * is implemented. */
+#define GP_MATERIAL_BUFFER_LEN 16
+
 /* ***************************************** */
 /* GP Stroke Points */



More information about the Bf-blender-cvs mailing list