Jump to content
  • Advertisement
Sign in to follow this  
Pure

OpenGL Program Objects Usage

This topic is 4236 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 all, I used to code with OpenGL a while back, but never touched shaders. I am trying to get myself up to date with it again and have a few questions regarding program objects. a) Does a PO require both pixel and vertex shaders to be set? b) When you bind a null PO, do you revert to FFP ? c) What is the most optimal way to utilise program objects? I thought I would create a single PO and assign my multiple shaders to it before drawing. I am not sure if this would be best solution so please let me know what you think. Something tells me the assigning and linking when drawing objects that use different shaders hurts performance. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
a) no, you can use both or one of the other and the driver will supply you with the one you dont' create. That said, myself and others have noticed pretty large performance loss when you don't supply both shaders, this could be a driver thing and it might be fixed however it's probably best just to provide both and be done with it

b) yes

c) GLSL PO and shaders should be thought of the same way as textures; setup at the beginning. Compiling and linking a shader is very heavy work, so do it at start up.

Share this post


Link to post
Share on other sites
Thank you for the reply phantom.

With regards to my third question. I understand the compiling of shaders would not be suitable every frame, but what about linking while drawing? I am not sure if this is possible but as an example:


glAttachObjectARB( program_object, vertex_shader0 );
glAttachObjectARB( program_object, fragment_shader1 );
glLinkProgramARB( program_object);

glUseProgramObjectARB( program_object );

// Now render all objects that use vs0 and fs1

glAttachObjectARB( program_object, vertex_shader0 );
glAttachObjectARB( program_object, fragment_shader4 );
glLinkProgramARB( program_object);

glUseProgramObjectARB( program_object );

// Now render all objects that use vs0 and fs4




Could this work and would it be wise to do it like this?

The only other choice ( as I can see ) is having a PO for every shader configuration.

i.e FS0 and VS0 has PO0, FS1 and VS0 has PO1, FS0 and VS1 has PO2, etc...

where FS = fragment shader, VS = vertex shader, PO = program object

Thanks

Share this post


Link to post
Share on other sites
linking is also out as it's a heavy operation.
For starters you'd have to deattach the shaders you weren't going to use (FS in this case) and attach a new one. When linking the driver has to perform various validations and match up slots and assign slots for data; this is all as I say heavy work and doing it mid-frame would kill your frame rate.

So, yes, the best way is to produce your combinations up front

Share this post


Link to post
Share on other sites
As phantom pointed out, neither compiling nor linking shaders in a program should be done in real-time. Also, I'd like to point out that you can reuse your shaders and link them to several programs (and detach/destroy them thereafter). I remember having some problems with (old) ATI cards in the past, but I can't remember if it had anything to do with this. It did have something to do with not following the specs though, so be careful.

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
a) no, you can use both or one of the other and the driver will supply you with the one you dont' create. That said, myself and others have noticed pretty large performance loss when you don't supply both shaders, this could be a driver thing and it might be fixed however it's probably best just to provide both and be done with it

Interesting, I've not heard about that before. I usually just use a fragment shader and leave the vertex shader as the fixed function.

I'll have to try supplying a simple vertex shader and see if that makes any effect on my framerate (it could explain the surprisingly poor performance I got a while ago).

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!