]> git.tdb.fi Git - libs/gl.git/commitdiff
Disconnect the PrimitiveType enum from OpenGL constants
authorMikko Rasa <tdb@tdb.fi>
Sat, 11 Sep 2021 10:54:43 +0000 (13:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 11 Sep 2021 13:54:04 +0000 (16:54 +0300)
source/core/batch.cpp
source/core/batch.h
source/core/commands.cpp
source/core/primitivetype.cpp
source/core/primitivetype.h

index d53156bd7a66c7bba1bc922e92aa07c4d190c30b..2be5cc3a69ffacd2472f2575da0b480db37b3989 100644 (file)
@@ -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),
index 3fedeaf83db8a80e642edf801789abdc55a55b48..c2107f823c2907a28cf36e79b2c6190cdc486a1b 100644 (file)
@@ -33,6 +33,7 @@ public:
 
 private:
        PrimitiveType prim_type;
+       GLenum gl_prim_type;
        DataType index_type;
        GLenum gl_index_type;
        std::vector<UInt8> 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; }
index 72b5a939f7194bb95280c9c4e3fbad9fd1b5caf8..563c4a83d549175a34d61f65339a19e98fa9816b 100644 (file)
@@ -32,7 +32,7 @@ void Commands::draw(const Batch &batch)
 {
        pipeline_state->apply();
        void *data_ptr = reinterpret_cast<void *>(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<void *>(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)
index 81375843c9f649609e4ef2c7e60873eca3534dfa..848da8000d786ee26d05d8007453e90437bdac7b 100644 (file)
@@ -1,9 +1,26 @@
 #include <msp/strings/format.h>
 #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")
index 8e33b1da141fc6cfabfc473329c9e73bb71f3607..b0854331423d2aa12748e57d603a0ac9061de6b8 100644 (file)
@@ -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