Hello,
Quick question. I've made a shader program wrapper that does what you'd expect, but I'm not sure how to tackle all the different opengl functions for 'glSetUniform*'. For example to add to the api every single call feels messy and cluttered, is there a better way I am missing?
For all the different uniform functions: http://www.opengl.org/sdk/docs/man3/ -> glUniform
Thanks
GLSL shader program wrapper and uniforms
Started by KaiserJohan, Nov 09 2012 08:22 AM
3 replies to this topic
Sponsor:
#4 Members - Reputation: 1986
Posted 10 November 2012 - 08:14 AM
With buffers you only need one call, as many uniforms can be stored in the same buffer, with different types.
Something like this for example, in your source:
And in GLSL:
Something like this for example, in your source:
struct Uniforms {
float transformMatrix[16];
float color[4];
};
Uniforms uniforms;
uniforms.transformMatrix ...
uniforms.color ...
glBufferData(GL_UNIFORM_BUFFER, ..., &uniforms, ..);
And in GLSL:
layout(std140) uniform Uniforms {
mat4 transformMatrix;
vec4 color;
};
in vec3 inPosition;
out vec4 outColor;
void main() {
gl_position = transformMatrix * vec4(inPosition, 1.0);
outColor = color;
}
Edited by Erik Rufelt, 10 November 2012 - 08:16 AM.