globjects
1.1.0.2f0c753c8647
Strict OpenGL objects wrapper.
|
Wrapper for OpenGL buffer objects. More...
#include <globjects/include/globjects/Buffer.h>
Public Types | |
enum | BindlessImplementation { BindlessImplementation::DirectStateAccessARB, BindlessImplementation::DirectStateAccessEXT, BindlessImplementation::Legacy } |
Public Types inherited from globjects::Object | |
enum | NameImplementation { NameImplementation::DebugKHR, NameImplementation::Legacy } |
Public Member Functions | |
Buffer () | |
Creates a new OpenGL buffer object. More... | |
virtual void | accept (ObjectVisitor &visitor) override |
Implements the visitor pattern. More... | |
void | bind (gl::GLenum target) const |
Binds the buffer to target. More... | |
void | setData (gl::GLsizeiptr size, const gl::GLvoid *data, gl::GLenum usage) |
Wraps the OpenGL function glBufferData. Creates video memory for the buffer. More... | |
template<typename T > | |
void | setData (const T &data, gl::GLenum usage) |
Convenience method to simplify passing of data in form of a POD struct. More... | |
template<typename T > | |
void | setData (const std::vector< T > &data, gl::GLenum usage) |
Convenience method to simplify passing of data in form of an std::vector. More... | |
template<typename T , std::size_t Count> | |
void | setData (const std::array< T, Count > &data, gl::GLenum usage) |
Convenience method to simplify passing of data in form of an std::array. More... | |
void | setSubData (gl::GLintptr offset, gl::GLsizeiptr size, const gl::GLvoid *data=nullptr) |
Wraps the OpenGL function glBufferSubData. Writes data only to a defined area of the memory. More... | |
template<typename T > | |
void | setSubData (const T &data, gl::GLintptr offset=0) |
Convenience method to simplify passing of data in form of a POD struct. More... | |
template<typename T > | |
void | setSubData (const std::vector< T > &data, gl::GLintptr offset=0) |
Convenience method to simplify passing of data in form of an std::vector. More... | |
template<typename T , std::size_t Count> | |
void | setSubData (const std::array< T, Count > &data, gl::GLintptr offset=0) |
Convenience method to simplify passing of data in form of an std::array. More... | |
void | setStorage (gl::GLsizeiptr size, const gl::GLvoid *data, gl::BufferStorageMask flags) |
Wraps the OpenGL function glBufferStorage. More... | |
template<typename T > | |
void | setStorage (const T &data, gl::BufferStorageMask flags) |
Convenience method to simplify passing of data in form of a POD struct. More... | |
template<typename T > | |
void | setStorage (const std::vector< T > &data, gl::BufferStorageMask flags) |
Convenience method to simplify passing of data in form of an std::vector. More... | |
template<typename T , std::size_t Count> | |
void | setStorage (const std::array< T, Count > &data, gl::BufferStorageMask flags) |
Convenience method to simplify passing of data in form of an std::array. More... | |
gl::GLint | getParameter (gl::GLenum pname) const |
Wraps the OpenGL function gl::glGetBufferParameter. Queries OpenGL for internal state of the buffer. More... | |
gl::GLint64 | getParameter64 (gl::GLenum pname) const |
Wraps the OpenGL function gl::glGetBufferParameter for 64 bit data types. Queries OpenGL for internal state of the buffer. More... | |
const void * | map () const |
Maps the Buffer's memory read only. More... | |
void * | map (gl::GLenum access) |
Maps the Buffer's memory using the internal target. More... | |
void * | mapRange (gl::GLintptr offset, gl::GLsizeiptr length, gl::BufferAccessMask access) |
Wraps the OpenGL function glMapBufferRange. Maps only a range of the buffers memory. More... | |
bool | unmap () const |
Wraps the OpenGL function glUnmapBuffer. More... | |
void | flushMappedRange (gl::GLintptr offset, gl::GLsizeiptr length) |
Wraps the OpenGL function glFlushMappedBufferRange. More... | |
void | bindBase (gl::GLenum target, gl::GLuint index) const |
Wraps the OpenGL function gl::glBindBufferBase. More... | |
void | bindRange (gl::GLenum target, gl::GLuint index, gl::GLintptr offset, gl::GLsizeiptr size) const |
Wraps the OpenGL function gl::glBindBufferRange. More... | |
void | copySubData (Buffer *buffer, gl::GLintptr readOffset, gl::GLintptr writeOffset, gl::GLsizeiptr size) const |
Wraps the OpenGL function glCopyBufferSubData. More... | |
void | copySubData (Buffer *buffer, gl::GLsizeiptr size) const |
Convenience method. Both readOffset and writeOffset are 0. More... | |
void | copyData (Buffer *buffer, gl::GLsizeiptr size, gl::GLenum usage) const |
Creates new uninitialized memory to fit size (using usage), then copies the contents of buffer to this buffer's new memory. More... | |
void | clearData (gl::GLenum internalformat, gl::GLenum format, gl::GLenum type, const void *data=nullptr) |
Wraps the OpenGL function gl::glClearBufferData. Clears the Buffer's data by filling it with the value in data, which has to be long enough to match format. More... | |
void | clearSubData (gl::GLenum internalformat, gl::GLintptr offset, gl::GLsizeiptr size, gl::GLenum format, gl::GLenum type, const void *data=nullptr) |
Wraps the OpenGL function gl::glClearBufferSubData. More... | |
const void * | getPointer () const |
void * | getPointer () |
const void * | getPointer (gl::GLenum pname) const |
void * | getPointer (gl::GLenum pname) |
void | getSubData (gl::GLintptr offset, gl::GLsizeiptr size, void *data) const |
Wraps the OpenGL function glGetBufferSubData. Retrieves the contents of the buffers data store. More... | |
template<typename T > | |
std::vector< T > | getSubData (gl::GLsizeiptr count, gl::GLintptr offset=0) const |
Convenience method to simplify getting of data in form of an std::vector. More... | |
template<typename T , std::size_t Count> | |
std::array< T, Count > | getSubData (gl::GLintptr offset=0) const |
Convenience method to simplify getting of data in form of an std::array. More... | |
void | invalidateData () const |
Wraps the OpenGL function gl::glInvalidateBufferData. More... | |
void | invalidateSubData (gl::GLintptr offset, gl::GLsizeiptr length) const |
Wraps the OpenGL function gl::glInvalidateBufferSubData. More... | |
virtual gl::GLenum | objectType () const override |
Public Member Functions inherited from globjects::Object | |
gl::GLuint | id () const |
std::string | name () const |
void | setName (const std::string &name) |
bool | hasName () const |
bool | isDefault () const |
void | detach () |
Public Member Functions inherited from globjects::Referenced | |
Referenced () | |
void | ref () const |
void | unref () const |
int | refCounter () const |
Public Member Functions inherited from globjects::HeapOnly | |
HeapOnly () | |
void | destroy () const |
Static Public Member Functions | |
static void | hintBindlessImplementation (BindlessImplementation impl) |
static void | setWorkingTarget (gl::GLenum target) |
Sets the target that is used for binding buffers to call state changing OpenGL functions. This has an effect only when GL_EXT_direct_state_access is not available. Usually this target never has to be changed unless you want to ensure that a certain binding target will not be used. More... | |
static Buffer * | fromId (gl::GLuint id) |
Creates a buffer with an external id. This object does not own the associated OpenGL object and will not delete it in the destructor. More... | |
static void | unbind (gl::GLenum target) |
Unbinds a specific target, i.e. binds a 0 id to the target. More... | |
static void | unbind (gl::GLenum target, gl::GLuint index) |
Unbinds the buffer bound to the target and index. More... | |
Static Public Member Functions inherited from globjects::Object | |
static void | hintNameImplementation (NameImplementation impl) |
Protected Member Functions | |
Buffer (IDResource *resource) | |
Creates a buffer with an external id. More... | |
virtual | ~Buffer () |
Protected Member Functions inherited from globjects::Object | |
Object (IDResource *resource) | |
virtual | ~Object () |
Protected Member Functions inherited from globjects::Referenced | |
virtual | ~Referenced () |
Protected Member Functions inherited from globjects::HeapOnly | |
virtual | ~HeapOnly () |
Additional Inherited Members | |
Protected Attributes inherited from globjects::Object | |
IDResource * | m_resource |
void * | m_objectLabelState |
Wrapper for OpenGL buffer objects.
The Buffer class encapsulates OpenGL buffer objects. Each buffer can be bound and unbound (bind(), unbind()). To fill the buffer use setData(). To access the data of a buffer directly, you can use map(). Buffers can be used for OpenGL draw calls, which are encapsulated within drawArrays() and drawElements() on VertexArrayObject, but that doesn't guarantee that OpenGL will use this buffer for drawing. The current bound VertexArrayObject and Program will specify the render pipeline and data.
|
strong |
globjects::Buffer::Buffer | ( | ) |
Creates a new OpenGL buffer object.
|
protected |
Creates a buffer with an external id.
id | an external OpenGL buffer id |
|
protectedvirtual |
Automatically deletes the associated OpenGL buffer unless the object was created with an external id.
|
static |
|
static |
Sets the target that is used for binding buffers to call state changing OpenGL functions. This has an effect only when GL_EXT_direct_state_access is not available. Usually this target never has to be changed unless you want to ensure that a certain binding target will not be used.
target |
|
static |
Creates a buffer with an external id. This object does not own the associated OpenGL object and will not delete it in the destructor.
id | an external OpenGL buffer id |
|
overridevirtual |
Implements the visitor pattern.
visitor | The visitor on which visitBuffer will be called. |
Implements globjects::Object.
void globjects::Buffer::bind | ( | gl::GLenum | target | ) | const |
Binds the buffer to target.
target | the target for binding |
|
static |
Unbinds a specific target, i.e. binds a 0 id to the target.
target | the target for unbinding |
|
static |
Unbinds the buffer bound to the target and index.
target | the target for unbinding |
index | the index for unbinding |
void globjects::Buffer::setData | ( | gl::GLsizeiptr | size, |
const gl::GLvoid * | data, | ||
gl::GLenum | usage | ||
) |
Wraps the OpenGL function glBufferData. Creates video memory for the buffer.
size | size of the new memory in bytes |
data | memory location containing the data. If data is nullptr, uninitalized memory will be created. |
usage | used as a performance hint on how the buffer is used |
void globjects::Buffer::setData | ( | const T & | data, |
gl::GLenum | usage | ||
) |
Convenience method to simplify passing of data in form of a POD struct.
void globjects::Buffer::setData | ( | const std::vector< T > & | data, |
gl::GLenum | usage | ||
) |
Convenience method to simplify passing of data in form of an std::vector.
void globjects::Buffer::setData | ( | const std::array< T, Count > & | data, |
gl::GLenum | usage | ||
) |
Convenience method to simplify passing of data in form of an std::array.
void globjects::Buffer::setSubData | ( | gl::GLintptr | offset, |
gl::GLsizeiptr | size, | ||
const gl::GLvoid * | data = nullptr |
||
) |
Wraps the OpenGL function glBufferSubData. Writes data only to a defined area of the memory.
size | size of memory in bytes |
offset | offset from the beginning of the buffer in bytes |
data | memory location containing the data |
void globjects::Buffer::setSubData | ( | const T & | data, |
gl::GLintptr | offset = 0 |
||
) |
Convenience method to simplify passing of data in form of a POD struct.
void globjects::Buffer::setSubData | ( | const std::vector< T > & | data, |
gl::GLintptr | offset = 0 |
||
) |
Convenience method to simplify passing of data in form of an std::vector.
void globjects::Buffer::setSubData | ( | const std::array< T, Count > & | data, |
gl::GLintptr | offset = 0 |
||
) |
Convenience method to simplify passing of data in form of an std::array.
void globjects::Buffer::setStorage | ( | gl::GLsizeiptr | size, |
const gl::GLvoid * | data, | ||
gl::BufferStorageMask | flags | ||
) |
Wraps the OpenGL function glBufferStorage.
size | size of the new memory in bytes |
data | data memory location containing the data. |
flags | flags indicating usage |
void globjects::Buffer::setStorage | ( | const T & | data, |
gl::BufferStorageMask | flags | ||
) |
Convenience method to simplify passing of data in form of a POD struct.
void globjects::Buffer::setStorage | ( | const std::vector< T > & | data, |
gl::BufferStorageMask | flags | ||
) |
Convenience method to simplify passing of data in form of an std::vector.
void globjects::Buffer::setStorage | ( | const std::array< T, Count > & | data, |
gl::BufferStorageMask | flags | ||
) |
Convenience method to simplify passing of data in form of an std::array.
gl::GLint globjects::Buffer::getParameter | ( | gl::GLenum | pname | ) | const |
Wraps the OpenGL function gl::glGetBufferParameter. Queries OpenGL for internal state of the buffer.
pname | name of the parameter, e.g. gl::GL_BUFFER_SIZE |
gl::GLint64 globjects::Buffer::getParameter64 | ( | gl::GLenum | pname | ) | const |
Wraps the OpenGL function gl::glGetBufferParameter for 64 bit data types. Queries OpenGL for internal state of the buffer.
pname | name of the parameter, e.g. gl::GL_BUFFER_SIZE |
const void* globjects::Buffer::map | ( | ) | const |
Maps the Buffer's memory read only.
void* globjects::Buffer::map | ( | gl::GLenum | access | ) |
Maps the Buffer's memory using the internal target.
access | specifies reading/writing access |
void* globjects::Buffer::mapRange | ( | gl::GLintptr | offset, |
gl::GLsizeiptr | length, | ||
gl::BufferAccessMask | access | ||
) |
Wraps the OpenGL function glMapBufferRange. Maps only a range of the buffers memory.
offset | offset from the beginning of the buffer data in bytes. |
length | length of the range in bytes. |
access | bitfield of desired access flags |
bool globjects::Buffer::unmap | ( | ) | const |
Wraps the OpenGL function glUnmapBuffer.
void globjects::Buffer::flushMappedRange | ( | gl::GLintptr | offset, |
gl::GLsizeiptr | length | ||
) |
Wraps the OpenGL function glFlushMappedBufferRange.
offset | offset from the beginning of the buffer data in bytes. |
length | length of the range in bytes |
void globjects::Buffer::bindBase | ( | gl::GLenum | target, |
gl::GLuint | index | ||
) | const |
Wraps the OpenGL function gl::glBindBufferBase.
void globjects::Buffer::bindRange | ( | gl::GLenum | target, |
gl::GLuint | index, | ||
gl::GLintptr | offset, | ||
gl::GLsizeiptr | size | ||
) | const |
Wraps the OpenGL function gl::glBindBufferRange.
void globjects::Buffer::copySubData | ( | Buffer * | buffer, |
gl::GLintptr | readOffset, | ||
gl::GLintptr | writeOffset, | ||
gl::GLsizeiptr | size | ||
) | const |
Wraps the OpenGL function glCopyBufferSubData.
readOffset | offset in bytes in read buffer |
writeOffset | offset in bytes in write buffer |
size | size of the data to be copies in bytes |
void globjects::Buffer::copySubData | ( | Buffer * | buffer, |
gl::GLsizeiptr | size | ||
) | const |
Convenience method. Both readOffset and writeOffset are 0.
void globjects::Buffer::copyData | ( | Buffer * | buffer, |
gl::GLsizeiptr | size, | ||
gl::GLenum | usage | ||
) | const |
Creates new uninitialized memory to fit size (using usage), then copies the contents of buffer to this buffer's new memory.
buffer | buffer from which content is copied |
size | size of the data to be copied |
usage | buffer usage |
void globjects::Buffer::clearData | ( | gl::GLenum | internalformat, |
gl::GLenum | format, | ||
gl::GLenum | type, | ||
const void * | data = nullptr |
||
) |
Wraps the OpenGL function gl::glClearBufferData. Clears the Buffer's data by filling it with the value in data, which has to be long enough to match format.
data | up to 4 components of the vector value to fill the buffer with |
void globjects::Buffer::clearSubData | ( | gl::GLenum | internalformat, |
gl::GLintptr | offset, | ||
gl::GLsizeiptr | size, | ||
gl::GLenum | format, | ||
gl::GLenum | type, | ||
const void * | data = nullptr |
||
) |
Wraps the OpenGL function gl::glClearBufferSubData.
offset | offset in bytes |
size | size in bytes |
const void* globjects::Buffer::getPointer | ( | ) | const |
void* globjects::Buffer::getPointer | ( | ) |
const void* globjects::Buffer::getPointer | ( | gl::GLenum | pname | ) | const |
void* globjects::Buffer::getPointer | ( | gl::GLenum | pname | ) |
void globjects::Buffer::getSubData | ( | gl::GLintptr | offset, |
gl::GLsizeiptr | size, | ||
void * | data | ||
) | const |
Wraps the OpenGL function glGetBufferSubData. Retrieves the contents of the buffers data store.
offset | offset from the beginning of the buffer in bytes |
size | size of memory in bytes |
data | memory location to store the data |
std::vector<T> globjects::Buffer::getSubData | ( | gl::GLsizeiptr | count, |
gl::GLintptr | offset = 0 |
||
) | const |
Convenience method to simplify getting of data in form of an std::vector.
std::array<T, Count> globjects::Buffer::getSubData | ( | gl::GLintptr | offset = 0 | ) | const |
Convenience method to simplify getting of data in form of an std::array.
void globjects::Buffer::invalidateData | ( | ) | const |
Wraps the OpenGL function gl::glInvalidateBufferData.
void globjects::Buffer::invalidateSubData | ( | gl::GLintptr | offset, |
gl::GLsizeiptr | length | ||
) | const |
Wraps the OpenGL function gl::glInvalidateBufferSubData.
offset | offset in bytes |
size | size in bytes |
|
overridevirtual |
Implements globjects::Object.