Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLSL shader program wrapper and uniforms

Started by KaiserJohan Nov 9, 2012 at 2:22 PM 2 replies 2.4k views
Original Post
KaiserJohan
KaiserJohan
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
Erik Rufelt
Erik Rufelt
Look into uniform buffers.
KaiserJohan
KaiserJohan
I've read about it, but I'm not sure how that would help me?
Erik Rufelt
Erik Rufelt
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;
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.