Changeset 832 for trunk/src/shader


Ignore:
Timestamp:
Aug 17, 2011, 5:20:09 PM (9 years ago)
Author:
sam
Message:

shader: factor the uniform handling logic into platform-independent methods
for both OpenGL and the PS3.

Location:
trunk/src/shader
Files:
2 edited

Legend:

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

    r828 r832  
    184184        tmp = cgGetNamedParameter(data->frag_id, uni);
    185185    return (int)(intptr_t)tmp;
     186#endif
     187}
     188
     189void Shader::SetUniform(int uni, float f)
     190{
     191#if !defined __CELLOS_LV2__
     192    glUniform1f(uni, f);
     193#else
     194    cgGLSetParameter1f((CGparameter)(intptr_t)uni, f);
     195#endif
     196}
     197
     198void Shader::SetUniform(int uni, vec2 const &v)
     199{
     200#if !defined __CELLOS_LV2__
     201    glUniform2f(uni, v.x, v.y);
     202#else
     203    cgGLSetParameter2f((CGparameter)(intptr_t)uni, v.x, v.y);
     204#endif
     205}
     206
     207void Shader::SetUniform(int uni, vec3 const &v)
     208{
     209#if !defined __CELLOS_LV2__
     210    glUniform3f(uni, v.x, v.y, v.z);
     211#else
     212    cgGLSetParameter3f((CGparameter)(intptr_t)uni, v.x, v.y, v.z);
     213#endif
     214}
     215
     216void Shader::SetUniform(int uni, vec4 const &v)
     217{
     218    /* FIXME: use the array versions of these functions */
     219#if !defined __CELLOS_LV2__
     220    glUniform4f(uni, v.x, v.y, v.z, v.w);
     221#else
     222    cgGLSetParameter4f((CGparameter)(intptr_t)uni, v.x, v.y, v.z, v.w);
     223#endif
     224}
     225
     226void Shader::SetUniform(int uni, mat4 const &m)
     227{
     228#if !defined __CELLOS_LV2__
     229    glUniformMatrix4fv(uni, 1, GL_FALSE, &m[0][0]);
     230#else
     231    cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni, &m[0][0]);
    186232#endif
    187233}
  • trunk/src/shader/shader.h

    r783 r832  
    2929
    3030    int GetAttribLocation(char const *attr) const;
     31
    3132    int GetUniformLocation(char const *uni) const;
     33    void SetUniform(int uni, float f);
     34    void SetUniform(int uni, vec2 const &v);
     35    void SetUniform(int uni, vec3 const &v);
     36    void SetUniform(int uni, vec4 const &v);
     37    void SetUniform(int uni, mat4 const &m);
    3238
    3339    void Bind() const;
Note: See TracChangeset for help on using the changeset viewer.