Changeset 1259


Ignore:
Timestamp:
Apr 21, 2012, 6:58:33 PM (8 years ago)
Author:
sam
Message:

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

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/shader.cpp

    r1241 r1259  
    393393    if (uni.vert)
    394394        cgGLSetParameter4f((CGparameter)uni.vert, v.x, v.y, v.z, v.w);
     395#endif
     396}
     397
     398void Shader::SetUniform(ShaderUniform const &uni, mat2 const &m)
     399{
     400#if defined USE_D3D9 || defined _XBOX
     401    if (uni.flags & 1)
     402        g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 1);
     403    if (uni.flags & 2)
     404        g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 1);
     405#elif !defined __CELLOS_LV2__
     406    glUniformMatrix2fv(uni.frag, 1, GL_FALSE, &m[0][0]);
     407#else
     408    /* Not implemented */
     409    Abort();
     410#endif
     411}
     412
     413void Shader::SetUniform(ShaderUniform const &uni, mat3 const &m)
     414{
     415#if defined USE_D3D9 || defined _XBOX
     416    /* FIXME: does this work at all? */
     417    if (uni.flags & 1)
     418        g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 3);
     419    if (uni.flags & 2)
     420        g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 3);
     421#elif !defined __CELLOS_LV2__
     422    glUniformMatrix3fv(uni.frag, 1, GL_FALSE, &m[0][0]);
     423#else
     424    /* FIXME: not implemented */
     425    Abort();
    395426#endif
    396427}
  • trunk/src/gpu/shader.h

    r1241 r1259  
    6767    void SetUniform(ShaderUniform const &uni, vec3 const &v);
    6868    void SetUniform(ShaderUniform const &uni, vec4 const &v);
     69    void SetUniform(ShaderUniform const &uni, mat2 const &m);
     70    void SetUniform(ShaderUniform const &uni, mat3 const &m);
    6971    void SetUniform(ShaderUniform const &uni, mat4 const &m);
    7072
  • trunk/src/lol/math/vector.h

    r1258 r1259  
    14531453    }
    14541454
    1455     static Mat3<T> normal(Mat3<T> const &mat)
    1456     {
    1457         return transpose(inverse(mat));
    1458     }
    1459 
    14601455    void printf() const;
    14611456
     
    15451540    {
    15461541        return rotate(angle, v) * mat;
    1547     }
    1548 
    1549     static Mat3<T> normal(Mat4<T> const &mat)
    1550     {
    1551         return transpose(inverse(Mat3<T>(mat)));
    15521542    }
    15531543
Note: See TracChangeset for help on using the changeset viewer.