Changeset 832


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

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

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debug/quad.cpp

    r830 r832  
    191191    }
    192192
     193    /* Our default quad color */
     194    vec4 orange(0.8f, 0.5f, 0.2f, 1.0f);
     195
    193196    /* Cheap iterators */
    194197#if !defined __CELLOS_LV2__ && !defined ANDROID_NDK
     
    208211     */
    209212#if defined HAVE_GLBEGIN || defined USE_GLEW
    210     glColor3f(0.8f, 0.5f, 0.2f);
     213    glColor3f(orange.x, orange.y, orange.z);
    211214    glBegin(GL_TRIANGLES);
    212215        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     
    429432     */
    430433#if !defined ANDROID_NDK
    431     glColor4f(0.8f, 0.5f, 0.2f, 1.0f);
     434    glColor4f(orange.x, orange.y, orange.z, orange.w);
    432435    glEnableClientState(GL_VERTEX_ARRAY);
    433436
     
    575578    }
    576579    shader[0]->Bind();
     580    shader[0]->SetUniform(uni[0], orange);
    577581    shader++;
    578 #if !defined __CELLOS_LV2__
    579     glUniform4f(uni[0], 0.8f, 0.5f, 0.2f, 1.0f);
    580 #else
    581     cgGLSetParameter4f((CGparameter)(intptr_t)uni[0], 0.8f, 0.5f, 0.2f, 1.0f);
    582 #endif
    583582    uni++;
    584583
     
    692691    }
    693692    shader[0]->Bind();
     693    shader[0]->SetUniform(uni[0], t2);
    694694    shader++;
    695 #if !defined __CELLOS_LV2__
    696     glUniformMatrix4fv(uni[0], 1, GL_FALSE, &t2[0][0]);
    697 #else
    698     cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni[0], &t2[0][0]);
    699 #endif
    700695    uni++;
    701696
  • trunk/src/scene.cpp

    r831 r832  
    267267    stdshader->Bind();
    268268
     269    uni_mat = stdshader->GetUniformLocation("proj_matrix");
     270    stdshader->SetUniform(uni_mat, Video::GetProjMatrix());
     271    uni_mat = stdshader->GetUniformLocation("view_matrix");
     272    stdshader->SetUniform(uni_mat, Video::GetViewMatrix());
     273    uni_mat = stdshader->GetUniformLocation("model_matrix");
     274    stdshader->SetUniform(uni_mat, data->model_matrix);
     275
    269276#if !defined __CELLOS_LV2__
    270     uni_mat = stdshader->GetUniformLocation("proj_matrix");
    271     glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &Video::GetProjMatrix()[0][0]);
    272     uni_mat = stdshader->GetUniformLocation("view_matrix");
    273     glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &Video::GetViewMatrix()[0][0]);
    274     uni_mat = stdshader->GetUniformLocation("model_matrix");
    275     glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &data->model_matrix[0][0]);
    276 
    277277    uni_tex = stdshader->GetUniformLocation("in_Texture");
    278278    glUniform1i(uni_tex, 0);
    279279#else
    280     uni_mat = stdshader->GetUniformLocation("proj_matrix");
    281     cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni_mat, &Video::GetProjMatrix()[0][0]);
    282     uni_mat = stdshader->GetUniformLocation("view_matrix");
    283     cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni_mat, &Video::GetViewMatrix()[0][0]);
    284     uni_mat = stdshader->GetUniformLocation("model_matrix");
    285     cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni_mat, &data->model_matrix[0][0]);
    286 
    287280    // WTF? this doesn't exist
    288281    //uni_tex = stdshader->GetUniformLocation("in_Texture");
  • 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.