[Bf-blender-cvs] [b1f700d] blender2.8: Gawain: use PRIM_ and INDEX_ enums instead of GLenum
Mike Erwin
noreply at git.blender.org
Wed Nov 16 22:04:10 CET 2016
Commit: b1f700dad36c943c2c2a6f5477a4400cba5803f0
Author: Mike Erwin
Date: Wed Nov 16 16:03:15 2016 -0500
Branches: blender2.8
https://developer.blender.org/rBb1f700dad36c943c2c2a6f5477a4400cba5803f0
Gawain: use PRIM_ and INDEX_ enums instead of GLenum
For a few reasons:
- separate enum sets for separate concepts
- debug with symbolic names instead of 0x4e72
- prepare for a Vulkan future
===================================================================
M source/blender/gpu/gawain/batch.c
M source/blender/gpu/gawain/batch.h
M source/blender/gpu/gawain/common.h
M source/blender/gpu/gawain/element.c
M source/blender/gpu/gawain/element.h
M source/blender/gpu/gawain/immediate.c
M source/blender/gpu/gawain/immediate.h
===================================================================
diff --git a/source/blender/gpu/gawain/batch.c b/source/blender/gpu/gawain/batch.c
index 0e817e1b..f1c07d4 100644
--- a/source/blender/gpu/gawain/batch.c
+++ b/source/blender/gpu/gawain/batch.c
@@ -16,11 +16,11 @@
extern void gpuBindMatrices(GLuint program);
extern bool gpuMatricesDirty(void); // how best to use this here?
-Batch* Batch_create(GLenum prim_type, VertexBuffer* verts, ElementList* elem)
+Batch* Batch_create(PrimitiveType prim_type, VertexBuffer* verts, ElementList* elem)
{
#if TRUST_NO_ONE
assert(verts != NULL);
- assert(prim_type == GL_POINTS || prim_type == GL_LINES || prim_type == GL_TRIANGLES);
+ assert(prim_type == PRIM_POINTS || prim_type == PRIM_LINES || prim_type == PRIM_TRIANGLES);
// we will allow other primitive types in a future update
#endif
diff --git a/source/blender/gpu/gawain/batch.h b/source/blender/gpu/gawain/batch.h
index 40d87dd..c276837 100644
--- a/source/blender/gpu/gawain/batch.h
+++ b/source/blender/gpu/gawain/batch.h
@@ -25,7 +25,7 @@ typedef struct {
// geometry
VertexBuffer* verts;
ElementList* elem; // NULL if element list not needed
- GLenum prim_type;
+ PrimitiveType prim_type;
// book-keeping
GLuint vao_id; // remembers all geometry state (vertex attrib bindings & element buffer)
@@ -37,7 +37,7 @@ typedef struct {
GLuint program;
} Batch;
-Batch* Batch_create(GLenum prim_type, VertexBuffer*, ElementList*);
+Batch* Batch_create(PrimitiveType, VertexBuffer*, ElementList*);
void Batch_discard(Batch*); // verts & elem are not discarded
void Batch_discard_all(Batch*); // including verts & elem
@@ -87,11 +87,11 @@ typedef struct {
VertexBuffer verts; // link batch.verts to this
} BatchWithOwnVertexBufferAndElementList;
-Batch* create_BatchWithOwnVertexBuffer(GLenum prim_type, VertexFormat*, unsigned v_ct, ElementList*);
-Batch* create_BatchWithOwnElementList(GLenum prim_type, VertexBuffer*, unsigned prim_ct);
-Batch* create_BatchWithOwnVertexBufferAndElementList(GLenum prim_type, VertexFormat*, unsigned v_ct, unsigned prim_ct);
+Batch* create_BatchWithOwnVertexBuffer(PrimitiveType, VertexFormat*, unsigned v_ct, ElementList*);
+Batch* create_BatchWithOwnElementList(PrimitiveType, VertexBuffer*, unsigned prim_ct);
+Batch* create_BatchWithOwnVertexBufferAndElementList(PrimitiveType, VertexFormat*, unsigned v_ct, unsigned prim_ct);
// verts: shared, own
// elem: none, shared, own
-Batch* create_BatchInGeneral(GLenum prim_type, VertexBufferStuff, ElementListStuff);
+Batch* create_BatchInGeneral(PrimitiveType, VertexBufferStuff, ElementListStuff);
#endif // future plans
diff --git a/source/blender/gpu/gawain/common.h b/source/blender/gpu/gawain/common.h
index ffd0f32..90340b9 100644
--- a/source/blender/gpu/gawain/common.h
+++ b/source/blender/gpu/gawain/common.h
@@ -40,4 +40,19 @@
#define glBindVertexArray glBindVertexArrayAPPLE
#endif
-#define PRIM_NONE 0xF
+typedef enum {
+ PRIM_POINTS = GL_POINTS,
+ PRIM_LINES = GL_LINES,
+ PRIM_TRIANGLES = GL_TRIANGLES,
+
+#ifdef WITH_GL_PROFILE_COMPAT
+ PRIM_QUADS = GL_QUADS, // legacy GL has this, modern GL & Vulkan do not
+#endif
+
+ PRIM_LINE_STRIP = GL_LINE_STRIP,
+ PRIM_LINE_LOOP = GL_LINE_LOOP, // GL has this, Vulkan does not
+ PRIM_TRIANGLE_STRIP = GL_TRIANGLE_STRIP,
+ PRIM_TRIANGLE_FAN = GL_TRIANGLE_FAN,
+
+ PRIM_NONE = 0xF
+} PrimitiveType;
diff --git a/source/blender/gpu/gawain/element.c b/source/blender/gpu/gawain/element.c
index 699b416..30d7548 100644
--- a/source/blender/gpu/gawain/element.c
+++ b/source/blender/gpu/gawain/element.c
@@ -19,9 +19,9 @@ unsigned ElementList_size(const ElementList* elem)
#if TRACK_INDEX_RANGE
switch (elem->index_type)
{
- case GL_UNSIGNED_BYTE: return elem->index_ct * sizeof(GLubyte);
- case GL_UNSIGNED_SHORT: return elem->index_ct * sizeof(GLushort);
- case GL_UNSIGNED_INT: return elem->index_ct * sizeof(GLuint);
+ case INDEX_U8: return elem->index_ct * sizeof(GLubyte);
+ case INDEX_U16: return elem->index_ct * sizeof(GLushort);
+ case INDEX_U32: return elem->index_ct * sizeof(GLuint);
default:
#if TRUST_NO_ONE
assert(false);
@@ -56,18 +56,18 @@ void ElementList_use(ElementList* elem)
ElementList_prime(elem);
}
-void ElementListBuilder_init(ElementListBuilder* builder, GLenum prim_type, unsigned prim_ct, unsigned vertex_ct)
+void ElementListBuilder_init(ElementListBuilder* builder, PrimitiveType prim_type, unsigned prim_ct, unsigned vertex_ct)
{
unsigned verts_per_prim = 0;
switch (prim_type)
{
- case GL_POINTS:
+ case PRIM_POINTS:
verts_per_prim = 1;
break;
- case GL_LINES:
+ case PRIM_LINES:
verts_per_prim = 2;
break;
- case GL_TRIANGLES:
+ case PRIM_TRIANGLES:
verts_per_prim = 3;
break;
default:
@@ -98,7 +98,7 @@ void add_generic_vertex(ElementListBuilder* builder, unsigned v)
void add_point_vertex(ElementListBuilder* builder, unsigned v)
{
#if TRUST_NO_ONE
- assert(builder->prim_type == GL_POINTS);
+ assert(builder->prim_type == PRIM_POINTS);
#endif
add_generic_vertex(builder, v);
@@ -107,7 +107,7 @@ void add_point_vertex(ElementListBuilder* builder, unsigned v)
void add_line_vertices(ElementListBuilder* builder, unsigned v1, unsigned v2)
{
#if TRUST_NO_ONE
- assert(builder->prim_type == GL_LINES);
+ assert(builder->prim_type == PRIM_LINES);
assert(v1 != v2);
#endif
@@ -118,7 +118,7 @@ void add_line_vertices(ElementListBuilder* builder, unsigned v1, unsigned v2)
void add_triangle_vertices(ElementListBuilder* builder, unsigned v1, unsigned v2, unsigned v3)
{
#if TRUST_NO_ONE
- assert(builder->prim_type == GL_TRIANGLES);
+ assert(builder->prim_type == PRIM_TRIANGLES);
assert(v1 != v2 && v2 != v3 && v3 != v1);
#endif
@@ -224,17 +224,17 @@ void ElementList_build_in_place(ElementListBuilder* builder, ElementList* elem)
if (range <= 0xFF)
{
- elem->index_type = GL_UNSIGNED_BYTE;
+ elem->index_type = INDEX_U8;
squeeze_indices_byte(builder->data, elem);
}
else if (range <= 0xFFFF)
{
- elem->index_type = GL_UNSIGNED_SHORT;
+ elem->index_type = INDEX_U16;
squeeze_indices_short(builder->data, elem);
}
else
{
- elem->index_type = GL_UNSIGNED_INT;
+ elem->index_type = INDEX_U32;
elem->base_index = 0;
if (builder->index_ct < builder->max_index_ct)
diff --git a/source/blender/gpu/gawain/element.h b/source/blender/gpu/gawain/element.h
index 6a07b70..6dcb367 100644
--- a/source/blender/gpu/gawain/element.h
+++ b/source/blender/gpu/gawain/element.h
@@ -15,10 +15,16 @@
#define TRACK_INDEX_RANGE 1
+typedef enum {
+ INDEX_U8 = GL_UNSIGNED_BYTE,
+ INDEX_U16 = GL_UNSIGNED_SHORT,
+ INDEX_U32 = GL_UNSIGNED_INT
+} IndexType;
+
typedef struct {
unsigned index_ct;
#if TRACK_INDEX_RANGE
- GLenum index_type;
+ IndexType index_type;
unsigned min_index;
unsigned max_index;
unsigned base_index;
@@ -34,17 +40,17 @@ typedef struct {
unsigned max_allowed_index;
unsigned max_index_ct;
unsigned index_ct;
- GLenum prim_type;
+ PrimitiveType prim_type;
unsigned* data;
} ElementListBuilder;
// supported primitives:
-// GL_POINTS
-// GL_LINES
-// GL_TRIANGLES
+// PRIM_POINTS
+// PRIM_LINES
+// PRIM_TRIANGLES
-void ElementListBuilder_init(ElementListBuilder*, GLenum prim_type, unsigned prim_ct, unsigned vertex_ct);
-//void ElementListBuilder_init_custom(ElementListBuilder*, GLenum prim_type, unsigned index_ct, unsigned vertex_ct);
+void ElementListBuilder_init(ElementListBuilder*, PrimitiveType, unsigned prim_ct, unsigned vertex_ct);
+//void ElementListBuilder_init_custom(ElementListBuilder*, PrimitiveType, unsigned index_ct, unsigned vertex_ct);
void add_generic_vertex(ElementListBuilder*, unsigned v);
diff --git a/source/blender/gpu/gawain/immediate.c b/source/blender/gpu/gawain/immediate.c
index 38da738..72b1014 100644
--- a/source/blender/gpu/gawain/immediate.c
+++ b/source/blender/gpu/gawain/immediate.c
@@ -30,7 +30,7 @@ typedef struct {
unsigned buffer_bytes_mapped;
unsigned vertex_ct;
bool strict_vertex_ct;
- GLenum primitive;
+ PrimitiveType prim_type;
VertexFormat vertex_format;
@@ -70,7 +70,7 @@ void immInit()
glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE);
#endif
- imm.primitive = PRIM_NONE;
+ imm.prim_type = PRIM_NONE;
imm.strict_vertex_ct = true;
glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -83,7 +83,7 @@ void immActivate()
{
#if TRUST_NO_ONE
assert(initialized);
- assert(imm.primitive == PRIM_NONE); // make sure we're not between a Begin/End pair
+ assert(imm.prim_type == PRIM_NONE); // make sure we're not between a Begin/End pair
assert(imm.vao_id == 0);
#endif
@@ -94,7 +94,7 @@ void immDeactivate()
{
#if TRUST_NO_ONE
assert(initialized);
- assert(imm.primitive == PRIM_NONE); // make sure we're not between a Begin/End pair
+ assert(imm.prim_type == PRIM_NONE); // make sure we're not between a Begin/End pair
assert(imm.vao_id != 0);
#endif
@@ -143,28 +143,28 @@ void immUnbindProgram()
imm.bound_program = 0;
}
-static bool vertex_count_makes_sense_for_primitive(unsigned vertex_ct, GLenum primitive)
+static bool vertex_count_makes_sense_for_primitive(unsigned vertex_ct, PrimitiveType prim_type)
{
// does vertex_ct make sense for this primitive type?
if (vertex_ct == 0)
return false;
- switch (primitive)
+ switch (prim_type)
{
- case GL_POINTS:
+ case PRIM_POINTS:
return true;
- case GL_LINES:
+ case PRIM_LINES:
return vertex_ct % 2 == 0;
- case GL_LINE_STRIP:
- case GL_LINE_LOOP:
+ case PRIM_LINE_STRIP:
+ case PRIM_LINE_LOOP:
return vertex_ct >= 2;
- case GL_TRIANGLES:
+ case PRIM_TRIANGLES:
return vertex_ct % 3 == 0;
- case GL_TRIANGLE_STRIP:
- case GL_TRIANGLE_FAN:
+ case PRIM_TRIANGLE_STRIP:
+ case PRIM_TRIANGLE_FAN:
return vertex_ct >= 3;
#ifdef WITH_GL_PROFILE_COMPAT
- case GL_QUADS:
+ case PRIM_QUADS:
return vertex_ct % 4 == 0;
#endif
default:
@@ -172,15 +172,15 @@ static bool vertex_count_makes_sense_for_primitive(unsigned vertex_ct, GLenum pr
}
}
-void immBegin(GLenum primitive, unsigned vertex_ct)
+void immBegin(PrimitiveType prim_type, unsigned vertex_ct)
{
#if TRUST_NO_ONE
assert(initialized);
- assert(imm.primitive == PRIM_NONE); // make sure we haven't already begu
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list