12 #ifndef GlobeEngine_BufferArray_h
13 #define GlobeEngine_BufferArray_h
15 #include "OpenGL_Includes.h"
22 this->bufferHandles = NULL;
28 for (
int i = 0; i < bufferHandleCount; i++){
30 glBufferData(TYPE, 0, NULL, GL_STATIC_DRAW);
37 if (this->bufferHandleCount != _count) {
39 this->bufferHandles =
new GLuint[_count];
40 this->bufferHandleCount = _count;
42 glGenBuffers(_count, this->bufferHandles);
46 void copyToBuffer(
unsigned int _layerid, GLsizeiptr _size,
const GLvoid* _data, GLenum _access = GL_STATIC_DRAW) {
48 glBufferData(TYPE, _size, _data, _access);
55 GLenum _usage = GL_STATIC_DRAW, GLbitfield _mode = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT) {
57 glBufferData(TYPE, _size *
sizeof(T), NULL, _usage);
58 return reinterpret_cast<T*
>(glMapBufferRange(TYPE, 0, _size *
sizeof(T), _mode));
67 for (
int i = 0; i < bufferHandleCount; i++){
75 glBindBuffer(TYPE, this->bufferHandles[_layerid]);
79 glBindBuffer(TYPE, 0);
83 if (_layerid < bufferHandleCount){
84 return this->bufferHandles[_layerid];
87 return std::numeric_limits< unsigned int >::max();
94 glVertexAttribDivisor(_attributeIndex, _divisor);
99 if (bufferHandles != NULL) {
100 glDeleteBuffers(bufferHandleCount, bufferHandles);
101 delete[] bufferHandles;
103 bufferHandles = NULL;
104 bufferHandleCount = 0;
107 GLuint* bufferHandles;
108 GLuint bufferHandleCount;
112 #ifndef GENGINE_GL_ES
118 #ifndef GENGINE_GL_BELOW_410
void copyToBuffer(unsigned int _layerid, GLsizeiptr _size, const GLvoid *_data, GLenum _access=GL_STATIC_DRAW)
Definition: BufferArray.h:46
BufferArray< GL_PIXEL_UNPACK_BUFFER > PixelUnpackBufferArray
Definition: BufferArray.h:114
BufferArray< GL_SHADER_STORAGE_BUFFER > ShaderStorageBufferArray
Definition: BufferArray.h:119
void setAttributeDivisor(GLuint _attributeIndex, GLuint _divisor)
Definition: BufferArray.h:93
void bindBuffer(unsigned int _layerid)
Definition: BufferArray.h:74
T * mapBuffer(unsigned int _layerid, GLuint _size, GLenum _usage=GL_STATIC_DRAW, GLbitfield _mode=GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT)
Definition: BufferArray.h:54
~BufferArray()
Definition: BufferArray.h:26
void generateHandles(unsigned int _count)
Definition: BufferArray.h:36
BufferArray< GL_PIXEL_PACK_BUFFER > PixelPackBufferArray
Definition: BufferArray.h:115
BufferArray< GL_ARRAY_BUFFER > VertexBufferArray
Definition: BufferArray.h:111
void unmapBuffer(unsigned int _layerid)
Definition: BufferArray.h:61
void unbindBuffer()
Definition: BufferArray.h:78
Definition: BufferArray.h:18
void unmapAllBuffers()
Definition: BufferArray.h:66
GLuint getBufferHandle(unsigned int _layerid)
Definition: BufferArray.h:82
Definition: AvalancheTrainingSimulationEngine.h:28
BufferArray()
Definition: BufferArray.h:21
BufferArray< GL_UNIFORM_BUFFER > UniformBufferArray
Definition: BufferArray.h:113