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:
authorMike Erwin <significant.bit@gmail.com>2016-11-17 00:03:15 +0300
committerMike Erwin <significant.bit@gmail.com>2016-11-17 00:03:15 +0300
commitb1f700dad36c943c2c2a6f5477a4400cba5803f0 (patch)
tree780749d42f2455cd3f87af27eed4d6e785f0cf64 /source/blender/gpu
parent36ac979ee01f1a266e944a71272655f94ddcff52 (diff)
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
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/gawain/batch.c4
-rw-r--r--source/blender/gpu/gawain/batch.h12
-rw-r--r--source/blender/gpu/gawain/common.h17
-rw-r--r--source/blender/gpu/gawain/element.c26
-rw-r--r--source/blender/gpu/gawain/element.h20
-rw-r--r--source/blender/gpu/gawain/immediate.c76
-rw-r--r--source/blender/gpu/gawain/immediate.h8
7 files changed, 92 insertions, 71 deletions
diff --git a/source/blender/gpu/gawain/batch.c b/source/blender/gpu/gawain/batch.c
index 0e817e1baaa..f1c07d4ff67 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 40d87dd3d14..c2768377a96 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 ffd0f3293ac..90340b94e4d 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 699b416e9d8..30d75480dde 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 6a07b70228c..6dcb3676a6f 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 38da738dc16..72b1014061d 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 begun
- assert(vertex_count_makes_sense_for_primitive(vertex_ct, primitive));
+ assert(imm.prim_type == PRIM_NONE); // make sure we haven't already begun
+ assert(vertex_count_makes_sense_for_primitive(vertex_ct, prim_type));
#endif
- imm.primitive = primitive;
+ imm.prim_type = prim_type;
imm.vertex_ct = vertex_ct;
imm.vertex_idx = 0;
imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
@@ -232,27 +232,27 @@ void immBegin(GLenum primitive, unsigned vertex_ct)
imm.vertex_data = imm.buffer_data;
}
-void immBeginAtMost(GLenum primitive, unsigned vertex_ct)
+void immBeginAtMost(PrimitiveType prim_type, unsigned vertex_ct)
{
#if TRUST_NO_ONE
assert(vertex_ct > 0);
#endif
imm.strict_vertex_ct = false;
- immBegin(primitive, vertex_ct);
+ immBegin(prim_type, vertex_ct);
}
#if IMM_BATCH_COMBO
-Batch* immBeginBatch(GLenum prim_type, unsigned vertex_ct)
+Batch* immBeginBatch(PrimitiveType prim_type, unsigned vertex_ct)
{
#if TRUST_NO_ONE
assert(initialized);
- assert(imm.primitive == PRIM_NONE); // make sure we haven't already begun
+ assert(imm.prim_type == PRIM_NONE); // make sure we haven't already begun
assert(vertex_count_makes_sense_for_primitive(vertex_ct, prim_type));
#endif
- imm.primitive = prim_type;
+ imm.prim_type = prim_type;
imm.vertex_ct = vertex_ct;
imm.vertex_idx = 0;
imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
@@ -271,7 +271,7 @@ Batch* immBeginBatch(GLenum prim_type, unsigned vertex_ct)
return imm.batch;
}
-Batch* immBeginBatchAtMost(GLenum prim_type, unsigned vertex_ct)
+Batch* immBeginBatchAtMost(PrimitiveType prim_type, unsigned vertex_ct)
{
imm.strict_vertex_ct = false;
return immBeginBatch(prim_type, vertex_ct);
@@ -341,7 +341,7 @@ static void immDrawSetup(void)
void immEnd()
{
#if TRUST_NO_ONE
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
unsigned buffer_bytes_used;
@@ -365,7 +365,7 @@ void immEnd()
else
{
#if TRUST_NO_ONE
- assert(imm.vertex_idx == 0 || vertex_count_makes_sense_for_primitive(imm.vertex_idx, imm.primitive));
+ assert(imm.vertex_idx == 0 || vertex_count_makes_sense_for_primitive(imm.vertex_idx, imm.prim_type));
#endif
imm.vertex_ct = imm.vertex_idx;
buffer_bytes_used = vertex_buffer_size(&imm.vertex_format, imm.vertex_ct);
@@ -404,7 +404,7 @@ void immEnd()
if (imm.vertex_ct > 0)
{
immDrawSetup();
- glDrawArrays(imm.primitive, 0, imm.vertex_ct);
+ glDrawArrays(imm.prim_type, 0, imm.vertex_ct);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -415,7 +415,7 @@ void immEnd()
}
// prep for next immBegin
- imm.primitive = PRIM_NONE;
+ imm.prim_type = PRIM_NONE;
imm.strict_vertex_ct = true;
}
@@ -442,7 +442,7 @@ void immAttrib1f(unsigned attrib_id, float x)
assert(attrib->comp_type == COMP_F32);
assert(attrib->comp_ct == 1);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -462,7 +462,7 @@ void immAttrib2f(unsigned attrib_id, float x, float y)
assert(attrib->comp_type == COMP_F32);
assert(attrib->comp_ct == 2);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -483,7 +483,7 @@ void immAttrib3f(unsigned attrib_id, float x, float y, float z)
assert(attrib->comp_type == COMP_F32);
assert(attrib->comp_ct == 3);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -505,7 +505,7 @@ void immAttrib4f(unsigned attrib_id, float x, float y, float z, float w)
assert(attrib->comp_type == COMP_F32);
assert(attrib->comp_ct == 4);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -528,7 +528,7 @@ void immAttrib2i(unsigned attrib_id, int x, int y)
assert(attrib->comp_type == COMP_I32);
assert(attrib->comp_ct == 2);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -548,7 +548,7 @@ void immAttrib2s(unsigned attrib_id, short x, short y)
assert(attrib->comp_type == COMP_I16);
assert(attrib->comp_ct == 2);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -578,7 +578,7 @@ void immAttrib3ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned
assert(attrib->comp_type == COMP_U8);
assert(attrib->comp_ct == 3);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -600,7 +600,7 @@ void immAttrib4ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned
assert(attrib->comp_type == COMP_U8);
assert(attrib->comp_ct == 4);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -629,7 +629,7 @@ void immSkipAttrib(unsigned attrib_id)
#if TRUST_NO_ONE
assert(attrib_id < imm.vertex_format.attrib_ct);
assert(imm.vertex_idx < imm.vertex_ct);
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
#endif
setAttribValueBit(attrib_id);
@@ -638,7 +638,7 @@ void immSkipAttrib(unsigned attrib_id)
static void immEndVertex(void) // and move on to the next vertex
{
#if TRUST_NO_ONE
- assert(imm.primitive != PRIM_NONE); // make sure we're between a Begin/End pair
+ assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair
assert(imm.vertex_idx < imm.vertex_ct);
#endif
diff --git a/source/blender/gpu/gawain/immediate.h b/source/blender/gpu/gawain/immediate.h
index 678f2ecacdc..50965d3d36c 100644
--- a/source/blender/gpu/gawain/immediate.h
+++ b/source/blender/gpu/gawain/immediate.h
@@ -21,8 +21,8 @@ VertexFormat* immVertexFormat(void); // returns a cleared vertex format, ready f
void immBindProgram(GLuint program); // every immBegin must have a program bound first
void immUnbindProgram(void); // call after your last immEnd, or before binding another program
-void immBegin(GLenum primitive, unsigned vertex_ct); // must supply exactly vertex_ct vertices
-void immBeginAtMost(GLenum primitive, unsigned max_vertex_ct); // can supply fewer vertices
+void immBegin(PrimitiveType, unsigned vertex_ct); // must supply exactly vertex_ct vertices
+void immBeginAtMost(PrimitiveType, unsigned max_vertex_ct); // can supply fewer vertices
void immEnd(void); // finishes and draws
#if IMM_BATCH_COMBO
@@ -30,8 +30,8 @@ void immEnd(void); // finishes and draws
// immBegin a batch, then use standard immFunctions as usual.
// immEnd will finalize the batch instead of drawing.
// Then you can draw it as many times as you like! Partially replaces the need for display lists.
-Batch* immBeginBatch(GLenum prim_type, unsigned vertex_ct);
-Batch* immBeginBatchAtMost(GLenum prim_type, unsigned vertex_ct);
+Batch* immBeginBatch(PrimitiveType, unsigned vertex_ct);
+Batch* immBeginBatchAtMost(PrimitiveType, unsigned vertex_ct);
#endif