Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: uniform sizes

  1. #1
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117

    uniform sizes

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

  2. #2
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    325
    Hi,


    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:

    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.

    Pro:
    * 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.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Thanks for the comments

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •