diff --git a/src/debug/quad.cpp b/src/debug/quad.cpp index de2384e2..71324829 100644 --- a/src/debug/quad.cpp +++ b/src/debug/quad.cpp @@ -73,7 +73,7 @@ private: GLuint buffer[NUM_BUFFERS]; Shader *shader[NUM_SHADERS]; GLuint attr[NUM_ATTRS]; - GLuint uni[NUM_UNIFORMS]; + ShaderUniform uni[NUM_UNIFORMS]; GLuint texture[NUM_TEXTURES]; uint8_t image[1][TEX_SIZE * TEX_SIZE * 4]; @@ -246,7 +246,7 @@ void DebugQuad::TickDraw(float deltams) GLuint *buffer = data->buffer; Shader **shader = data->shader; GLuint *attr = data->attr; - GLuint *uni = data->uni; + ShaderUniform *uni = data->uni; /* These may be shared across calls */ GLfloat const *sine; diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index 0c9ec162..e3522222 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -284,6 +284,51 @@ ShaderUniform Shader::GetUniformLocation(char const *uni) const 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) { #if defined USE_D3D9 || defined _XBOX @@ -335,9 +380,12 @@ void Shader::SetUniform(ShaderUniform const &uni, vec4 const &v) if (uni.flags & 2) g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &v[0], 1); #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 - 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 } @@ -349,9 +397,12 @@ void Shader::SetUniform(ShaderUniform const &uni, mat4 const &m) if (uni.flags & 2) g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 4); #elif !defined __CELLOS_LV2__ - glUniformMatrix4fv(uni, 1, GL_FALSE, &m[0][0]); + glUniformMatrix4fv(uni.frag, 1, GL_FALSE, &m[0][0]); #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 } diff --git a/src/gpu/shader.h b/src/gpu/shader.h index f67b10ca..9b70b3af 100644 --- a/src/gpu/shader.h +++ b/src/gpu/shader.h @@ -45,6 +45,10 @@ public: int GetAttribLocation(char const *attr) 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, vec2 const &v); void SetUniform(ShaderUniform const &uni, vec3 const &v); diff --git a/src/gradient.cpp b/src/gradient.cpp index cdb776e8..4a6ae992 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -166,7 +166,8 @@ void Gradient::TickDraw(float deltams) 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__ attr_pos = data->shader->GetAttribLocation("in_Vertex"); attr_col = data->shader->GetAttribLocation("in_Color"); diff --git a/src/scene.cpp b/src/scene.cpp index 93f81fd6..8080c72f 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -324,7 +324,8 @@ void Scene::Render() // XXX: rename to Blit() data->model_matrix *= mat4::translate(-320.0f, -240.0f, 0.0f); // 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__ attr_pos = stdshader->GetAttribLocation("in_Position"); attr_tex = stdshader->GetAttribLocation("in_TexCoord"); @@ -339,16 +340,8 @@ void Scene::Render() // XXX: rename to Blit() uni_mat = stdshader->GetUniformLocation("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"); - 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 /* TODO */ diff --git a/test/tutorial/tut03.cpp b/test/tutorial/tut03.cpp index 2d1abec9..ad166742 100644 --- a/test/tutorial/tut03.cpp +++ b/test/tutorial/tut03.cpp @@ -453,7 +453,7 @@ public: 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 * so that we can upload four different subimages each frame. */ glGenTextures(1, &m_texid);