Atomic Counter/Layout Parameters

From OpenGL Wiki
Jump to navigation Jump to search

Atomic counters use two layout qualifier parameters. The binding defines which Buffer Object bound to the given index in the indexed target GL_ATOMIC_COUNTER_BUFFER​ will provide the storage for this atomic counter. The binding parameter is not optional.

Atomic counters also have an optional offset parameter. The offset is the byte offset from the beginning of the range bound to the target to the location where this variable gets its 32-bits of storage.

The offset parameter is not required. If it is not specified, then the offset will be 4 bytes larger than the offset previously used for that binding, starting at 0 if none were previously specified. For example:

layout(binding = 0, offset = 12) uniform atomic_uint one;
layout(binding = 0) uniform atomic_uint two;
layout(binding = 0, offset = 4) uniform atomic_uint three;

layout(binding = 1) uniform atomic_uint four;
layout(binding = 1) uniform atomic_uint five;
layout(binding = 1, offset = 20) uniform atomic_uint six;
layout(binding = 0) uniform atomic_uint seven;

The offsets for these are as follows:

  • one: 12
  • two: 16 (12 + 4)
  • three: 4 (specified)
  • four: 0 (unused bindings offsets always start with a default of 0).
  • five: 4
  • six: 20
  • seven: 8 (the last value used for binding 0 was 4, so this one gets 8).