瀏覽代碼

gpu: add methods to send mat2 and mat3 matrices to the shader.

legacy
Sam Hocevar sam 12 年之前
父節點
當前提交
f1c0e3ba4e
共有 3 個檔案被更改,包括 33 行新增10 行删除
  1. +31
    -0
      src/gpu/shader.cpp
  2. +2
    -0
      src/gpu/shader.h
  3. +0
    -10
      src/lol/math/vector.h

+ 31
- 0
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


+ 2
- 0
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;


+ 0
- 10
src/lol/math/vector.h 查看文件

@@ -1452,11 +1452,6 @@ template <typename T> struct Mat3
return rotate(angle, v) * mat;
}

static Mat3<T> normal(Mat3<T> const &mat)
{
return transpose(inverse(mat));
}

void printf() const;

#if !defined __ANDROID__
@@ -1546,11 +1541,6 @@ template <typename T> struct Mat4
return rotate(angle, v) * mat;
}

static Mat3<T> normal(Mat4<T> const &mat)
{
return transpose(inverse(Mat3<T>(mat)));
}

/* Helpers for view matrices */
static Mat4<T> lookat(Vec3<T> eye, Vec3<T> center, Vec3<T> up);



Loading…
取消
儲存