1#ifndef GLK_ATOMIC_COUNTERS_HPP
2#define GLK_ATOMIC_COUNTERS_HPP
12 this->num_counters = num_counters;
14 glGenBuffers(1, &atomic_buffer);
15 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomic_buffer);
16 glBufferData(GL_ATOMIC_COUNTER_BUFFER,
sizeof(GLuint) * num_counters,
nullptr, usage);
17 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
20 glDeleteBuffers(1, &atomic_buffer);
23 void reset(GLuint* values =
nullptr) {
24 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomic_buffer);
27 glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0,
sizeof(GLuint) * num_counters, values);
29 std::vector<GLuint> v(num_counters, 0);
30 glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0,
sizeof(GLuint) * num_counters, v.data());
33 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
37 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomic_buffer);
40 glGetBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0,
sizeof(GLuint), &value);
42 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
48 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomic_buffer);
50 std::vector<GLuint> values(num_counters, 0);
51 glGetBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0,
sizeof(GLuint) * num_counters, values.data());
53 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
58 void bind(GLuint index = 0)
const {
59 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, index, atomic_buffer);
63 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, 0);
Definition atomic_counters.hpp:9
GLuint get_value() const
Definition atomic_counters.hpp:36
void unbind() const
Definition atomic_counters.hpp:62
void bind(GLuint index=0) const
Definition atomic_counters.hpp:58
std::vector< GLuint > get_values() const
Definition atomic_counters.hpp:47
AtomicCounters(int num_counters, GLenum usage=GL_DYNAMIC_COPY)
Definition atomic_counters.hpp:11
~AtomicCounters()
Definition atomic_counters.hpp:19
void reset(GLuint *values=nullptr)
Definition atomic_counters.hpp:23
Definition async_buffer_copy.hpp:6