Monday, 16 June 2014

Uniform buffers in OpenGL

In OpenGL, the uniform buffer "Binding Index" is the equivalent of DX11's buffer slots. However, GL has many, many more indices available for than DX - about 35000.

You should therefore NEVER use the same index to bind two different blocks in the same frame - there's simply no need.

e.g


 static int lastBindingIndex=21;
 if(lastBindingIndex>=GL_MAX_UNIFORM_BUFFER_BINDINGS)
  lastBindingIndex=1;
 bindingIndex=lastBindingIndex;
 lastBindingIndex++;
 
 glUniformBlockBinding(program,indexInShader,bindingIndex);