Jump to content
  • Advertisement
Sign in to follow this  
Decrius

OpenGL Managing multiple shaders in one program

This topic is 3494 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

Hi, for an OpenGL GUI library I thought the addition of shaders would be pretty nice. However, I'm not really experience with shaders yet. I did play around with it once, so loading and simple using them is no problem, however I need a bit more: I thought of a Shader object, which I can then bind to any GUI element, this Shader object would hold one or more actual OpenGL shaders. However, which functions should I call in which order for OGL? Say, the Shader object starts empty with one GLuint for the program ID and an array of GLuint's for shader ID's. Then, when adding a shader I thought of doing the following steps: - create new array element and store an ID using the glCreateShaderObjectARB function - read the shader source from file / memory - use glShaderSourceARB to set the source - compile using glCompileShaderARB - attach to program using glAttachObjectARB As for the program object, I thought of this: - whenever Shader is initialised, make a new program object using glCreateProgramObjectARB - use glLinkProgramARB to link the program (is this correct!?) - whenever shaders are added, I use glAttachObjectARB to attach it to the program - when library requests to use the shader, use glUseProgramObjectARB Is this correct? I've read the OpenGL docs, but I'm still unsure about the glLinkProgramARB command, does it matter if I attach new shaders after linking? Also, naming convention is unclear to me. I have WinXP, so should I use the ARB behind every function? And some function names in the doc where slightly different, like 'object' and 'shader' were swapped... Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I have an Effects class. Which I can attach to either an object or the output of an FBO.

-> Create Effect Class
-> Load Shader Source (my class only supports one set of shader sources)
-> Create Program
-> Link Program

Then when I'm rendering an object I do

Effect->Enable

(Which does glUseProgram(EffectID); )

And then

Effect->Disable

(Which does glUseProgram(0); )

This way I can move my Effect's classes between Models/Objects and Camera outputs.

Share this post


Link to post
Share on other sites
Should be no need for the arb stuff nowadays. I dont think I've used it for ages. (I guess thats the problem with the internet... everythings so out of date.)

As for the nomenclature, I'll have a look at my notes if noone else knows off the top of their head.

Share this post


Link to post
Share on other sites
Thanks AndyEsser, but would it matter if you linked your program before adding new shaders?

Quote:
Original post by Simon_Roth
Should be no need for the arb stuff nowadays. I dont think I've used it for ages. (I guess thats the problem with the internet... everythings so out of date.)

As for the nomenclature, I'll have a look at my notes if noone else knows off the top of their head.


Thanks!

Share this post


Link to post
Share on other sites
By new Shaders, I'm assuming you mean Shader source. In which case yes it would matter. You have to load the Shader source first and then link.

http://www.opengl.org/sdk/docs/man/xhtml/glLinkProgram.xml

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyEsser
By new Shaders, I'm assuming you mean Shader source. In which case yes it would matter. You have to load the Shader source first and then link.

http://www.opengl.org/sdk/docs/man/xhtml/glLinkProgram.xml


Okay thanks, I just confirmed that with a test. You must link the program every time you attach a new shader to the program. I did read that site before, but it wasn't clear to me that I had to re-link whenever I attach a new shader.

And I also confirmed I can use the OpenGL 2.0 syntax, not the ARB syntax.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!