From f1c0e3ba4ee5e6c5cf0f2fc65df16a1255c64980 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 21 Apr 2012 16:58:33 +0000 Subject: [PATCH] gpu: add methods to send mat2 and mat3 matrices to the shader. --- src/gpu/shader.cpp | 31 +++++++++++++++++++++++++++++++ src/gpu/shader.h | 2 ++ src/lol/math/vector.h | 10 ---------- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index 9651fc2c..a5cba2f2 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -395,6 +395,37 @@ void Shader::SetUniform(ShaderUniform const &uni, vec4 const &v) #endif } +void Shader::SetUniform(ShaderUniform const &uni, mat2 const &m) +{ +#if defined USE_D3D9 || defined _XBOX + if (uni.flags & 1) + g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 1); + if (uni.flags & 2) + g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 1); +#elif !defined __CELLOS_LV2__ + glUniformMatrix2fv(uni.frag, 1, GL_FALSE, &m[0][0]); +#else + /* Not implemented */ + Abort(); +#endif +} + +void Shader::SetUniform(ShaderUniform const &uni, mat3 const &m) +{ +#if defined USE_D3D9 || defined _XBOX + /* FIXME: does this work at all? */ + if (uni.flags & 1) + g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 3); + if (uni.flags & 2) + g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 3); +#elif !defined __CELLOS_LV2__ + glUniformMatrix3fv(uni.frag, 1, GL_FALSE, &m[0][0]); +#else + /* FIXME: not implemented */ + Abort(); +#endif +} + void Shader::SetUniform(ShaderUniform const &uni, mat4 const &m) { #if defined USE_D3D9 || defined _XBOX diff --git a/src/gpu/shader.h b/src/gpu/shader.h index a682487a..3828e323 100644 --- a/src/gpu/shader.h +++ b/src/gpu/shader.h @@ -66,6 +66,8 @@ public: void SetUniform(ShaderUniform const &uni, vec2 const &v); void SetUniform(ShaderUniform const &uni, vec3 const &v); void SetUniform(ShaderUniform const &uni, vec4 const &v); + void SetUniform(ShaderUniform const &uni, mat2 const &m); + void SetUniform(ShaderUniform const &uni, mat3 const &m); void SetUniform(ShaderUniform const &uni, mat4 const &m); void Bind() const; diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 5e47c8f2..40c9139f 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1452,11 +1452,6 @@ template struct Mat3 return rotate(angle, v) * mat; } - static Mat3 normal(Mat3 const &mat) - { - return transpose(inverse(mat)); - } - void printf() const; #if !defined __ANDROID__ @@ -1546,11 +1541,6 @@ template struct Mat4 return rotate(angle, v) * mat; } - static Mat3 normal(Mat4 const &mat) - { - return transpose(inverse(Mat3(mat))); - } - /* Helpers for view matrices */ static Mat4 lookat(Vec3 eye, Vec3 center, Vec3 up);