X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Funiform.cpp;h=8aba365be5e5cd2238a0934eb639d6585c453d8e;hb=8f7d5b6460ef68e7316c7f556b7152d9c9f7bfe2;hp=af49c047f71be82f5c635a66560a40d7f27d549d;hpb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8;p=libs%2Fgl.git diff --git a/source/uniform.cpp b/source/uniform.cpp index af49c047..8aba365b 100644 --- a/source/uniform.cpp +++ b/source/uniform.cpp @@ -1,107 +1,57 @@ -#include #include "arb_shader_objects.h" #include "uniform.h" namespace Msp { namespace GL { -Uniform1i::Uniform1i(int v_): - v(v_) -{ } - -void Uniform1i::apply(int index) const -{ - glUniform1iARB(index, v); -} - -Uniform1i *Uniform1i::clone() const -{ - return new Uniform1i(v); -} - - -Uniform1f::Uniform1f(float v_): - v(v_) -{ } - -void Uniform1f::apply(int index) const -{ - glUniform1fARB(index, v); -} - -Uniform1f *Uniform1f::clone() const -{ - return new Uniform1f(v); -} - - -Uniform2f::Uniform2f(float v0, float v1) -{ - v[0] = v0; - v[1] = v1; -} - -void Uniform2f::apply(int index) const -{ - glUniform2fvARB(index, 1, v); -} - -Uniform2f *Uniform2f::clone() const -{ - return new Uniform2f(v[0], v[1]); -} - - -Uniform3f::Uniform3f(float v0, float v1, float v2) -{ - v[0] = v0; - v[1] = v1; - v[2] = v2; -} - -void Uniform3f::apply(int index) const +template<> +void UniformScalar::apply(int index, unsigned size, const int *value) { - glUniform3fvARB(index, 1, v); + glUniform1iv(index, size, value); } -Uniform3f *Uniform3f::clone() const +template<> +void UniformScalar::apply(int index, unsigned size, const float *value) { - return new Uniform3f(v[0], v[1], v[2]); + glUniform1fv(index, size, value); } -Uniform4f::Uniform4f(float v0, float v1, float v2, float v3) +template<> +void UniformVector::apply(int index, unsigned size, const float *value) { - v[0] = v0; - v[1] = v1; - v[2] = v2; - v[3] = v3; + glUniform2fv(index, size, value); } -void Uniform4f::apply(int index) const +template<> +void UniformVector::apply(int index, unsigned size, const float *value) { - glUniform4fvARB(index, 1, v); + glUniform3fv(index, size, value); } -Uniform4f *Uniform4f::clone() const +template<> +void UniformVector::apply(int index, unsigned size, const float *value) { - return new Uniform4f(v[0], v[1], v[2], v[3]); + glUniform4fv(index, size, value); } -UniformMatrix4x4f::UniformMatrix4x4f(const float *vp) +template<> +void UniformMatrix::apply(int index, unsigned size, const float *value) { - std::copy(vp, vp+16, v); + glUniformMatrix2fv(index, size, false, value); } -void UniformMatrix4x4f::apply(int index) const +template<> +void UniformMatrix::apply(int index, unsigned size, const float *value) { - glUniformMatrix4fvARB(index, 1, false, v); + glUniformMatrix2fv(index, size, false, value); } -UniformMatrix4x4f *UniformMatrix4x4f::clone() const +template<> +void UniformMatrix::apply(int index, unsigned size, const float *value) { - return new UniformMatrix4x4f(v); + glUniformMatrix4fv(index, size, false, value); } } // namespace GL