Sign in to follow this  
gusso

Need help demistyfying glsl and multiple shaders.

Recommended Posts

Hello :) I've been messing around with glsl for a while now, at the moment I'm writing a "shader manager", everything seems quite trivial but then someone mentioned me that a program could have many 'shaders' attached, so I thought I should have a list for vertex and fragment shaders, per program. Would this be correct?. I don't understand why would this be required, so far I've only seen shaders that use 1 pair (vertex, fragment) and nothing else. Why would I need to support more shaders per program?, anyone care to explain me please?. The other day I was staring at some code someone wrote and they were actually doing what I mention, each 'shader' object (in their class) had the ability to store multiple frag and vert shaders. How is this any useful? What should the ideal 'shader manager' provide to the developer aside from an abstracted layer that handles the gl objects and shader loading?.

Share this post


Link to post
Share on other sites
In the engine I use (Horde3D) each "shader object" can contain several "shader contexts" - the contexts contain the actual shader code. This means that yes, one shader object can contain many different frag/vertex programs.

The point of this system is for the "shader object" to describe a type of material, and the "shader contexts" describe the individual techniques that are used by that material.

Share this post


Link to post
Share on other sites
OK that's starting to make sense, but how would the shader lib manage this situation? (ie. it has tons of shaders, how is it going to know when or where to enable them? ). Mind you I'm a little retarded unless you draw me a picture I might not understand it fully :D

I'm just writing this high-level manager so I don't have to mess around with the low level stuff, it's really driving me crazy!

Is there any website or piece of code I could take a look at to fully understand the concept?

Thanks

Share this post


Link to post
Share on other sites
I think you are talking about glAttachShader. According to the spec, yes you can attach multiple shader objects of the same type to the Program Object.
Then you need to call glLinkProgram.
Mind you that if something is wrong, linking will fail. For example, you can only have 1 main() for VS, 1 for FS, 1 for GS.

It is just a flexibility the API offers. At the end of the day, the drivers must produce a single executable code that gets uploaded to the GPU.
It might even produces 1 executable for VS, 1 for FS....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this