GLSL shader program wrapper and uniforms

Started by
2 comments, last by Erik Rufelt 11 years, 5 months ago
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
Advertisement
Look into uniform buffers.
I've read about it, but I'm not sure how that would help me?
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:

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;
}

This topic is closed to new replies.

Advertisement