Game Development

opengl – Professionals and cons of caching uniforms

I’m utilizing LWJGL, and I’ve a ShaderProgram class that abstracts a GPU shader. I’ve a bindUniform(int location, Object worth) technique that binds a uniform to the shader (by calling acceptable subroutines primarily based on the kind of worth, like glUniformMatrix4fv).

I predict that I will likely be going through many situations the place the worth of a at the moment certain uniform would be the similar for the enter of bindUniform in subsequent calls.

I take into account implementing a caching logic that, for each name to bindUniform() will attempt to lookup if the worth is cached (by performing by worth comparisons), and provided that it is not, it’s going to name the underlying opengl glUniform_(), then save the worth to the cache.

I’m wondering:

  1. is that this a minor micro optimization?
  2. is the an optimization in any respect, contemplating some comparisons between matrices will likely be 16 == operations?

About the author

Theme control panel

Leave a Comment