Program Objects Usage

Started by
4 comments, last by OrangyTang 17 years, 4 months ago
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!
Framerate is LIFE.
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.
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 fs1glAttachObjectARB( 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
Framerate is LIFE.
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
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.
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).

This topic is closed to new replies.

Advertisement