I am using LWJGL, and I have a ShaderProgram class that abstracts a GPU shader. I have a bindUniform(int location, Object value) method that binds a uniform to the shader (by calling appropriate subroutines based on the type of value, like glUniformMatrix4fv).

I predict that I will be facing many scenarios where the value of a currently bound uniform will be the same for the input of bindUniform in subsequent calls.

I consider implementing a caching logic that, for every call to bindUniform() will try to look up if the value is cached (by performing by value comparisons), and only if it isn't, it will call the underlying opengl glUniform_(), then save the value to the cache.

I wonder:

  1. is this a minor micro optimization?
  2. is the an optimization at all, considering some comparisons between matrices will be 16 == operations?
  • 2
    \$\begingroup\$ This sounds like a question you could answer conclusively for your use case by profiling. Otherwise, you'll get answers for someone else's use case, which might entail a different workload or target hardware than yours. \$\endgroup\$
    – DMGregory
    Commented Mar 23 at 0:44


You must log in to answer this question.

Browse other questions tagged .