From d971f8d4848c0b3b453c626a2dafe19445e3e5a8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 5 Feb 2020 23:35:42 +0200 Subject: [PATCH] Add support for non-square matrix uniforms --- source/program.cpp | 20 ++++++++++ source/program.h | 1 + source/programdata.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++ source/programdata.h | 18 +++++++++ 4 files changed, 129 insertions(+) diff --git a/source/program.cpp b/source/program.cpp index e65a703f..37d72e94 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -143,6 +143,26 @@ void Program::link() query_uniforms(); query_attributes(); + + for(UniformMap::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i) + require_type(i->second.type); + for(AttributeMap::const_iterator i=attributes.begin(); i!=attributes.end(); ++i) + 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() diff --git a/source/program.h b/source/program.h index 734d665b..8c1356c2 100644 --- a/source/program.h +++ b/source/program.h @@ -111,6 +111,7 @@ public: void link(); private: + static void require_type(GLenum); void query_uniforms(); void query_uniform_blocks(const std::vector &); void query_attributes(); diff --git a/source/programdata.cpp b/source/programdata.cpp index 1e4f5c1d..dba6b06f 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -210,6 +210,36 @@ void ProgramData::uniform_matrix2(const string &name, const float *v) uniform(name, new UniformMatrix2x2f(v)); } +void ProgramData::uniform(const string &name, const LinAl::Matrix &m) +{ + uniform_matrix3x2(name, &m(0, 0)); +} + +void ProgramData::uniform_matrix3x2(const string &name, const float *v) +{ + uniform(name, new UniformMatrix3x2f(v)); +} + +void ProgramData::uniform(const string &name, const LinAl::Matrix &m) +{ + uniform_matrix4x2(name, &m(0, 0)); +} + +void ProgramData::uniform_matrix4x2(const string &name, const float *v) +{ + uniform(name, new UniformMatrix4x2f(v)); +} + +void ProgramData::uniform(const string &name, const LinAl::Matrix &m) +{ + uniform_matrix2x3(name, &m(0, 0)); +} + +void ProgramData::uniform_matrix2x3(const string &name, const float *v) +{ + uniform(name, new UniformMatrix2x3f(v)); +} + void ProgramData::uniform(const string &name, const LinAl::Matrix &m) { uniform_matrix3(name, &m(0, 0)); @@ -220,6 +250,36 @@ void ProgramData::uniform_matrix3(const string &name, const float *v) uniform(name, new UniformMatrix3x3f(v)); } +void ProgramData::uniform(const string &name, const LinAl::Matrix &m) +{ + uniform_matrix4x3(name, &m(0, 0)); +} + +void ProgramData::uniform_matrix4x3(const string &name, const float *v) +{ + uniform(name, new UniformMatrix4x3f(v)); +} + +void ProgramData::uniform(const string &name, const LinAl::Matrix &m) +{ + uniform_matrix2x4(name, &m(0, 0)); +} + +void ProgramData::uniform_matrix2x4(const string &name, const float *v) +{ + uniform(name, new UniformMatrix2x4f(v)); +} + +void ProgramData::uniform(const string &name, const LinAl::Matrix &m) +{ + uniform_matrix3x4(name, &m(0, 0)); +} + +void ProgramData::uniform_matrix3x4(const string &name, const float *v) +{ + uniform(name, new UniformMatrix3x4f(v)); +} + void ProgramData::uniform(const string &name, const Matrix &m) { uniform_matrix4(name, m.data()); @@ -275,11 +335,41 @@ void ProgramData::uniform_matrix2_array(const string &name, unsigned n, const fl uniform(name, new UniformArray(n, v)); } +void ProgramData::uniform_matrix3x2_array(const string &name, unsigned n, const float *v) +{ + uniform(name, new UniformArray(n, v)); +} + +void ProgramData::uniform_matrix4x2_array(const string &name, unsigned n, const float *v) +{ + uniform(name, new UniformArray(n, v)); +} + +void ProgramData::uniform_matrix2x3_array(const string &name, unsigned n, const float *v) +{ + uniform(name, new UniformArray(n, v)); +} + void ProgramData::uniform_matrix3_array(const string &name, unsigned n, const float *v) { uniform(name, new UniformArray(n, v)); } +void ProgramData::uniform_matrix4x3_array(const string &name, unsigned n, const float *v) +{ + uniform(name, new UniformArray(n, v)); +} + +void ProgramData::uniform_matrix2x4_array(const string &name, unsigned n, const float *v) +{ + uniform(name, new UniformArray(n, v)); +} + +void ProgramData::uniform_matrix3x4_array(const string &name, unsigned n, const float *v) +{ + uniform(name, new UniformArray(n, v)); +} + void ProgramData::uniform_matrix4_array(const string &name, unsigned n, const float *v) { uniform(name, new UniformArray(n, v)); diff --git a/source/programdata.h b/source/programdata.h index 08b117b4..605b41b1 100644 --- a/source/programdata.h +++ b/source/programdata.h @@ -181,8 +181,20 @@ public: void uniform4(const std::string &, const float *); void uniform(const std::string &, const LinAl::Matrix &); void uniform_matrix2(const std::string &, const float *); + void uniform(const std::string &, const LinAl::Matrix &); + void uniform_matrix3x2(const std::string &, const float *); + void uniform(const std::string &, const LinAl::Matrix &); + void uniform_matrix4x2(const std::string &, const float *); + void uniform(const std::string &, const LinAl::Matrix &); + void uniform_matrix2x3(const std::string &, const float *); void uniform(const std::string &, const LinAl::Matrix &); void uniform_matrix3(const std::string &, const float *); + void uniform(const std::string &, const LinAl::Matrix &); + void uniform_matrix4x3(const std::string &, const float *); + void uniform(const std::string &, const LinAl::Matrix &); + void uniform_matrix2x4(const std::string &, const float *); + void uniform(const std::string &, const LinAl::Matrix &); + void uniform_matrix3x4(const std::string &, const float *); void uniform(const std::string &, const Matrix &); void uniform_matrix4(const std::string &, const float *); void uniform1_array(const std::string &, unsigned, const int *); @@ -194,7 +206,13 @@ public: void uniform4_array(const std::string &, unsigned, const int *); void uniform4_array(const std::string &, unsigned, const float *); void uniform_matrix2_array(const std::string &, unsigned, const float *); + void uniform_matrix3x2_array(const std::string &, unsigned, const float *); + void uniform_matrix4x2_array(const std::string &, unsigned, const float *); + void uniform_matrix2x3_array(const std::string &, unsigned, const float *); void uniform_matrix3_array(const std::string &, unsigned, const float *); + void uniform_matrix4x3_array(const std::string &, unsigned, const float *); + void uniform_matrix2x4_array(const std::string &, unsigned, const float *); + void uniform_matrix3x4_array(const std::string &, unsigned, const float *); void uniform_matrix4_array(const std::string &, unsigned, const float *); void remove_uniform(const std::string &); -- 2.45.2