Changing Uniform Variables for a Single Shader - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Changing Uniform Variables for a Single Shader (/thread-7853.html)
Changing Uniform Variables for a Single Shader - reapz - Jul 13, 2010 05:23 PM
I'm currently trying to use a single shader to render a bunch of separate objects where each object has their own orientation in the world. I plan on moving to batching soon but some objects will still be separate.
From what I understand the glUseProgram call has quite a lot of OpenGL driver overhead so it would make sense to set a program and reuse it by changing variables for each object I render. The problem is when I do this they seem to all render to the same position on the screen.
What I am trying to do is the following:
The impression I get is that you can only set uniform variables once? From my research I have read that this should be working but please correct me if I'm wrong. I know atleast the shader and the draw code is correct, because when I add the glUseProgram line in between each glDrawArrays call it renders correctly.
RE: Changing Uniform Variables for a Single Shader - dazza - Jul 14, 2010 01:21 PM
You're correct, you should be able to set uniforms multiple times with draw calls. You're right to want to minimise calls to glUseProgram as it's expensive.
RE: Changing Uniform Variables for a Single Shader - reapz - Jul 14, 2010 04:35 PM
(Jul 14, 2010 01:21 PM)dazza Wrote: You're correct, you should be able to set uniforms multiple times with draw calls. You're right to want to minimise calls to glUseProgram as it's expensive.
Yes I realise it is quite an expensive call which is why I'd like to only call it once but when I do it is like the transform matrixes don't get updated in between the drawing of entities... Even though the only thing that has changed is me calling glUseProgram once at the start of a group rather than in between.
I have no idea why this should be happening, I wonder is there anything I should be looking at? Because I was under the same impression, that I should be able to change the variables.
RE: Changing Uniform Variables for a Single Shader - dazza - Jul 15, 2010 01:29 AM
Hmm, given what you are doing should work it's probably something simple. Check that your uniform variable is correct and that you are indeed passing a different matrix for each model.
I have a feeling you'll kick yourself when you see the problem.