Imagination PowerVR SDK Blog

Cost of updating uniforms in rendering ?


#1
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. 




#2
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]


#3

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.

#4

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

Thanks !