Sharing uniforms across shader programs
Hi All,
I've been porting my openGL ES 1.1 game over to 2.0. I've got a number of vertex shader programs now that all need to take a uniform for the model view projection matrix.
Can I give this uniform the same name in each shader program?
If I do give the uniform the same name in the vertex shader programs, when I call glGetUniformLocation will I get the same uniform location for each program or will I get a different location for each one?
Assuming I get the same location, when I set the value for the mvp uniform do I need to set it for each program I use or can I set it at the start of my rendering and will all the programs get the same value?
Sorry if these are all obvious questions - but I've looked through the gold book and it didn't really seem to say.
I've been porting my openGL ES 1.1 game over to 2.0. I've got a number of vertex shader programs now that all need to take a uniform for the model view projection matrix.
Can I give this uniform the same name in each shader program?
If I do give the uniform the same name in the vertex shader programs, when I call glGetUniformLocation will I get the same uniform location for each program or will I get a different location for each one?
Assuming I get the same location, when I set the value for the mvp uniform do I need to set it for each program I use or can I set it at the start of my rendering and will all the programs get the same value?
Sorry if these are all obvious questions - but I've looked through the gold book and it didn't really seem to say.
(Sep 3, 2010 08:39 AM)iamflimflam1 Wrote: Can I give this uniform the same name in each shader programYes.
Quote:If I do give the uniform the same name in the vertex shader programs, when I call glGetUniformLocation will I get the same uniform location for each program or will I get a different location for each one?Undefined. The compiler can assign any location it wants. Don't depend on it being the same.
Quote:Assuming I get the same location, when I set the value for the mvp uniform do I need to set it for each program I use or can I set it at the start of my rendering and will all the programs get the same value?You need to set it for each program.
Thanks arekkusu,, so uniforms are pretty much tied to the program.
I seem to remember reading somewhere that if you set a uniform on a program, change programs, then switch back to the original program the uniform's value is still valid - is that definitely the case?
Thanks
Chris.
I seem to remember reading somewhere that if you set a uniform on a program, change programs, then switch back to the original program the uniform's value is still valid - is that definitely the case?
Thanks
Chris.
Yes. Uniforms are program state.
Uniforms are initialized to zero when you (re)link.
Uniforms are initialized to zero when you (re)link.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| (just sharing) C++ to Objective-C callbacks | godexsoft | 0 | 2,213 |
Apr 11, 2012 06:37 PM Last Post: godexsoft |
|
| sharing files between apps | captainfreedom | 3 | 2,399 |
Apr 19, 2010 01:11 PM Last Post: captainfreedom |
|
| Long shader compile times on iPhone 3G S | conal | 9 | 5,559 |
Nov 20, 2009 03:54 AM Last Post: OneSadCookie |
|
| Hi everyOne ,3D and other knowledge sharing | priyankranka | 2 | 2,344 |
Feb 1, 2009 10:41 PM Last Post: priyankranka |
|

