TIGSource Forums

Developer => Technical => Topic started by: kamac on August 28, 2012, 08:08:01 AM



Title: OpenGL binding attributes and uniforms - where
Post by: kamac on August 28, 2012, 08:08:01 AM
Hey.

I am thinking of where to bind uniforms and attributes to some certain shaders.
I have two options:

A) Bind them inside my shader class and let other classes just copy them. (Like sprites)
B) Bind them for each sprite class. (So, I'd have uniforms and attributes binding on each sprite's initialization)

Doing the 1st one is a little bit tense, but easier on performance.
Is there a big difference between those two?


Title: Re: OpenGL binding attributes and uniforms - where
Post by: ThemsAllTook on August 28, 2012, 08:51:15 AM
I handle this by using a variadic function for shader initialization, where the caller passes in a list of attribute names and indexes to be bound. This way, the caller knows the attribute locations it needs to use, but doesn't actually bind them itself. Calling glBindAttribLocation in a place other than your shader class seems like it's asking for trouble. I assume you'll potentially have one kind of shader applying to more than one kind of sprite, and you don't want both sprites doing the same binding.


Title: Re: OpenGL binding attributes and uniforms - where
Post by: Xienen on August 29, 2012, 04:40:48 PM
At present, I'm binding uniforms and attributes based on an object type.  If I need to use a different shader for an existing type, I simply subclass that type and override the uniform/attrib bindings.  The actual values for the uniforms come from values held in the objects, obviously, while the attribute values come from the vertex data in the vertex buffer.  I believe this will allow maximum flexibility without making it tooo difficult to setup a new shader.  I could be wrong, though, since I'm not that far into my engine's development, yet, much less the game's development.