Uniform buffer objects or constant registers in OpenGL ES 2.
When changing shaders, it may be desirable to have certain uniforms carry over without having to set/write to them each time. For example, when rendering elements in a scene, you may want to change shaders more than once; and yet it would be nice to only have to set the view projection matrix once and have the value carried over when switching shader programs. In direct 3d, I believe this is done through constant registers (i.e. postfixing uniforms with a c0, c1, c2, etc. semantic), and in the "old" opengl way of doing things, constants like gl_ModelViewMatrix were available in the shader. Uniform Buffer Objects seemed like an alternative to this, however it looks like they are not available in OpenGL ES 2.0? If so, is there any way to do what I have described above or is the only option to simply set uniforms like this each time you change shaders?
Re: Uniform buffer objects or constant registers in OpenGL E
I have been being have same head-ache.
All matrices such like bone matrix palette and parameters such as lighting and so on must be set every shader changes. This extra and waste process is going to be heavy load for CPU and GPU pretty much.
And, if you set shader constant registers in every shader changes, extra parameter management is going to be needed. For instance, write shader class and make it have all parameters that are needed to be set into GPU constant registers before render. This means, if you use a hounded shaders in the scene, then there must be a hounded times duplicated projection matrices and so on exist on the memory.
To avoid this, I made shaders into one shader using conditional branch a lot. However putting conditional branch in shader especially fragment shader is the worst thing that GPU programmer has to avoid as much as he can.
In DirectX9, constant registers can be easily shared by EffectPool object. Using EffectPool object and share bunch of matrices between shaders, my DirectX9 engine runs with out extra costs that I described above.
I am new to ES shader so I might be having wrong understanding about this, or there may be smart solution about this, any suggestion appreciated.