Jump to content
  • Advertisement
Sign in to follow this  
gusso

Need help demistyfying glsl and multiple shaders.

This topic is 3557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!