gtsam_points
Loading...
Searching...
No Matches
atomic_counters.hpp
Go to the documentation of this file.
1#ifndef GLK_ATOMIC_COUNTERS_HPP
2#define GLK_ATOMIC_COUNTERS_HPP
3
4#include <vector>
5#include <GL/gl3w.h>
6
7namespace glk {
8
10public:
11 AtomicCounters(int num_counters, GLenum usage = GL_DYNAMIC_COPY) {
12 this->num_counters = num_counters;
13
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);
18 }
20 glDeleteBuffers(1, &atomic_buffer);
21 }
22
23 void reset(GLuint* values = nullptr) {
24 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomic_buffer);
25
26 if(values) {
27 glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(GLuint) * num_counters, values);
28 } else {
29 std::vector<GLuint> v(num_counters, 0);
30 glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(GLuint) * num_counters, v.data());
31 }
32
33 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
34 }
35
36 GLuint get_value() const {
37 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomic_buffer);
38
39 GLuint value;
40 glGetBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(GLuint), &value);
41
42 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
43
44 return value;
45 }
46
47 std::vector<GLuint> get_values() const {
48 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomic_buffer);
49
50 std::vector<GLuint> values(num_counters, 0);
51 glGetBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(GLuint) * num_counters, values.data());
52
53 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
54
55 return values;
56 }
57
58 void bind(GLuint index = 0) const {
59 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, index, atomic_buffer);
60 }
61
62 void unbind() const {
63 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, 0);
64 }
65
66private:
67 int num_counters;
68 GLuint atomic_buffer;
69};
70} // namespace glk
71
72#endif
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