Game Development

opengl – Prons 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) that binds a uniform to the shader (by calling applicable subroutines based mostly on the kind of worth, like glUniformMatrix4fv).

I predict that I will likely be dealing with many eventualities the place the worth of a at present sure 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 can 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