Atomic Counter/Layout Parameters: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
(Centralizing this data on atomic counter layouts.)
 
m (Alfonse moved page Atomic counter layout parameters to Atomic Counter/Layout Parameters without leaving a redirect: By convention, these kind of separate snippets should be under the main including page.)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
Atomic counters also have an optional {{code|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.
Atomic counters also have an optional {{code|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 {{code|offset}} parameter is not required. If it is not specified, then the {{code|offset}} will be 4 bytes larger than the offset previously used for that {{code|binding}}, starting at 0 if none were specified. For example:
The {{code|offset}} parameter is not required. If it is not specified, then the {{code|offset}} will be 4 bytes larger than the offset previously used for that {{code|binding}}, starting at 0 if none were previously specified. For example:


<source lang="glsl">
<source lang="glsl">

Latest revision as of 21:55, 2 May 2015

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).