From 096481bcb88844ec28fd33147ed5010bfe2e15d9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 30 Mar 2021 17:51:39 +0300 Subject: [PATCH] Use DataType instead of GLenum for Program variable types --- source/core/datatype.cpp | 18 ++++++++++++++++++ source/core/datatype.h | 8 ++++++-- source/core/program.cpp | 25 ++++--------------------- source/core/program.h | 6 +++--- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/source/core/datatype.cpp b/source/core/datatype.cpp index c43b8f44..af7446eb 100644 --- a/source/core/datatype.cpp +++ b/source/core/datatype.cpp @@ -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>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 diff --git a/source/core/datatype.h b/source/core/datatype.h index 92529a18..6bc08527 100644 --- a/source/core/datatype.h +++ b/source/core/datatype.h @@ -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 diff --git a/source/core/program.cpp b/source/core/program.cpp index c41976ed..dd155d5c 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -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 &uniforms_by_inde indices2.clear(); for(vector::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); } } } diff --git a/source/core/program.h b/source/core/program.h index 9fa75747..40c1d320 100644 --- a/source/core/program.h +++ b/source/core/program.h @@ -5,6 +5,7 @@ #include #include #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 UniformMap; @@ -137,7 +138,6 @@ public: void link(); private: - static void require_type(GLenum); void query_uniforms(); void query_uniform_blocks(const std::vector &); void query_attributes(); -- 2.45.2