23 #ifndef __BUFFEROBJECT__ 24 #define __BUFFEROBJECT__ 28 #include <Eigen/Dense> 79 BufferObject (
int s, GLenum buftype) : buffer_id(0), buffer_type(buftype), size(s)
104 glBindBuffer(buffer_type, buffer_id);
113 binding_point = index;
114 glBindBufferBase(buffer_type, binding_point, buffer_id);
121 glBindBufferBase(buffer_type, binding_point, 0);
130 glBindBuffer(buffer_type, 0);
143 buffer_data = (T*)glMapBufferRange(buffer_type,
146 GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT
150 memset(buffer_data, 0,
sizeof(T) * size );
152 glUnmapBuffer(buffer_type);
165 T *values =
new T[
size];
169 buffer_data = (T*)glMapBufferRange(buffer_type,
172 GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT
176 for (
int i = 0; i <
size; ++i) {
177 values[i] = buffer_data[i];
179 *return_values = values;
182 glUnmapBuffer(buffer_type);
192 for (
int i = 0; i <
size; ++i) {
193 cout << i <<
" : " << values[i] << endl;
BufferObject(int s, GLenum buftype)
Definition: bufferobject.hpp:79
int binding_point
Binding point for this buffer.
Definition: bufferobject.hpp:70
An Atomic Buffer object (inherited from BufferObject).
Definition: bufferobject.hpp:214
The buffer object of thype ShaderStorageBuffer with Float elements.
Definition: bufferobject.hpp:228
Definition: bufferobject.hpp:34
virtual ~BufferObject(void)
Default Destructor.
Definition: bufferobject.hpp:88
ShaderStorageBufferInt(int s)
Integer Shader Storage Buffer constructor.
Definition: bufferobject.hpp:250
void unbindBase(void)
Unbinds buffer from binding point.
Definition: bufferobject.hpp:120
virtual void clear(void)
Clears all values (sets to zero).
Definition: bufferobject.hpp:136
virtual void readBuffer(T **return_values)
Reads a GPU buffer and stores it in a CPU array.
Definition: bufferobject.hpp:163
virtual void unbind(void)
Unbinds the buffer object.
Definition: bufferobject.hpp:128
The buffer object of thype ShaderStorageBuffer with Integer elements.
Definition: bufferobject.hpp:242
virtual void bind(void)
Binds buffer object.
Definition: bufferobject.hpp:102
ShaderStorageBufferFloat(int s)
Float Shader Storage Buffer constructor.
Definition: bufferobject.hpp:236
void bindBase(int index)
Binds buffer to a specific binding point.
Definition: bufferobject.hpp:111
GLuint buffer_id
The handle of the Buffer Object.
Definition: bufferobject.hpp:61
GLuint getBufferID(void)
Returns The id of the buffer (handle).
Definition: bufferobject.hpp:95
virtual void create(void)
Creates the Buffer Object.
Definition: bufferobject.hpp:50
GLenum buffer_type
Type of buffer.
Definition: bufferobject.hpp:64
int getSize(void)
Returns the size of the buffer, number of elements.
Definition: bufferobject.hpp:202
A buffer object (i.e. ShaderStorageBuffer).
Definition: bufferobject.hpp:43
AtomicBuffer(int s)
Atomic Buffer constructor.
Definition: bufferobject.hpp:222
void printBuffer(void)
Prints the content of a GPU. Usually used for debugging.
Definition: bufferobject.hpp:189
int size
Buffer dimension (number of elements).
Definition: bufferobject.hpp:67