From 9885c5465db78b6a1d9cc8bf7ffa7a79fb116afc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 26 Oct 2016 18:11:06 +0300 Subject: [PATCH] Add uniform integer vectors of 2, 3 and 4 elements --- source/ambientocclusion.cpp | 4 +- source/programdata.cpp | 108 ++++++++++++++++++++++++++++++++++++ source/programdata.h | 18 ++++++ source/uniform.cpp | 18 ++++++ source/uniform.h | 3 + 5 files changed, 149 insertions(+), 2 deletions(-) diff --git a/source/ambientocclusion.cpp b/source/ambientocclusion.cpp index f1e722af..444b18b8 100644 --- a/source/ambientocclusion.cpp +++ b/source/ambientocclusion.cpp @@ -108,12 +108,12 @@ AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float depth_ratio): occlude_shdata.uniform("depth", 0); occlude_shdata.uniform("rotate", 1); - occlude_shdata.uniform("screen_size", w, h); + occlude_shdata.uniform("screen_size", static_cast(w), static_cast(h)); combine_shdata.uniform("color", 1); combine_shdata.uniform("depth", 0); combine_shdata.uniform("occlusion", 2); - combine_shdata.uniform("screen_size", w, h); + combine_shdata.uniform("screen_size", static_cast(w), static_cast(h)); set_depth_ratio(depth_ratio); set_darkness(1.5); diff --git a/source/programdata.cpp b/source/programdata.cpp index d0de3c05..615da767 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -99,17 +99,34 @@ void ProgramData::uniform(const string &name, float v) uniform(name, new Uniform1f(v)); } +void ProgramData::uniform(const string &name, int v0, int v1) +{ + int va[2] = { v0, v1 }; + uniform2(name, va); +} + void ProgramData::uniform(const string &name, float v0, float v1) { float va[2] = { v0, v1 }; uniform2(name, va); } +void ProgramData::uniform2(const string &name, const int *v) +{ + uniform(name, new Uniform2i(v)); +} + void ProgramData::uniform2(const string &name, const float *v) { uniform(name, new Uniform2f(v)); } +void ProgramData::uniform(const string &name, int v0, int v1, int v2) +{ + int va[3] = { v0, v1, v2 }; + uniform3(name, va); +} + void ProgramData::uniform(const string &name, float v0, float v1, float v2) { float va[3] = { v0, v1, v2 }; @@ -121,11 +138,22 @@ void ProgramData::uniform(const string &name, const Vector3 &v) uniform(name, v.x, v.y, v.z); } +void ProgramData::uniform3(const string &name, const int *v) +{ + uniform(name, new Uniform3i(v)); +} + void ProgramData::uniform3(const string &name, const float *v) { uniform(name, new Uniform3f(v)); } +void ProgramData::uniform(const string &name, int v0, int v1, int v2, int v3) +{ + int va[4] = { v0, v1, v2, v3 }; + uniform4(name, va); +} + void ProgramData::uniform(const string &name, float v0, float v1, float v2, float v3) { float va[4] = { v0, v1, v2, v3 }; @@ -142,6 +170,11 @@ void ProgramData::uniform(const string &name, const Color &c) uniform(name, c.r, c.g, c.b, c.a); } +void ProgramData::uniform4(const string &name, const int *v) +{ + uniform(name, new Uniform4i(v)); +} + void ProgramData::uniform4(const string &name, const float *v) { uniform(name, new Uniform4f(v)); @@ -187,16 +220,31 @@ void ProgramData::uniform1_array(const string &name, unsigned n, const float *v) uniform(name, new UniformArray(n, v)); } +void ProgramData::uniform2_array(const string &name, unsigned n, const int *v) +{ + uniform(name, new UniformArray(n, v)); +} + void ProgramData::uniform2_array(const string &name, unsigned n, const float *v) { uniform(name, new UniformArray(n, v)); } +void ProgramData::uniform3_array(const string &name, unsigned n, const int *v) +{ + uniform(name, new UniformArray(n, v)); +} + void ProgramData::uniform3_array(const string &name, unsigned n, const float *v) { uniform(name, new UniformArray(n, v)); } +void ProgramData::uniform4_array(const string &name, unsigned n, const int *v) +{ + uniform(name, new UniformArray(n, v)); +} + void ProgramData::uniform4_array(const string &name, unsigned n, const float *v) { uniform(name, new UniformArray(n, v)); @@ -370,10 +418,16 @@ ProgramData::Loader::Loader(ProgramData &pd): add("uniform1i", &Loader::uniform1i); add("uniform", &Loader::uniform1f); add("uniform1f", &Loader::uniform1f); + add("uniform", &Loader::uniform2i); + add("uniform2i", &Loader::uniform2i); add("uniform", &Loader::uniform2f); add("uniform2f", &Loader::uniform2f); + add("uniform", &Loader::uniform3i); + add("uniform3i", &Loader::uniform3i); add("uniform", &Loader::uniform3f); add("uniform3f", &Loader::uniform3f); + add("uniform", &Loader::uniform4i); + add("uniform4i", &Loader::uniform4i); add("uniform", &Loader::uniform4f); add("uniform4f", &Loader::uniform4f); add("uniform1i_array", &Loader::uniform1i_array); @@ -394,16 +448,31 @@ void ProgramData::Loader::uniform1f(const string &n, float v) obj.uniform(n, v); } +void ProgramData::Loader::uniform2i(const string &n, int v0, int v1) +{ + obj.uniform(n, v0, v1); +} + void ProgramData::Loader::uniform2f(const string &n, float v0, float v1) { obj.uniform(n, v0, v1); } +void ProgramData::Loader::uniform3i(const string &n, int v0, int v1, int v2) +{ + obj.uniform(n, v0, v1, v2); +} + void ProgramData::Loader::uniform3f(const string &n, float v0, float v1, float v2) { obj.uniform(n, v0, v1, v2); } +void ProgramData::Loader::uniform4i(const string &n, int v0, int v1, int v2, int v3) +{ + obj.uniform(n, v0, v1, v2, v3); +} + void ProgramData::Loader::uniform4f(const string &n, float v0, float v1, float v2, float v3) { obj.uniform(n, v0, v1, v2, v3); @@ -424,6 +493,12 @@ void ProgramData::Loader::uniform_array_(const string &n, DataType t, unsigned e const int *data = reinterpret_cast(ldr.get_data()); if(elem_size==1) obj.uniform1_array(n, size, data); + else if(elem_size==2) + obj.uniform2_array(n, size, data); + else if(elem_size==3) + obj.uniform3_array(n, size, data); + else if(elem_size==4) + obj.uniform4_array(n, size, data); else throw logic_error("unsupported combination of array type and element size"); } @@ -455,16 +530,31 @@ void ProgramData::Loader::uniform1f_array(const string &n) uniform_array_(n, FLOAT, 1); } +void ProgramData::Loader::uniform2i_array(const string &n) +{ + uniform_array_(n, INT, 2); +} + void ProgramData::Loader::uniform2f_array(const string &n) { uniform_array_(n, FLOAT, 2); } +void ProgramData::Loader::uniform3i_array(const string &n) +{ + uniform_array_(n, INT, 3); +} + void ProgramData::Loader::uniform3f_array(const string &n) { uniform_array_(n, FLOAT, 3); } +void ProgramData::Loader::uniform4i_array(const string &n) +{ + uniform_array_(n, INT, 4); +} + void ProgramData::Loader::uniform4f_array(const string &n) { uniform_array_(n, FLOAT, 4); @@ -517,18 +607,36 @@ void ProgramData::ArrayLoader::uniform1f(float v) uniform(FLOAT, 1, &v); } +void ProgramData::ArrayLoader::uniform2i(int v0, int v1) +{ + int va[2] = { v0, v1 }; + uniform(INT, 2, va); +} + void ProgramData::ArrayLoader::uniform2f(float v0, float v1) { float va[2] = { v0, v1 }; uniform(FLOAT, 2, va); } +void ProgramData::ArrayLoader::uniform3i(int v0, int v1, int v2) +{ + int va[3] = { v0, v1, v2 }; + uniform(INT, 3, va); +} + void ProgramData::ArrayLoader::uniform3f(float v0, float v1, float v2) { float va[3] = { v0, v1, v2 }; uniform(FLOAT, 3, va); } +void ProgramData::ArrayLoader::uniform4i(int v0, int v1, int v2, int v3) +{ + int va[4] = { v0, v1, v2, v3 }; + uniform(INT, 4, va); +} + void ProgramData::ArrayLoader::uniform4f(float v0, float v1, float v2, float v3) { float va[4] = { v0, v1, v2, v3 }; diff --git a/source/programdata.h b/source/programdata.h index 07e1bb64..e045c6fd 100644 --- a/source/programdata.h +++ b/source/programdata.h @@ -35,14 +35,20 @@ public: private: void uniform1i(const std::string &, int); void uniform1f(const std::string &, float); + void uniform2i(const std::string &, int, int); void uniform2f(const std::string &, float, float); + void uniform3i(const std::string &, int, int, int); void uniform3f(const std::string &, float, float, float); + void uniform4i(const std::string &, int, int, int, int); void uniform4f(const std::string &, float, float, float, float); void uniform_array_(const std::string &, DataType, unsigned); void uniform1i_array(const std::string &); void uniform1f_array(const std::string &); + void uniform2i_array(const std::string &); void uniform2f_array(const std::string &); + void uniform3i_array(const std::string &); void uniform3f_array(const std::string &); + void uniform4i_array(const std::string &); void uniform4f_array(const std::string &); void uniform_array(const std::string &); }; @@ -67,8 +73,11 @@ private: void uniform(DataType, unsigned, const void *); void uniform1i(int); void uniform1f(float); + void uniform2i(int, int); void uniform2f(float, float); + void uniform3i(int, int, int); void uniform3f(float, float, float); + void uniform4i(int, int, int, int); void uniform4f(float, float, float, float); }; @@ -133,14 +142,20 @@ private: public: void uniform(const std::string &, int); void uniform(const std::string &, float); + void uniform(const std::string &, int, int); void uniform(const std::string &, float, float); + void uniform2(const std::string &, const int *); void uniform2(const std::string &, const float *); + void uniform(const std::string &, int, int, int); void uniform(const std::string &, float, float, float); void uniform(const std::string &, const Vector3 &); + void uniform3(const std::string &, const int *); void uniform3(const std::string &, const float *); + void uniform(const std::string &, int, int, int, int); void uniform(const std::string &, float, float, float, float); void uniform(const std::string &, const Vector4 &); void uniform(const std::string &, const Color &); + void uniform4(const std::string &, const int *); void uniform4(const std::string &, const float *); void uniform(const std::string &, const LinAl::Matrix &); void uniform_matrix2(const std::string &, const float *); @@ -150,8 +165,11 @@ public: void uniform_matrix4(const std::string &, const float *); void uniform1_array(const std::string &, unsigned, const int *); void uniform1_array(const std::string &, unsigned, const float *); + void uniform2_array(const std::string &, unsigned, const int *); void uniform2_array(const std::string &, unsigned, const float *); + void uniform3_array(const std::string &, unsigned, const int *); void uniform3_array(const std::string &, unsigned, const float *); + void uniform4_array(const std::string &, unsigned, const int *); void uniform4_array(const std::string &, unsigned, const float *); void uniform_matrix4_array(const std::string &, unsigned, const float *); diff --git a/source/uniform.cpp b/source/uniform.cpp index 7ebfc3e0..b183719f 100644 --- a/source/uniform.cpp +++ b/source/uniform.cpp @@ -17,18 +17,36 @@ void UniformScalar::apply(int index, unsigned size, const float *value) } +template<> +void UniformVector::apply(int index, unsigned size, const int *value) +{ + glUniform2iv(index, size, value); +} + template<> void UniformVector::apply(int index, unsigned size, const float *value) { glUniform2fv(index, size, value); } +template<> +void UniformVector::apply(int index, unsigned size, const int *value) +{ + glUniform3iv(index, size, value); +} + template<> void UniformVector::apply(int index, unsigned size, const float *value) { glUniform3fv(index, size, value); } +template<> +void UniformVector::apply(int index, unsigned size, const int *value) +{ + glUniform4iv(index, size, value); +} + template<> void UniformVector::apply(int index, unsigned size, const float *value) { diff --git a/source/uniform.h b/source/uniform.h index 780bfe74..8dc43ab5 100644 --- a/source/uniform.h +++ b/source/uniform.h @@ -84,8 +84,11 @@ public: { return new UniformVector(value); } }; +typedef UniformVector Uniform2i; typedef UniformVector Uniform2f; +typedef UniformVector Uniform3i; typedef UniformVector Uniform3f; +typedef UniformVector Uniform4i; typedef UniformVector Uniform4f; -- 2.45.2