From: Mikko Rasa Date: Sat, 11 Sep 2021 10:54:43 +0000 (+0300) Subject: Disconnect the PrimitiveType enum from OpenGL constants X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a60b558e1c327fd2e2600ad2551dc0ac648761f2;p=libs%2Fgl.git Disconnect the PrimitiveType enum from OpenGL constants --- diff --git a/source/core/batch.cpp b/source/core/batch.cpp index d53156bd..2be5cc3a 100644 --- a/source/core/batch.cpp +++ b/source/core/batch.cpp @@ -52,6 +52,7 @@ unsigned Batch::restart_index = 0; Batch::Batch(PrimitiveType t): prim_type(t), + gl_prim_type(GL::get_gl_primitive_type(prim_type)), index_type(UNSIGNED_SHORT), gl_index_type(get_gl_type(index_type)), max_index(0), diff --git a/source/core/batch.h b/source/core/batch.h index 3fedeaf8..c2107f82 100644 --- a/source/core/batch.h +++ b/source/core/batch.h @@ -33,6 +33,7 @@ public: private: PrimitiveType prim_type; + GLenum gl_prim_type; DataType index_type; GLenum gl_index_type; std::vector data; @@ -46,6 +47,7 @@ public: ~Batch(); PrimitiveType get_type() const { return prim_type; } + GLenum get_gl_primitive_type() const { return gl_prim_type; } void set_index_type(DataType); DataType get_index_type() const { return index_type; } GLenum get_gl_index_type() const { return gl_index_type; } diff --git a/source/core/commands.cpp b/source/core/commands.cpp index 72b5a939..563c4a83 100644 --- a/source/core/commands.cpp +++ b/source/core/commands.cpp @@ -32,7 +32,7 @@ void Commands::draw(const Batch &batch) { pipeline_state->apply(); void *data_ptr = reinterpret_cast(batch.get_offset()); - glDrawElements(batch.get_type(), batch.size(), batch.get_gl_index_type(), data_ptr); + glDrawElements(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr); } void Commands::draw_instanced(const Batch &batch, unsigned count) @@ -41,7 +41,7 @@ void Commands::draw_instanced(const Batch &batch, unsigned count) pipeline_state->apply(); void *data_ptr = reinterpret_cast(batch.get_offset()); - glDrawElementsInstanced(batch.get_type(), batch.size(), batch.get_gl_index_type(), data_ptr, count); + glDrawElementsInstanced(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr, count); } void Commands::resolve_multisample(Framebuffer &target, BufferBits buffers) diff --git a/source/core/primitivetype.cpp b/source/core/primitivetype.cpp index 81375843..848da800 100644 --- a/source/core/primitivetype.cpp +++ b/source/core/primitivetype.cpp @@ -1,9 +1,26 @@ #include #include "primitivetype.h" +using namespace std; + namespace Msp { namespace GL { +GLenum get_gl_primitive_type(PrimitiveType pt) +{ + switch(pt) + { + case POINTS: return GL_POINTS; + case LINES: return GL_LINES; + case LINE_STRIP: return GL_LINE_STRIP; + case LINE_LOOP: return GL_LINE_LOOP; + case TRIANGLES: return GL_TRIANGLES; + case TRIANGLE_STRIP: return GL_TRIANGLE_STRIP; + case TRIANGLE_FAN: return GL_TRIANGLE_FAN; + default: throw invalid_argument("get_gl_primitive_type"); + } +} + void operator>>(const LexicalConverter &conv, PrimitiveType &pt) { if(conv.get()=="POINTS") diff --git a/source/core/primitivetype.h b/source/core/primitivetype.h index 8e33b1da..b0854331 100644 --- a/source/core/primitivetype.h +++ b/source/core/primitivetype.h @@ -9,15 +9,17 @@ namespace GL { enum PrimitiveType { - POINTS = GL_POINTS, - LINES = GL_LINES, - LINE_STRIP = GL_LINE_STRIP, - LINE_LOOP = GL_LINE_LOOP, - TRIANGLES = GL_TRIANGLES, - TRIANGLE_STRIP = GL_TRIANGLE_STRIP, - TRIANGLE_FAN = GL_TRIANGLE_FAN + POINTS, + LINES, + LINE_STRIP, + LINE_LOOP, + TRIANGLES, + TRIANGLE_STRIP, + TRIANGLE_FAN }; +GLenum get_gl_primitive_type(PrimitiveType); + void operator>>(const LexicalConverter &, PrimitiveType &); } // namespace GL