globjects  1.1.0.2f0c753c8647
Strict OpenGL objects wrapper.

Wrapper for OpenGL buffer objects. More...

#include <globjects/include/globjects/Buffer.h>

Inheritance diagram for globjects::Buffer:
globjects::Object globjects::Referenced globjects::HeapOnly

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 BufferfromId (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
 

Detailed Description

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.

Buffer * buffer = new Buffer(gl::GL_SHADER_STORAGE_BUFFER);
buffer->setData(sizeof(glm::vec4) * 100, nullptr, gl::GL_DYNAMIC_DRAW); // allocate 100 vec4
See also
http://www.opengl.org/wiki/Buffer_Object

Member Enumeration Documentation

Enumerator
DirectStateAccessARB 
DirectStateAccessEXT 
Legacy 

Constructor & Destructor Documentation

globjects::Buffer::Buffer ( )

Creates a new OpenGL buffer object.

globjects::Buffer::Buffer ( IDResource *  resource)
protected

Creates a buffer with an external id.

Parameters
idan external OpenGL buffer id
virtual globjects::Buffer::~Buffer ( )
protectedvirtual

Automatically deletes the associated OpenGL buffer unless the object was created with an external id.

See also
https://www.opengl.org/sdk/docs/man4/xhtml/gl::glDeleteBuffers.xml

Member Function Documentation

static void globjects::Buffer::hintBindlessImplementation ( BindlessImplementation  impl)
static
static void globjects::Buffer::setWorkingTarget ( gl::GLenum  target)
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.

Parameters
target
static Buffer* globjects::Buffer::fromId ( gl::GLuint  id)
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.

Parameters
idan external OpenGL buffer id
virtual void globjects::Buffer::accept ( ObjectVisitor visitor)
overridevirtual

Implements the visitor pattern.

Parameters
visitorThe visitor on which visitBuffer will be called.

Implements globjects::Object.

void globjects::Buffer::bind ( gl::GLenum  target) const

Binds the buffer to target.

Parameters
targetthe target for binding
See also
https://www.opengl.org/sdk/docs/man4/xhtml/gl::glBindBuffer.xml
static void globjects::Buffer::unbind ( gl::GLenum  target)
static

Unbinds a specific target, i.e. binds a 0 id to the target.

Parameters
targetthe target for unbinding
static void globjects::Buffer::unbind ( gl::GLenum  target,
gl::GLuint  index 
)
static

Unbinds the buffer bound to the target and index.

Parameters
targetthe target for unbinding
indexthe 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.

Parameters
sizesize of the new memory in bytes
datamemory location containing the data. If data is nullptr, uninitalized memory will be created.
usageused as a performance hint on how the buffer is used
See also
https://www.opengl.org/sdk/docs/man4/xhtml/glBufferData.xml
template<typename T >
void globjects::Buffer::setData ( const T &  data,
gl::GLenum  usage 
)

Convenience method to simplify passing of data in form of a POD struct.

template<typename T >
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.

template<typename T , std::size_t Count>
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.

Parameters
sizesize of memory in bytes
offsetoffset from the beginning of the buffer in bytes
datamemory location containing the data
See also
http://www.opengl.org/sdk/docs/man/xhtml/glBufferSubData.xml
template<typename T >
void globjects::Buffer::setSubData ( const T &  data,
gl::GLintptr  offset = 0 
)

Convenience method to simplify passing of data in form of a POD struct.

template<typename T >
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.

template<typename T , std::size_t Count>
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.

Parameters
sizesize of the new memory in bytes
datadata memory location containing the data.
flagsflags indicating usage
See also
www.opengl.org/sdk/docs/man/xhtml/glBufferStorage.xml
template<typename T >
void globjects::Buffer::setStorage ( const T &  data,
gl::BufferStorageMask  flags 
)

Convenience method to simplify passing of data in form of a POD struct.

template<typename T >
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.

template<typename T , std::size_t Count>
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.

Parameters
pnamename of the parameter, e.g. gl::GL_BUFFER_SIZE
Returns
integer value for the parameter
See also
http://www.opengl.org/sdk/docs/man/xhtml/gl::glGetBufferParameter.xml
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.

Parameters
pnamename of the parameter, e.g. gl::GL_BUFFER_SIZE
Returns
integer value for the parameter
See also
http://www.opengl.org/sdk/docs/man/xhtml/gl::glGetBufferParameter.xml
const void* globjects::Buffer::map ( ) const

Maps the Buffer's memory read only.

Returns
a pointer to the mapped memory
void* globjects::Buffer::map ( gl::GLenum  access)

Maps the Buffer's memory using the internal target.

Parameters
accessspecifies reading/writing access
Returns
a pointer to the mapped memory
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.

Parameters
offsetoffset from the beginning of the buffer data in bytes.
lengthlength of the range in bytes.
accessbitfield of desired access flags
Returns
pointer to the mapped memory
See also
http://www.opengl.org/sdk/docs/man/xhtml/glMapBufferRange.xml
bool globjects::Buffer::unmap ( ) const

Wraps the OpenGL function glUnmapBuffer.

See also
http://www.opengl.org/sdk/docs/man3/xhtml/glMapBuffer.xml
void globjects::Buffer::flushMappedRange ( gl::GLintptr  offset,
gl::GLsizeiptr  length 
)

Wraps the OpenGL function glFlushMappedBufferRange.

Parameters
offsetoffset from the beginning of the buffer data in bytes.
lengthlength of the range in bytes
See also
http://www.opengl.org/sdk/docs/man/html/glFlushMappedBufferRange.xhtml
void globjects::Buffer::bindBase ( gl::GLenum  target,
gl::GLuint  index 
) const

Wraps the OpenGL function gl::glBindBufferBase.

See also
http://www.opengl.org/sdk/docs/man/xhtml/gl::glBindBufferBase.xml
void globjects::Buffer::bindRange ( gl::GLenum  target,
gl::GLuint  index,
gl::GLintptr  offset,
gl::GLsizeiptr  size 
) const

Wraps the OpenGL function gl::glBindBufferRange.

See also
http://www.opengl.org/sdk/docs/man3/xhtml/gl::glBindBufferRange.xml
void globjects::Buffer::copySubData ( Buffer buffer,
gl::GLintptr  readOffset,
gl::GLintptr  writeOffset,
gl::GLsizeiptr  size 
) const

Wraps the OpenGL function glCopyBufferSubData.

Parameters
readOffsetoffset in bytes in read buffer
writeOffsetoffset in bytes in write buffer
sizesize of the data to be copies in bytes
See also
http://www.opengl.org/sdk/docs/man3/xhtml/glCopyBufferSubData.xml
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.

Parameters
bufferbuffer from which content is copied
sizesize of the data to be copied
usagebuffer 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.

Parameters
dataup to 4 components of the vector value to fill the buffer with
See also
http://www.opengl.org/sdk/docs/man/xhtml/gl::glClearBufferData.xml
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.

Parameters
offsetoffset in bytes
sizesize in bytes
See also
https://www.opengl.org/sdk/docs/man4/xhtml/gl::glClearBufferSubData.xml
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.

Parameters
offsetoffset from the beginning of the buffer in bytes
sizesize of memory in bytes
datamemory location to store the data
See also
http://www.opengl.org/sdk/docs/man/xhtml/glGetBufferSubData.xml
template<typename T >
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.

template<typename T , std::size_t Count>
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.

See also
https://www.opengl.org/sdk/docs/man/html/glInvalidateBufferData.xhtml
void globjects::Buffer::invalidateSubData ( gl::GLintptr  offset,
gl::GLsizeiptr  length 
) const

Wraps the OpenGL function gl::glInvalidateBufferSubData.

Parameters
offsetoffset in bytes
sizesize in bytes
See also
https://www.opengl.org/sdk/docs/man/html/glInvalidateBufferSubData.xhtml
virtual gl::GLenum globjects::Buffer::objectType ( ) const
overridevirtual

Implements globjects::Object.


The documentation for this class was generated from the following file: