Changeset 1215


Ignore:
Timestamp:
Apr 11, 2012, 1:41:55 AM (8 years ago)
Author:
sam
Message:

gpu: add support for integer uniforms and fix a few PS3 and Linux compilation
issues that were introduced with the Direct3D changes.

Location:
trunk
Files:
6 edited

Legend:

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

    r1208 r1215  
    7474    Shader *shader[NUM_SHADERS];
    7575    GLuint attr[NUM_ATTRS];
    76     GLuint uni[NUM_UNIFORMS];
     76    ShaderUniform uni[NUM_UNIFORMS];
    7777    GLuint texture[NUM_TEXTURES];
    7878    uint8_t image[1][TEX_SIZE * TEX_SIZE * 4];
     
    247247    Shader **shader = data->shader;
    248248    GLuint *attr = data->attr;
    249     GLuint *uni = data->uni;
     249    ShaderUniform *uni = data->uni;
    250250
    251251    /* These may be shared across calls */
  • trunk/src/gpu/shader.cpp

    r1214 r1215  
    285285}
    286286
     287void Shader::SetUniform(ShaderUniform const &uni, int i)
     288{
     289#if defined USE_D3D9 || defined _XBOX
     290    SetUniform(uni, ivec4(i, 0, 0, 0));
     291#elif !defined __CELLOS_LV2__
     292    glUniform1i(uni.frag, i);
     293#else
     294    /* FIXME: does this exist at all? */
     295    //cgGLSetParameter1i((CGparameter)uni.frag, i);
     296#endif
     297}
     298
     299void Shader::SetUniform(ShaderUniform const &uni, ivec2 const &v)
     300{
     301#if defined USE_D3D9 || defined _XBOX
     302    SetUniform(uni, ivec4(v, 0, 0));
     303#elif !defined __CELLOS_LV2__
     304    glUniform2i(uni.frag, v.x, v.y);
     305#else
     306    /* FIXME: does this exist at all? */
     307#endif
     308}
     309
     310void Shader::SetUniform(ShaderUniform const &uni, ivec3 const &v)
     311{
     312#if defined USE_D3D9 || defined _XBOX
     313    SetUniform(uni, ivec4(v, 0));
     314#elif !defined __CELLOS_LV2__
     315    glUniform3i(uni.frag, v.x, v.y, v.z);
     316#else
     317    /* FIXME: does this exist at all? */
     318#endif
     319}
     320
     321void Shader::SetUniform(ShaderUniform const &uni, ivec4 const &v)
     322{
     323#if defined USE_D3D9 || defined _XBOX
     324    SetUniform(uni, v);
     325#elif !defined __CELLOS_LV2__
     326    glUniform4i(uni.frag, v.x, v.y, v.z, v.w);
     327#else
     328    /* FIXME: does this exist at all? */
     329#endif
     330}
     331
    287332void Shader::SetUniform(ShaderUniform const &uni, float f)
    288333{
     
    336381        g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &v[0], 1);
    337382#elif !defined __CELLOS_LV2__
    338     glUniform4f(uni, v.x, v.y, v.z, v.w);
    339 #else
    340     cgGLSetParameter4f((CGparameter)uni, v.x, v.y, v.z, v.w);
     383    glUniform4f(uni.frag, v.x, v.y, v.z, v.w);
     384#else
     385    if (uni.frag)
     386        cgGLSetParameter4f((CGparameter)uni.frag, v.x, v.y, v.z, v.w);
     387    if (uni.vert)
     388        cgGLSetParameter4f((CGparameter)uni.vert, v.x, v.y, v.z, v.w);
    341389#endif
    342390}
     
    350398        g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 4);
    351399#elif !defined __CELLOS_LV2__
    352     glUniformMatrix4fv(uni, 1, GL_FALSE, &m[0][0]);
    353 #else
    354     cgGLSetMatrixParameterfc((CGparameter)uni, &m[0][0]);
     400    glUniformMatrix4fv(uni.frag, 1, GL_FALSE, &m[0][0]);
     401#else
     402    if (uni.frag)
     403        cgGLSetMatrixParameterfc((CGparameter)uni.frag, &m[0][0]);
     404    if (uni.vert)
     405        cgGLSetMatrixParameterfc((CGparameter)uni.vert, &m[0][0]);
    355406#endif
    356407}
  • trunk/src/gpu/shader.h

    r1214 r1215  
    4646
    4747    ShaderUniform GetUniformLocation(char const *uni) const;
     48    void SetUniform(ShaderUniform const &uni, int i);
     49    void SetUniform(ShaderUniform const &uni, ivec2 const &v);
     50    void SetUniform(ShaderUniform const &uni, ivec3 const &v);
     51    void SetUniform(ShaderUniform const &uni, ivec4 const &v);
    4852    void SetUniform(ShaderUniform const &uni, float f);
    4953    void SetUniform(ShaderUniform const &uni, vec2 const &v);
  • trunk/src/gradient.cpp

    r1208 r1215  
    167167    mat4 model_matrix = mat4(1.0f);
    168168
    169     GLuint uni_mat, attr_pos, attr_col;
     169    ShaderUniform uni_mat;
     170    GLuint attr_pos, attr_col;
    170171#if !defined __CELLOS_LV2__
    171172    attr_pos = data->shader->GetAttribLocation("in_Vertex");
  • trunk/src/scene.cpp

    r1212 r1215  
    325325    // XXX: end of debug stuff
    326326
    327     int uni_mat, uni_tex, attr_pos, attr_tex;
     327    ShaderUniform uni_mat, uni_tex;
     328    int attr_pos, attr_tex;
    328329#if !defined __CELLOS_LV2__
    329330    attr_pos = stdshader->GetAttribLocation("in_Position");
     
    340341    stdshader->SetUniform(uni_mat, data->model_matrix);
    341342
    342 #if defined USE_D3D9 || defined _XBOX
    343     /* TODO */
    344 #elif !defined __CELLOS_LV2__
    345343    uni_tex = stdshader->GetUniformLocation("in_Texture");
    346     glUniform1i(uni_tex, 0);
    347 #else
    348     // WTF? this doesn't exist
    349     //uni_tex = stdshader->GetUniformLocation("in_Texture");
    350     //cgGLSetParameter1i((CGparameter)(intptr_t)uni_tex, 0);
    351 #endif
     344    stdshader->SetUniform(uni_tex, 0);
    352345
    353346#if defined USE_D3D9 || defined _XBOX
  • trunk/test/tutorial/tut03.cpp

    r1214 r1215  
    454454        if (!m_ready)
    455455        {
    456 #if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9
     456#if !defined _XBOX && !defined USE_D3D9
    457457            /* Create a texture of half the width and twice the height
    458458             * so that we can upload four different subimages each frame. */
Note: See TracChangeset for help on using the changeset viewer.