[Bf-blender-cvs] [7ba07b7e64c] blender2.8: GPU_batch_from_poly_2d_encoded: optional rctf arg

Campbell Barton noreply at git.blender.org
Mon Jan 15 14:12:08 CET 2018


Commit: 7ba07b7e64c884bf69aa3c31d771e0275d39c1c3
Author: Campbell Barton
Date:   Tue Jan 16 00:06:39 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB7ba07b7e64c884bf69aa3c31d771e0275d39c1c3

GPU_batch_from_poly_2d_encoded: optional rctf arg

Also use compiler attributes

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

M	source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
M	source/blender/gpu/GPU_batch.h
M	source/blender/gpu/intern/gpu_batch.c

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

diff --git a/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
index 6d5b6332ec5..a60204b5f0a 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
@@ -114,7 +114,7 @@ static void button2d_draw_intern(
 			/* We shouldn't need the +1, but a NULL char is set. */
 			char *polys = MEM_mallocN(polys_len + 1, __func__);
 			RNA_property_string_get(mpr->ptr, prop, polys);
-			button->shape_batch = GPU_batch_from_poly_2d_encoded((uchar *)polys, polys_len, -1.0f, 1.0f);
+			button->shape_batch = GPU_batch_from_poly_2d_encoded((uchar *)polys, polys_len, NULL);
 			MEM_freeN(polys);
 		}
 	}
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index 8b2dc2af355..4eaf90b486e 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -33,26 +33,31 @@
 
 #include "../../../intern/gawain/gawain/gwn_batch.h"
 
+struct rctf;
+
 // TODO: CMake magic to do this:
 // #include "gawain/batch.h"
 
+#include "BLI_compiler_attrs.h"
+
 #include "GPU_shader.h"
 
 /* Extend GWN_batch_program_set to use Blender’s library of built-in shader programs. */
 
 /* gpu_batch.c */
-void GWN_batch_program_set_builtin(Gwn_Batch *, GPUBuiltinShader);
+void GWN_batch_program_set_builtin(Gwn_Batch *batch, GPUBuiltinShader shader_id) ATTR_NONNULL(1);
 
 Gwn_Batch *GPU_batch_from_poly_2d_encoded(
-        const uchar *polys_flat, uint polys_flat_len, float min, float max);
+        const uchar *polys_flat, uint polys_flat_len, const struct rctf *rect
+        ) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
 
 void gpu_batch_init(void);
 void gpu_batch_exit(void);
 
 /* gpu_batch_presets.c */
 /* Replacement for gluSphere */
-Gwn_Batch *GPU_batch_preset_sphere(int lod);
-Gwn_Batch *GPU_batch_preset_sphere_wire(int lod);
+Gwn_Batch *GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT;
+Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) ATTR_WARN_UNUSED_RESULT;
 
 void gpu_batch_presets_init(void);
 void gpu_batch_presets_exit(void);
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index deee84e92cb..67a2fc5ab24 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -32,6 +32,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_utildefines.h"
+#include "BLI_rect.h"
 #include "BLI_math.h"
 #include "BLI_polyfill2d.h"
 
@@ -61,25 +62,38 @@ void GWN_batch_program_set_builtin(Gwn_Batch *batch, GPUBuiltinShader shader_id)
  * Creates triangles from a byte-array of polygons.
  *
  * See 'make_shape_2d_from_blend.py' utility to create data to pass to this function.
+ *
+ * \param polys_flat: Pairs of X, Y coordinates (repeating to signify closing the polygon).
+ * \param polys_flat_len: Length of the array (must be an even number).
+ * \param rect: Optional region to map the byte 0..255 coords to. When not set use -1..1.
  */
 Gwn_Batch *GPU_batch_from_poly_2d_encoded(
-        const uchar *polys_flat, uint polys_flat_len, float min, float max)
+        const uchar *polys_flat, uint polys_flat_len, const rctf *rect)
 {
 	uchar (*polys)[2] = (void *)polys_flat;
 	uint polys_len = polys_flat_len / 2;
+	BLI_assert(polys_flat_len == polys_len * 2);
 
 	/* Over alloc in both cases */
 	float (*verts)[2] = MEM_mallocN(sizeof(*verts) * polys_len, __func__);
 	float (*verts_step)[2] = verts;
 	uint (*tris)[3] = MEM_mallocN(sizeof(*tris) * polys_len, __func__);
 	uint (*tris_step)[3] = tris;
-	const float range_uchar = (max - min) / 255.0f;
+
+	const float range_uchar[2] = {
+		(rect ? (rect->xmax - rect->xmin) : 2.0f) / 255.0f,
+		(rect ? (rect->ymax - rect->ymin) : 2.0f) / 255.0f,
+	};
+	const float min_uchar[2] = {
+		(rect ? rect->xmin : -1.0f),
+		(rect ? rect->ymin : -1.0f),
+	};
 
 	uint i_poly = 0;
 	uint i_vert = 0;
 	while (i_poly != polys_len) {
 		for (uint j = 0; j < 2; j++) {
-			verts[i_vert][j] = min + ((float)polys[i_poly][j] * range_uchar);
+			verts[i_vert][j] = min_uchar[j] + ((float)polys[i_poly][j] * range_uchar[j]);
 		}
 		i_vert++;
 		i_poly++;



More information about the Bf-blender-cvs mailing list