Changing Uniform Variables for a Single Shader
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:
glUseProgram(...)
glUniform(...)
glDrawArrays(...)
glUniform(...)
glDrawArrays(...)
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.
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:
glUseProgram(...)
glUniform(...)
glDrawArrays(...)
glUniform(...)
glDrawArrays(...)
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.
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.
(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.
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.
I have a feeling you'll kick yourself when you see the problem.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
ios/mac shader - shared glsl source | OptimisticMonkey | 2 | 7,261 |
Jun 17, 2011 08:59 AM Last Post: OptimisticMonkey |
|
passing values from vertex to fragment shader | Sumaleth | 5 | 16,725 |
Feb 18, 2011 01:54 AM Last Post: Holmes |
|
Changing Pixel Values using CG | LIPH700 | 1 | 6,034 |
Nov 25, 2010 03:17 PM Last Post: SethWillits |
|
Texture mapping single 3D object with one draw call | jeonghyunhan | 1 | 4,485 |
Jul 13, 2009 06:05 AM Last Post: ThemsAllTook |
|
Vertex shader particle billboarding question | TomorrowPlusX | 3 | 7,856 |
Sep 15, 2008 06:46 AM Last Post: TomorrowPlusX |