Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

GLSL shader program wrapper and uniforms

4: Adsense

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   

2269
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

#2 Erik Rufelt   Members   

5901
Like
1Likes
Like

Posted 09 November 2012 - 10:16 AM

Look into uniform buffers.

#3 KaiserJohan   Members   

2269
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   Members   

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