Need help demistyfying glsl and multiple shaders.

Started by
2 comments, last by V-man 15 years, 5 months ago
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?.
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.
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
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....
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement