]> git.tdb.fi Git - libs/gl.git/commitdiff
Use DataType instead of GLenum for Program variable types
authorMikko Rasa <tdb@tdb.fi>
Tue, 30 Mar 2021 14:51:39 +0000 (17:51 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 30 Mar 2021 14:56:02 +0000 (17:56 +0300)
source/core/datatype.cpp
source/core/datatype.h
source/core/program.cpp
source/core/program.h

index c43b8f44315432847e8d93ba55776ebb434d770f..af7446eb1f86916e23af1c2c84cd4e57c7fcf3ca 100644 (file)
@@ -94,5 +94,23 @@ GLenum get_gl_type(DataType type)
        return ptr->gl_type;
 }
 
+DataType from_gl_type(GLenum gl_type)
+{
+       for(unsigned i=0; i<type_map_size; ++i)
+               if(type_map[i].gl_type==gl_type)
+                       return type_map[i].type;
+       throw invalid_argument("from_gl_type");
+}
+
+void require_type(DataType type)
+{
+       unsigned rows = ((type>>12)&3)+1;
+       unsigned cols = ((type>>14)&4)+1;
+       if(rows>1 && cols>1 && rows!=cols)
+               static Require _req(NV_non_square_matrices);
+       if((type&0x200) && get_type_size(type)/(rows*cols)==8)
+               static Require _req(ARB_gpu_shader_fp64);
+}
+
 } // namespace GL
 } // namespace Msp
index 92529a18fc256535eb92e85bd0ae93252c1c11a9..6bc085276c05f3b05c83708df45a4be74b01ffa0 100644 (file)
@@ -90,10 +90,14 @@ enum DataType
        SAMPLER_CUBE_ARRAY_SHADOW = 0x3C0304
 };
 
-inline unsigned get_type_size(DataType t)
-{ return t&0xFF; }
+inline unsigned get_type_size(DataType t) { return t&0xFF; }
+inline bool is_matrix(DataType t) { return (t>>14)&3; }
+inline bool is_vector(DataType t) { return !is_matrix(t) && ((t>>12)&3); }
 
 GLenum get_gl_type(DataType);
+DataType from_gl_type(GLenum);
+
+void require_type(DataType);
 
 } // namespace GL
 } // namespace Msp
index c41976ed8eef270a238de46b837e529ad4904dd9..dd155d5c5c9ed4c3296591bd1ea645b7018e46b8 100644 (file)
@@ -254,21 +254,6 @@ void Program::link()
                require_type(i->second.type);
 }
 
-void Program::require_type(GLenum t)
-{
-       switch(t)
-       {
-       case GL_FLOAT_MAT2x3:
-       case GL_FLOAT_MAT2x4:
-       case GL_FLOAT_MAT3x2:
-       case GL_FLOAT_MAT3x4:
-       case GL_FLOAT_MAT4x2:
-       case GL_FLOAT_MAT4x3:
-               { static Require _req(NV_non_square_matrices); }
-               break;
-       }
-}
-
 void Program::query_uniforms()
 {
        unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS);
@@ -293,7 +278,7 @@ void Program::query_uniforms()
                        info.size = size;
                        info.array_stride = 0;
                        info.matrix_stride = 0;
-                       info.type = type;
+                       info.type = from_gl_type(type);
                        uniforms_by_index[i] = &info;
                }
        }
@@ -370,10 +355,8 @@ void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_inde
                indices2.clear();
                for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
                {
-                       GLenum t = uniforms_by_index[*j]->type;
-                       if(t==GL_FLOAT_MAT4 || t==GL_FLOAT_MAT3 || t==GL_FLOAT_MAT2 ||
-                               t==GL_FLOAT_MAT2x3 || t==GL_FLOAT_MAT2x4 || t==GL_FLOAT_MAT3x2 ||
-                               t==GL_FLOAT_MAT3x4 || t==GL_FLOAT_MAT4x2 || t==GL_FLOAT_MAT4x3)
+                       DataType t = uniforms_by_index[*j]->type;
+                       if(is_matrix(t))
                                indices2.push_back(*j);
                }
                if(!indices2.empty())
@@ -413,7 +396,7 @@ void Program::query_attributes()
                        info.name = name;
                        info.location = glGetAttribLocation(id, name);
                        info.size = size;
-                       info.type = type;
+                       info.type = from_gl_type(type);
                }
        }
 }
index 9fa757479eacf11d09ca7880bbab83daeb74c6db..40c1d320f861e81d662ec2aa8e118e3191a5c602 100644 (file)
@@ -5,6 +5,7 @@
 #include <vector>
 #include <msp/datafile/objectloader.h>
 #include "bindable.h"
+#include "datatype.h"
 #include "gl.h"
 #include "vertexformat.h"
 
@@ -67,7 +68,7 @@ public:
                unsigned size;
                unsigned array_stride;
                unsigned matrix_stride;
-               GLenum type;
+               DataType type;
        };
 
        struct UniformBlockInfo
@@ -84,7 +85,7 @@ public:
                std::string name;
                unsigned location;
                unsigned size;
-               GLenum type;
+               DataType type;
        };
 
        typedef std::map<std::string, UniformInfo> UniformMap;
@@ -137,7 +138,6 @@ public:
 
        void link();
 private:
-       static void require_type(GLenum);
        void query_uniforms();
        void query_uniform_blocks(const std::vector<UniformInfo *> &);
        void query_attributes();