uniform sizes

Can anyone tell me if it better to use a vec4 to hold 4 independent variables rather that defining 4 floats?


using 4 floats for 4 independent variables is more intuitive for the developer, you shouldn’t make his life (probably your own) more complicated without a good reason.

That being said let’s look at the pros & cons:


  • You need to supply all 4 values even if you only want to change one, so you need to cache all 4.
  • The default uniform block is most likely just a uniform block handled by the driver in (nearly) every GL implementation your code will run on, if it works similar to user defined uniform blocks there is the chance that the same padding rules apply and a vec4 uses up more memory than 4 floats internally (due to padding). On the other hand, why would you care? It’s not a performance problem.


  • If you change all values often, you only need one glUniform4f call instead of 4 glUniform1f calls. On the other hand, if a large number of glUniform calls is your problem, why not replace the uniforms with a uniform block and upload all values for a frame in one go?

I don’t see strong advantages of one vec4 over 4 floats, so do what makes your life easier, consider uniform blocks if a high number of glUniform calls is your problem.

Thanks for the comments

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.