[Bf-blender-cvs] [d5883bb1ba6] blender2.8: Gawain: remove GL enum from primitive API
Mike Erwin
noreply at git.blender.org
Sat Apr 8 07:32:19 CEST 2017
Commit: d5883bb1ba6e4cfdd70bd3b8c0531a22c616b1be
Author: Mike Erwin
Date: Sat Apr 8 01:19:25 2017 -0400
Branches: blender2.8
https://developer.blender.org/rBd5883bb1ba6e4cfdd70bd3b8c0531a22c616b1be
Gawain: remove GL enum from primitive API
Callers now have to use Gawain's PRIM enum to specify geometric primitives.
This makes the API more bullet-proof (at least less vulnerable) since GLenum covers waaay more than GL_POINTS, GL_LINES, etc.
Also prepares us for Vulkan.
===================================================================
M intern/gawain/gawain/batch.h
M intern/gawain/gawain/primitive.h
M intern/gawain/src/batch.c
M intern/gawain/src/immediate.c
M intern/gawain/src/primitive.c
===================================================================
diff --git a/intern/gawain/gawain/batch.h b/intern/gawain/gawain/batch.h
index 189a586f964..532c45ae832 100644
--- a/intern/gawain/gawain/batch.h
+++ b/intern/gawain/gawain/batch.h
@@ -28,6 +28,7 @@ typedef struct Batch {
VertexBuffer* verts[BATCH_MAX_VBO_CT]; // verts[0] is required, others can be NULL
ElementList* elem; // NULL if element list not needed
PrimitiveType prim_type;
+ GLenum gl_prim_type;
// book-keeping
GLuint vao_id; // remembers all geometry state (vertex attrib bindings & element buffer)
diff --git a/intern/gawain/gawain/primitive.h b/intern/gawain/gawain/primitive.h
index 214902e9a2b..c9123ec79df 100644
--- a/intern/gawain/gawain/primitive.h
+++ b/intern/gawain/gawain/primitive.h
@@ -14,21 +14,21 @@
#include "common.h"
typedef enum {
- PRIM_POINTS = GL_POINTS,
- PRIM_LINES = GL_LINES,
- PRIM_TRIANGLES = GL_TRIANGLES,
+ PRIM_POINTS,
+ PRIM_LINES,
+ PRIM_TRIANGLES,
+ PRIM_LINE_STRIP,
+ PRIM_LINE_LOOP, // GL has this, Vulkan does not
+ PRIM_TRIANGLE_STRIP,
+ PRIM_TRIANGLE_FAN,
+
+ PRIM_LINE_STRIP_ADJACENCY,
#ifdef WITH_GL_PROFILE_COMPAT
- PRIM_QUADS_XXX = GL_QUADS, // legacy GL has this, modern GL & Vulkan do not
+ PRIM_QUADS_XXX, // legacy GL has this, modern GL & Vulkan do not
#endif
- PRIM_LINE_STRIP = GL_LINE_STRIP,
- PRIM_LINE_STRIP_ADJACENCY = GL_LINE_STRIP_ADJACENCY,
- 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
+ PRIM_NONE
} PrimitiveType;
// what types of primitives does each shader expect?
@@ -42,3 +42,5 @@ typedef enum {
PrimitiveClass prim_class_of_type(PrimitiveType);
bool prim_type_belongs_to_class(PrimitiveType, PrimitiveClass);
+
+GLenum convert_prim_type_to_gl(PrimitiveType);
diff --git a/intern/gawain/src/batch.c b/intern/gawain/src/batch.c
index 68771e59383..7e904cbd487 100644
--- a/intern/gawain/src/batch.c
+++ b/intern/gawain/src/batch.c
@@ -30,8 +30,6 @@ void Batch_init(Batch* batch, PrimitiveType prim_type, VertexBuffer* verts, Elem
{
#if TRUST_NO_ONE
assert(verts != NULL);
- // assert(prim_type == PRIM_POINTS || prim_type == PRIM_LINES || prim_type == PRIM_TRIANGLES);
- // we will allow other primitive types in a future update
#endif
batch->verts[0] = verts;
@@ -39,6 +37,7 @@ void Batch_init(Batch* batch, PrimitiveType prim_type, VertexBuffer* verts, Elem
batch->verts[v] = NULL;
batch->elem = elem;
batch->prim_type = prim_type;
+ batch->gl_prim_type = convert_prim_type_to_gl(prim_type);
batch->phase = READY_TO_DRAW;
}
@@ -304,15 +303,15 @@ void Batch_draw(Batch* batch)
#if TRACK_INDEX_RANGE
if (el->base_index)
- glDrawRangeElementsBaseVertex(batch->prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0, el->base_index);
+ glDrawRangeElementsBaseVertex(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0, el->base_index);
else
- glDrawRangeElements(batch->prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0);
+ glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0);
#else
- glDrawElements(batch->prim_type, el->index_ct, GL_UNSIGNED_INT, 0);
+ glDrawElements(batch->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0);
#endif
}
else
- glDrawArrays(batch->prim_type, 0, batch->verts[0]->vertex_ct);
+ glDrawArrays(batch->gl_prim_type, 0, batch->verts[0]->vertex_ct);
Batch_done_using_program(batch);
glBindVertexArray(0);
@@ -341,15 +340,15 @@ void Batch_draw_stupid(Batch* batch)
#if TRACK_INDEX_RANGE
if (el->base_index)
- glDrawRangeElementsBaseVertex(batch->prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0, el->base_index);
+ glDrawRangeElementsBaseVertex(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0, el->base_index);
else
- glDrawRangeElements(batch->prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0);
+ glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0);
#else
- glDrawElements(batch->prim_type, el->index_ct, GL_UNSIGNED_INT, 0);
+ glDrawElements(batch->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0);
#endif
}
else
- glDrawArrays(batch->prim_type, 0, batch->verts[0]->vertex_ct);
+ glDrawArrays(batch->gl_prim_type, 0, batch->verts[0]->vertex_ct);
// Batch_done_using_program(batch);
glBindVertexArray(0);
@@ -394,10 +393,10 @@ void Batch_draw_stupid_instanced(Batch* batch, unsigned int instance_vbo, int in
{
const ElementList* el = batch->elem;
- glDrawElementsInstanced(batch->prim_type, el->index_ct, GL_UNSIGNED_INT, 0, instance_count);
+ glDrawElementsInstanced(batch->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0, instance_count);
}
else
- glDrawArraysInstanced(batch->prim_type, 0, batch->verts[0]->vertex_ct, instance_count);
+ glDrawArraysInstanced(batch->gl_prim_type, 0, batch->verts[0]->vertex_ct, instance_count);
// Batch_done_using_program(batch);
glBindVertexArray(0);
diff --git a/intern/gawain/src/immediate.c b/intern/gawain/src/immediate.c
index 8867c541edc..15cd1cc801f 100644
--- a/intern/gawain/src/immediate.c
+++ b/intern/gawain/src/immediate.c
@@ -409,7 +409,7 @@ void immEnd(void)
if (imm.vertex_ct > 0)
{
immDrawSetup();
- glDrawArrays(imm.prim_type, 0, imm.vertex_ct);
+ glDrawArrays(convert_prim_type_to_gl(imm.prim_type), 0, imm.vertex_ct);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
diff --git a/intern/gawain/src/primitive.c b/intern/gawain/src/primitive.c
index 7fee06021b8..21cee01d4db 100644
--- a/intern/gawain/src/primitive.c
+++ b/intern/gawain/src/primitive.c
@@ -15,7 +15,6 @@ PrimitiveClass prim_class_of_type(PrimitiveType prim_type)
{
static const PrimitiveClass classes[] =
{
- [PRIM_NONE] = PRIM_CLASS_NONE,
[PRIM_POINTS] = PRIM_CLASS_POINT,
[PRIM_LINES] = PRIM_CLASS_LINE,
[PRIM_LINE_STRIP] = PRIM_CLASS_LINE,
@@ -24,9 +23,13 @@ PrimitiveClass prim_class_of_type(PrimitiveType prim_type)
[PRIM_TRIANGLE_STRIP] = PRIM_CLASS_SURFACE,
[PRIM_TRIANGLE_FAN] = PRIM_CLASS_SURFACE,
+ [PRIM_LINE_STRIP_ADJACENCY] = PRIM_CLASS_LINE,
+
#ifdef WITH_GL_PROFILE_COMPAT
[PRIM_QUADS_XXX] = PRIM_CLASS_SURFACE,
#endif
+
+ [PRIM_NONE] = PRIM_CLASS_NONE
};
return classes[prim_type];
@@ -39,3 +42,29 @@ bool prim_type_belongs_to_class(PrimitiveType prim_type, PrimitiveClass prim_cla
return prim_class & prim_class_of_type(prim_type);
}
+
+GLenum convert_prim_type_to_gl(PrimitiveType prim_type)
+ {
+#if TRUST_NO_ONE
+ assert(prim_type != PRIM_NONE);
+#endif
+
+ static const GLenum table[] =
+ {
+ [PRIM_POINTS] = GL_POINTS,
+ [PRIM_LINES] = GL_LINES,
+ [PRIM_LINE_STRIP] = GL_LINE_STRIP,
+ [PRIM_LINE_LOOP] = GL_LINE_LOOP,
+ [PRIM_TRIANGLES] = PRIM_CLASS_SURFACE,
+ [PRIM_TRIANGLE_STRIP] = GL_TRIANGLE_STRIP,
+ [PRIM_TRIANGLE_FAN] = GL_TRIANGLE_FAN,
+
+ [PRIM_LINE_STRIP_ADJACENCY] = GL_LINE_STRIP_ADJACENCY,
+
+#ifdef WITH_GL_PROFILE_COMPAT
+ [PRIM_QUADS_XXX] = GL_QUADS,
+#endif
+ };
+
+ return table[prim_type];
+ }
More information about the Bf-blender-cvs
mailing list