View Full Version : Question about values returned by glGetActiveAtomicCounterBufferiv

07-21-2015, 04:07 AM
glGetActiveAtomicCounterBufferiv has an argument GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_IND ICES

The spec says:

Consider the following set of active atomic counter uniform declarations in three different shader types in a program:

[in vertex]
layout(binding = 0, offset = 0) uniform atomic_uint batman;
layout(binding = 3, offset = 4) uniform atomic_uint robin;
[in geometry]
layout(binding = 0, offset = 4) uniform atomic_uint joker;
layout(binding = 6, offset = 124) uniform atomic_uint riddler;
[in fragment]
layout(binding = 7, offset = 0) uniform atomic_uint penguin;

In this example, there are four active atomic counter buffers. For the
purposes of the GetActiveAtomicCounterBufferiv query, these will be
assigned indices 0, 1, 2, 3.

But the thing I don't understand how these indices are useful or what they are used for.

It would be great if someone could shed some light on this for me.


Alfonse Reinheart
07-21-2015, 04:50 AM
The indices are used to identify a particular atomic counter buffer binding. So if you want to iterate through all of a program's atomic counter buffer bindings, you would query the number of atomic counter buffer indices (glGetProgram(GL_ACTIVE_ATOMIC_COUNTER_BUFFERS)), and then you then loop from 0 to that value, to query properties about the buffer binding with glGetActiveAtomicCounterBufferiv:

int numBufferIndices = 0;
glGetProgram(prog, GL_ACTIVE_ATOMIC_COUNTER_BUFFERS, &numBufferIndices);

for(int buffIx = 0; buffIx < numBufferIndices; ++buffIx)
int bindingIx = 0;
glGetAtomicCounterBufferiv(prog, buffIx, GL_ATOMIC_COUNTER_BUFFER_BINDING, &bindingIx);

07-21-2015, 05:55 AM
Right, Thanks! Its starting to make more sense now. Just to be clear what is the difference between the binding index ans the buffer index? I've read this before but keep getting confused.

Alfonse Reinheart
07-21-2015, 06:00 AM
The binding index is what you give to glBindBufferRange when binding a buffer to that location. The atomic counter buffer index (use the full name) is just an index into the array of active atomic counter buffers for a program. It's nothing more than a unique identifier for querying information about an atomic counter buffer binding location (the binding index, size to bind, etc).

07-22-2015, 04:44 AM
Thanks for taking the time to answer my questions. I have a much clearer picture of whats going on now :)