Cost of updating uniforms in rendering ?

Hello. 

I'm writing a rendering routine, where uniform variables are frequently updated. 

My code is something like this : 

glUseProgram(id) ; // start shader 

for(...) 
{
   //Update uniforms
   glUniform... 
   glUniform...
   ...

   // Render a scene 
   renderScene() ; 

   glUseProgram(0) ; // end shader 
[/CODE]

My questions are : 

- Does this freqnent update of uniforms slow my rendering routine ? 
- What is the cost of updating a uniform  ?  


Thanks in advance. 

</div><div>glUseProgram(id) ; // start shader&nbsp;</div><div><br></div><div>for(...)&nbsp;</div><div>{</div><div>&nbsp; &nbsp;//Update uniforms</div><div>&nbsp; &nbsp;glUniform...&nbsp;</div><div>&nbsp; &nbsp;glUniform...</div><div>&nbsp; &nbsp;...</div><div><br></div><div>&nbsp; &nbsp;// Render a scene&nbsp;</div><div>&nbsp; &nbsp;renderScene() ;&nbsp;</div><div><br></div><div>&nbsp; &nbsp;glUseProgram(0) ; // end shader&nbsp;</div><div>


My questions are : 

- Does this freqnent update of uniforms slow my rendering routine ? 
- What is the cost of updating a uniform  ?  


Thanks in advance. 



I missed a '}' at the end of the code. 
The code should be like this : 

glUseProgram(id) ; // start shader 

for(...) 
{
   //Update uniforms
   glUniform... 
   glUniform...
   ...

   // Render a scene 
   renderScene() ; 
}

glUseProgram(0) ; // end shader 
[/CODE]

[CODE]
glUseProgram(id) ; // start shader 

for(...) 
{
   //Update uniforms
   glUniform... 
   glUniform...
   ...

   // Render a scene 
   renderScene() ; 
}

glUseProgram(0) ; // end shader 
[/CODE]

Hi WonwooLee.


The cost of updating uniforms is almost certainly minimal in comparison to other operations performed per-frame therefore I wouldn’t recommend spending time trying to ‘optimise’ this aspect unless you’ve profiled your application and determined that it is a bottleneck. However, this is very unlikely.

So, the operation may not bother my application.
That’s a good news.

Thanks !