Browse Source

gpu: add support for integer uniforms and fix a few PS3 and Linux compilation

issues that were introduced with the Direct3D changes.
legacy
Sam Hocevar sam 12 years ago
parent
commit
1485e5bf63
6 changed files with 67 additions and 18 deletions
  1. +2
    -2
      src/debug/quad.cpp
  2. +55
    -4
      src/gpu/shader.cpp
  3. +4
    -0
      src/gpu/shader.h
  4. +2
    -1
      src/gradient.cpp
  5. +3
    -10
      src/scene.cpp
  6. +1
    -1
      test/tutorial/tut03.cpp

+ 2
- 2
src/debug/quad.cpp View File

@@ -73,7 +73,7 @@ private:
GLuint buffer[NUM_BUFFERS]; GLuint buffer[NUM_BUFFERS];
Shader *shader[NUM_SHADERS]; Shader *shader[NUM_SHADERS];
GLuint attr[NUM_ATTRS]; GLuint attr[NUM_ATTRS];
GLuint uni[NUM_UNIFORMS];
ShaderUniform uni[NUM_UNIFORMS];
GLuint texture[NUM_TEXTURES]; GLuint texture[NUM_TEXTURES];
uint8_t image[1][TEX_SIZE * TEX_SIZE * 4]; uint8_t image[1][TEX_SIZE * TEX_SIZE * 4];


@@ -246,7 +246,7 @@ void DebugQuad::TickDraw(float deltams)
GLuint *buffer = data->buffer; GLuint *buffer = data->buffer;
Shader **shader = data->shader; Shader **shader = data->shader;
GLuint *attr = data->attr; GLuint *attr = data->attr;
GLuint *uni = data->uni;
ShaderUniform *uni = data->uni;


/* These may be shared across calls */ /* These may be shared across calls */
GLfloat const *sine; GLfloat const *sine;


+ 55
- 4
src/gpu/shader.cpp View File

@@ -284,6 +284,51 @@ ShaderUniform Shader::GetUniformLocation(char const *uni) const
return ret; return ret;
} }


void Shader::SetUniform(ShaderUniform const &uni, int i)
{
#if defined USE_D3D9 || defined _XBOX
SetUniform(uni, ivec4(i, 0, 0, 0));
#elif !defined __CELLOS_LV2__
glUniform1i(uni.frag, i);
#else
/* FIXME: does this exist at all? */
//cgGLSetParameter1i((CGparameter)uni.frag, i);
#endif
}

void Shader::SetUniform(ShaderUniform const &uni, ivec2 const &v)
{
#if defined USE_D3D9 || defined _XBOX
SetUniform(uni, ivec4(v, 0, 0));
#elif !defined __CELLOS_LV2__
glUniform2i(uni.frag, v.x, v.y);
#else
/* FIXME: does this exist at all? */
#endif
}

void Shader::SetUniform(ShaderUniform const &uni, ivec3 const &v)
{
#if defined USE_D3D9 || defined _XBOX
SetUniform(uni, ivec4(v, 0));
#elif !defined __CELLOS_LV2__
glUniform3i(uni.frag, v.x, v.y, v.z);
#else
/* FIXME: does this exist at all? */
#endif
}

void Shader::SetUniform(ShaderUniform const &uni, ivec4 const &v)
{
#if defined USE_D3D9 || defined _XBOX
SetUniform(uni, v);
#elif !defined __CELLOS_LV2__
glUniform4i(uni.frag, v.x, v.y, v.z, v.w);
#else
/* FIXME: does this exist at all? */
#endif
}

void Shader::SetUniform(ShaderUniform const &uni, float f) void Shader::SetUniform(ShaderUniform const &uni, float f)
{ {
#if defined USE_D3D9 || defined _XBOX #if defined USE_D3D9 || defined _XBOX
@@ -335,9 +380,12 @@ void Shader::SetUniform(ShaderUniform const &uni, vec4 const &v)
if (uni.flags & 2) if (uni.flags & 2)
g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &v[0], 1); g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &v[0], 1);
#elif !defined __CELLOS_LV2__ #elif !defined __CELLOS_LV2__
glUniform4f(uni, v.x, v.y, v.z, v.w);
glUniform4f(uni.frag, v.x, v.y, v.z, v.w);
#else #else
cgGLSetParameter4f((CGparameter)uni, v.x, v.y, v.z, v.w);
if (uni.frag)
cgGLSetParameter4f((CGparameter)uni.frag, v.x, v.y, v.z, v.w);
if (uni.vert)
cgGLSetParameter4f((CGparameter)uni.vert, v.x, v.y, v.z, v.w);
#endif #endif
} }


