Jump to content

  • Log In with Google      Sign In   
  • Create Account


GLSL shader program wrapper and uniforms


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 KaiserJohan   Members   -  Reputation: 1116

Like
0Likes
Like

Posted 09 November 2012 - 08:22 AM

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

Sponsor:

#2 Erik Rufelt   Crossbones+   -  Reputation: 3344

Like
1Likes
Like

Posted 09 November 2012 - 10:16 AM

Look into uniform buffers.

#3 KaiserJohan   Members   -  Reputation: 1116

Like
0Likes
Like

Posted 10 November 2012 - 05:59 AM

I've read about it, but I'm not sure how that would help me?

#4 Erik Rufelt   Crossbones+   -  Reputation: 3344

Like
2Likes
Like

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:
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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS