PDA

View Full Version : Multiple shaders single VAO/VBO



denom
07-28-2011, 06:21 PM
What is the best practice when you have mutliple similar objects in a scene and each one requires a seperate shader?
For instance, I can create a seperate VBO for every polygon mesh and also a seperate ArrayObject and then bind that particular ArrayObject and shader for each single mesh to draw a certain object. However, I feel like this is not so optimal.
Or if I created one large vbo for all the polygon meshes is there anyway I could use a different shader for every mesh?
Any suggestions?

zeoverlord
07-29-2011, 04:18 AM
well if you sort your objects depending on the shader it uses then there shouldn't be a problem putting it all in one big VBO/VAO.
Though you should try and create shaders that can be used for as many objects as possible

aqnuep
07-29-2011, 04:47 AM
Please note that you don't have to switch VAOs each time you switch shaders. If you store multiple meshes in a single VAO+VBO set then issue different Draw* commands to draw the different objects and switch the shader between the Draw* commands.

denom
07-29-2011, 10:03 AM
Though you should try and create shaders that can be used for as many objects as possible
Is it a bad idea (or even possible) to somehow have one more general purpose shader that you can pass a "flag" attribute and it decides which function to perform inside the shader?


Please note that you don't have to switch VAOs each time you switch shaders. If you store multiple meshes in a single VAO+VBO set then issue different Draw* commands to draw the different objects and switch the shader between the Draw* commands.
Are you referring to issuing a draw command like DrawRange* and keeping track of the count as zeoverlord suggested the ordering of VBO contents?

Is it better to just change the default VAO attributes upon drawing each VBO? Or is there any other most used practices addressing this issue?

zeoverlord
07-30-2011, 03:53 AM
Is it a bad idea (or even possible) to somehow have one more general purpose shader that you can pass a "flag" attribute and it decides which function to perform inside the shader?
Well it depends on the shaders themselves, if they are really similar then yes its better to condense it into one, like if the only difference is that they have a different amount of specular power it is definitely better to make that modifiable trough a uniform variable or a texture map.
But just have a super shader that sort of switches between a bunch of shaders might not be that optimal.


Are you referring to issuing a draw command like DrawRange* and keeping track of the count as zeoverlord suggested the ordering of VBO contents?
yes

denom
07-30-2011, 08:19 AM
Thanks for your helps guys!