@@ -349,9 +397,12 @@ void Shader::SetUniform(ShaderUniform const &uni, mat4 const &m)
if (uni.flags & 2) if (uni.flags & 2)
g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 4); g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 4);
#elif !defined __CELLOS_LV2__ #elif !defined __CELLOS_LV2__
glUniformMatrix4fv(uni, 1, GL_FALSE, &m[0][0]);
glUniformMatrix4fv(uni.frag, 1, GL_FALSE, &m[0][0]);
#else #else
cgGLSetMatrixParameterfc((CGparameter)uni, &m[0][0]);
if (uni.frag)
cgGLSetMatrixParameterfc((CGparameter)uni.frag, &m[0][0]);
if (uni.vert)
cgGLSetMatrixParameterfc((CGparameter)uni.vert, &m[0][0]);
#endif #endif
} }




+ 4
- 0
src/gpu/shader.h View File

@@ -45,6 +45,10 @@ public:
int GetAttribLocation(char const *attr) const; int GetAttribLocation(char const *attr) const;


ShaderUniform GetUniformLocation(char const *uni) const; ShaderUniform GetUniformLocation(char const *uni) const;
void SetUniform(ShaderUniform const &uni, int i);
void SetUniform(ShaderUniform const &uni, ivec2 const &v);
void SetUniform(ShaderUniform const &uni, ivec3 const &v);
void SetUniform(ShaderUniform const &uni, ivec4 const &v);
void SetUniform(ShaderUniform const &uni, float f); void SetUniform(ShaderUniform const &uni, float f);
void SetUniform(ShaderUniform const &uni, vec2 const &v); void SetUniform(ShaderUniform const &uni, vec2 const &v);
void SetUniform(ShaderUniform const &uni, vec3 const &v); void SetUniform(ShaderUniform const &uni, vec3 const &v);


+ 2
- 1
src/gradient.cpp View File

@@ -166,7 +166,8 @@ void Gradient::TickDraw(float deltams)


mat4 model_matrix = mat4(1.0f); mat4 model_matrix = mat4(1.0f);


GLuint uni_mat, attr_pos, attr_col;
ShaderUniform uni_mat;
GLuint attr_pos, attr_col;
#if !defined __CELLOS_LV2__ #if !defined __CELLOS_LV2__
attr_pos = data->shader->GetAttribLocation("in_Vertex"); attr_pos = data->shader->GetAttribLocation("in_Vertex");
attr_col = data->shader->GetAttribLocation("in_Color"); attr_col = data->shader->GetAttribLocation("in_Color");


+ 3
- 10
src/scene.cpp View File

@@ -324,7 +324,8 @@ void Scene::Render() // XXX: rename to Blit()
data->model_matrix *= mat4::translate(-320.0f, -240.0f, 0.0f); data->model_matrix *= mat4::translate(-320.0f, -240.0f, 0.0f);
// XXX: end of debug stuff // XXX: end of debug stuff


int uni_mat, uni_tex, attr_pos, attr_tex;
ShaderUniform uni_mat, uni_tex;
int attr_pos, attr_tex;
#if !defined __CELLOS_LV2__ #if !defined __CELLOS_LV2__
attr_pos = stdshader->GetAttribLocation("in_Position"); attr_pos = stdshader->GetAttribLocation("in_Position");
attr_tex = stdshader->GetAttribLocation("in_TexCoord"); attr_tex = stdshader->GetAttribLocation("in_TexCoord");
@@ -339,16 +340,8 @@ void Scene::Render() // XXX: rename to Blit()
uni_mat = stdshader->GetUniformLocation("model_matrix"); uni_mat = stdshader->GetUniformLocation("model_matrix");
stdshader->SetUniform(uni_mat, data->model_matrix); stdshader->SetUniform(uni_mat, data->model_matrix);


#if defined USE_D3D9 || defined _XBOX
/* TODO */
#elif !defined __CELLOS_LV2__
uni_tex = stdshader->GetUniformLocation("in_Texture"); uni_tex = stdshader->GetUniformLocation("in_Texture");
glUniform1i(uni_tex, 0);
#else
// WTF? this doesn't exist
//uni_tex = stdshader->GetUniformLocation("in_Texture");
//cgGLSetParameter1i((CGparameter)(intptr_t)uni_tex, 0);
#endif
stdshader->SetUniform(uni_tex, 0);


#if defined USE_D3D9 || defined _XBOX #if defined USE_D3D9 || defined _XBOX
/* TODO */ /* TODO */


+ 1
- 1
test/tutorial/tut03.cpp View File

@@ -453,7 +453,7 @@ public:


if (!m_ready) if (!m_ready)
{ {
#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9
#if !defined _XBOX && !defined USE_D3D9
/* Create a texture of half the width and twice the height /* Create a texture of half the width and twice the height
* so that we can upload four different subimages each frame. */ * so that we can upload four different subimages each frame. */
glGenTextures(1, &m_texid); glGenTextures(1, &m_texid);


Loading…
Cancel
Save