12 #ifndef GlobeEngine_Buffer_h
13 #define GlobeEngine_Buffer_h
15 #include "OpenGL_Includes.h"
31 if (this->bufferHandle != 0) {
32 glBindBuffer(TYPE, this->bufferHandle);
33 if (!this->isImmutable) {
34 glBufferData(TYPE, 0,
nullptr, GL_STATIC_DRAW);
36 glDeleteBuffers( 1, &bufferHandle );
37 glBindBuffer(TYPE, 0);
44 if (this->bufferHandle == 0) {
45 glGenBuffers(1, &this->bufferHandle);
52 void copyToBufferCustom(GLsizeiptr _size,
const GLvoid* _data, GLenum _access = GL_STATIC_DRAW) {
54 glBufferData(TYPE, _size, _data, _access);
60 glBufferData(TYPE, _count *
sizeof(T), _data, _access);
63 void copyToBufferUInt(GLuint _size,
const GLvoid* _data, GLenum _access = GL_STATIC_DRAW) {
65 glBufferData(TYPE, _size *
sizeof(GLuint), _data, _access);
71 GLenum _usage = GL_STATIC_DRAW, GLbitfield _mode = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT) {
73 glBufferData(TYPE, _count *
sizeof(T),
nullptr, _usage);
74 return reinterpret_cast<T*
>(glMapBufferRange(TYPE, 0, _count *
sizeof(T), _mode));
77 #ifndef GENGINE_GL_BELOW_410
80 GLbitfield _storageMode = GL_MAP_WRITE_BIT,
81 GLbitfield _mode = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT) {
84 glBufferStorage(TYPE, _count *
sizeof(T),
nullptr, _storageMode);
85 this->isImmutable =
true;
87 return reinterpret_cast<T*
>(glMapBufferRange(TYPE, 0, _count *
sizeof(T), _mode));
97 glBindBuffer(TYPE, this->bufferHandle);
101 glBindBuffer(TYPE, 0);
105 return this->bufferHandle;
116 #ifndef GENGINE_GL_ES
122 #ifndef GENGINE_GL_BELOW_410
Buffer< GL_ELEMENT_ARRAY_BUFFER > IndexBuffer
Definition: Buffer.h:115
Buffer< GL_PIXEL_PACK_BUFFER > PixelPackBuffer
Definition: Buffer.h:119
void copyToBufferByData(GLuint _count, const T *_data, GLenum _access=GL_STATIC_DRAW)
Definition: Buffer.h:58
Buffer< GL_SHADER_STORAGE_BUFFER > ShaderStorageBuffer
Definition: Buffer.h:124
void clear()
Definition: Buffer.h:29
Buffer< GL_UNIFORM_BUFFER > UniformBuffer
Definition: Buffer.h:117
T * mapBufferStorage(GLuint _count, GLbitfield _storageMode=GL_MAP_WRITE_BIT, GLbitfield _mode=GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT)
Definition: Buffer.h:79
bool generateHandle()
Definition: Buffer.h:42
void copyToBufferUInt(GLuint _size, const GLvoid *_data, GLenum _access=GL_STATIC_DRAW)
Definition: Buffer.h:63
Buffer()
Definition: Buffer.h:21
Buffer< GL_DRAW_INDIRECT_BUFFER > DrawIndirectBuffer
Definition: Buffer.h:123
void bindBuffer()
Definition: Buffer.h:96
~Buffer()
Definition: Buffer.h:25
T * mapBuffer(GLuint _count, GLenum _usage=GL_STATIC_DRAW, GLbitfield _mode=GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT)
Definition: Buffer.h:70
Buffer< GL_ARRAY_BUFFER > VertexBuffer
Definition: Buffer.h:114
Definition: AvalancheTrainingSimulationEngine.h:28
Buffer< GL_PIXEL_UNPACK_BUFFER > PixelUnpackBuffer
Definition: Buffer.h:118
void unmapBuffer()
Definition: Buffer.h:91
void copyToBufferCustom(GLsizeiptr _size, const GLvoid *_data, GLenum _access=GL_STATIC_DRAW)
Definition: Buffer.h:52
void unbindBuffer()
Definition: Buffer.h:100
GLuint getBufferHandle(unsigned int _layerid)
Definition: Buffer.h:104