How can I get automatic unique atom counter snap points (no hardcoded snap =)?

Many articles describe the use of atomic counters by specifying a fixed anchor point:

//Shader:
layout(binding = 0, offset = 0) uniform atomic_uint myAtomicCounter;

//App code
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, myBufferHandle);

Here, the hard coding binding = 0point is indicated both in the shader code and in the application code. I think these articles do it this way because

Atomic meters are not assigned a place and may not be with the help of commands Uniform*. The bindings, offsets, and steps belonging to the atomic counters of the program object are invalid, and new ones are assigned after each successful re-reference. [shader_atomic_counters]

The above is fine until you want a more modular shader code. For example, I have two files with shader inclusion, each of which needs an atom counter, which I wrote as a plug-in code that does not know about the other. Clearly, I don’t want to specify hard-coded anchor points, and I would like the application to process it automatically. I don't care what anchor points they use, they just don't match.

The vertex shader attributes are similar. I can force the binding location to be bound at runtime ( glBindAttribLocation) before the shader binding, or alternatively OpenGL select them for me and then request the result ( glGetAttribLocation). I can also search all attributes ( glGetActiveAttrib).

, , ?

, , :

  • OpenGL . , OpenGL . , , ?
  • , . , glBindAttribLocation . ?
  • , , , #define. . .
+4
2

1: binding layout .

2: binding , OpenGL.

, - β„– 3.

+1

glGetActiveUniform. , , :

int atomicCounterIndex;
glGetActiveUniformsiv(programId, count, index, 
        GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX, &atomicCounterIndex);
glGetActiveAtomicCounterBufferiv(programId, atomicCounterIndex, 
        GL_ATOMIC_COUNTER_BUFFER_BINDING, &myBufferHandle)

OpenGL 4.2,

0

All Articles