Month: August 2012

Writing to 3-components buffers using the image API in OpenGL

Posted on Updated on

As I’ve describe in detail in another blogpost, atomic counters used in conjunction with the image API and indirect draw buffers can be an excellent and highly performant alternative/replacement to the transformFeedback mechanism (oh wait, I still haven’t published that previous blogpost… and performant is not actually a real word).

Anyway, one place where this atomic counter + image API + indirect buffers approach becomes a little cumbersome, is its slightly less than elegant handling of 3-components buffer texture formats.

In the OpenGL 4.2 spec the list of supported buffer texture formats is listed in table 3.15, while the list of supported image unit formats is listed in table 3.21.  The takeaway from comparing these tables is that the supported image unit formats generally omit 3 components formats (other than the GL_R11F_G11F_B10F format).  So how to deal with this if you have a say a GL_RGB32F, or GL_RGB32UI internal format? Well, its actually pretty easy; just bind the proxy texture as the one component version of the internal format (GL_R32F, or GL_R32UI).

glBindImageTexture(0, buffer_proxy_tex, 0, GL_TRUE, 0, GL_WRITE_ONLY, GL_R32F);

Then in the shader put a 3-component stride on the atomic counter, then store each component with its own imageStore operation.

layout(binding = 0)         uniform atomic_uint atomicCount;
layout(rgb32f, binding = 0) uniform imageBuffer positionBuffer;

void main()
{
  //Some other code...

  int index = 3*int(atomicCounterIncrement(atomicCount));

  imageStore(positionBuffer, index+0, vec4(x));
  imageStore(positionBuffer, index+1, vec4(y));
  imageStore(positionBuffer, index+2, vec4(z));

  //Some more code...
}

And that actually works great, in my experience, replacing transformFeedback with this approach has been as fast or faster despite the multiple imageStore calls.

OpenGL 4.3 released

Posted on Updated on

OpenGL 4.3 has just been released and almost instantly G-Truc (Christophe Riccio) posted another excellent of his excellent OpenGL reviews.  Additionally Mike Bailey has already made available some slides on the new Compute shaders.  And as usual nvidia already has beta drivers available.

With over 20 new extensions this is a rather large update for a point release, and while I’m extremely grateful that people have had a chance preview these extensions and provide an alternative to the pain of reading through the extensions themselves (though I will probably do that anyway), I can’t help but wish that this sort of access wasn’t so exclusive.  I find the current method of dumping a bunch of new extensions out each SIGGRAPH and shouting “Surprise!” a bit jarring, and more tragically there is no mechanism to allow the OpenGL community at large to provide feedback (unless you are a member of Khronos, I guess).

If you look at the extensions I think they lend themselves perfectly to publication on some sort of official Wiki, revision history would be managed automatically, the OpenGL community could provide feedback on the discussion page, and Khronos members would have permission to make the actual edits to the extension.  I guess what I am saying, in particular regards to the publication of new extensions, is that I wish OpenGL were a little bit more “open.”

Extensions: