Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-01-15 16:06:39 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-01-15 16:16:54 +0300
commit7ba07b7e64c884bf69aa3c31d771e0275d39c1c3 (patch)
treee2da831e166f213ebb381f3d196da7370726f912
parent5cb43b0f2037c903c635609c75ebf0c3a23ad146 (diff)
GPU_batch_from_poly_2d_encoded: optional rctf arg
Also use compiler attributes
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c2
-rw-r--r--source/blender/gpu/GPU_batch.h13
-rw-r--r--source/blender/gpu/intern/gpu_batch.c20
3 files changed, 27 insertions, 8 deletions
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++;