sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
sgltk::Buffer Class Reference

Manages buffer objects. More...

#include <buffer.h>

Public Member Functions

 Buffer (GLenum target=GL_ARRAY_BUFFER)
void bind ()
 Binds the buffer object to the target it was previously bound to or GL_ARRAY_BUFFER if the buffer has not been bound to a target before.
void bind (GLenum target)
 Binds the buffer object to a target.
void bind (GLenum target, unsigned int index)
 Binds the buffer object to an indexed buffer target.
void unbind ()
 Unbinds the buffer object from the target it was bound to.
template<typename T>
void create_empty (unsigned int num_elements, GLenum usage)
 Creates an empty buffer.
template<typename T>
void load (const std::vector< T > &data, GLenum usage)
 Loads data into the buffer.
template<typename T>
void load (unsigned int num_elements, const T *data, GLenum usage)
 Loads data into the buffer.
bool store (unsigned int offset, unsigned int size, void *storage)
 Writes the contents of the buffer object into the storage.
bool copy (Buffer &source, unsigned int read_offset, unsigned int write_offset, unsigned int size)
 Copies data from another buffer object.
bool copy (Buffer *source, unsigned int read_offset, unsigned int write_offset, unsigned int size)
 Copies data from another buffer object.
void * map (GLenum access)
 Maps all of a buffer object's data into the client's address space.
void unmap ()
 Releases the mapping of a buffer object's data store into the client's address space.
template<typename T>
void replace_data (const std::vector< T > &data)
 Overwrites all data in a vertex buffer.
template<typename T>
void replace_data (const T *data, unsigned int number_elements)
 Overwrites all data in the buffer.
template<typename T>
bool replace_partial_data (unsigned int offset, const std::vector< T > &data)
 Overwrites data in the buffer starting at the specified offset.
template<typename T>
bool replace_partial_data (unsigned int offset, const T *data, unsigned int number_elements)
 Overwrites data in the buffer starting at the specified offset.

Public Attributes

GLuint buffer
 The name of the buffer object.
unsigned int size
 Size of the buffer in bytes.
unsigned int num_elements
 Number of elements contained in the buffer.

Detailed Description

Manages buffer objects.

Definition at line 12 of file buffer.h.

Constructor & Destructor Documentation

◆ Buffer()

sgltk::Buffer::Buffer ( GLenum target = GL_ARRAY_BUFFER)
inline
Parameters
targetThe initial target to bind the buffer to

Definition at line 34 of file buffer.h.

◆ ~Buffer()

sgltk::Buffer::~Buffer ( )
inline

Definition at line 39 of file buffer.h.

Member Function Documentation

◆ bind() [1/3]

void sgltk::Buffer::bind ( )
inline

Binds the buffer object to the target it was previously bound to or GL_ARRAY_BUFFER if the buffer has not been bound to a target before.

Definition at line 48 of file buffer.h.

◆ bind() [2/3]

void sgltk::Buffer::bind ( GLenum target)
inline

Binds the buffer object to a target.

Parameters
targetThe target to bind the buffer to

Definition at line 56 of file buffer.h.

◆ bind() [3/3]

void sgltk::Buffer::bind ( GLenum target,
unsigned int index )
inline

Binds the buffer object to an indexed buffer target.

Parameters
targetThe target to bind the buffer to
indexThe index of the binding point within the array specified by target.
Note
If the target of the buffer is not GL_ATOMIC_COUNTER_BUFFER, GL_TRANSFORM_FEEDBACK_BUFFER, GL_UNIFORM_BUFFER or GL_SHADER_STORAGE_BUFFER the index is ignored.

Definition at line 70 of file buffer.h.

◆ copy() [1/2]

bool sgltk::Buffer::copy ( Buffer & source,
unsigned int read_offset,
unsigned int write_offset,
unsigned int size )
inline

Copies data from another buffer object.

Parameters
sourceThe source of the data to copy
read_offsetThe offset into the source buffer
write_offsetThe offset into the destination buffer
sizeThe size of the data to copy in bytes
Returns
Returns true on success, false otherwise

Definition at line 179 of file buffer.h.

◆ copy() [2/2]

bool sgltk::Buffer::copy ( Buffer * source,
unsigned int read_offset,
unsigned int write_offset,
unsigned int size )
inline

Copies data from another buffer object.

Parameters
sourceThe source of the data to copy
read_offsetThe offset into the source buffer
write_offsetThe offset into the destination buffer
sizeThe size of the data to copy in bytes
Returns
Returns true on success, false otherwise

Definition at line 207 of file buffer.h.

◆ create_empty()

template<typename T>
void sgltk::Buffer::create_empty ( unsigned int num_elements,
GLenum usage )
inline

Creates an empty buffer.

Parameters
num_elementsNumber of elements
usageA hint as to how the buffer will be accessed. Valid values are GL_{STREAM,STATIC,DYNAMIC}_{DRAW,READ,COPY}.

Definition at line 102 of file buffer.h.

◆ load() [1/2]

template<typename T>
void sgltk::Buffer::load ( const std::vector< T > & data,
GLenum usage )
inline

Loads data into the buffer.

Parameters
dataThe data to load into the buffer
usageA hint as to how the buffer will be accessed. Valid values are GL_{STREAM,STATIC,DYNAMIC}_{DRAW,READ,COPY}.

Definition at line 117 of file buffer.h.

◆ load() [2/2]

template<typename T>
void sgltk::Buffer::load ( unsigned int num_elements,
const T * data,
GLenum usage )
inline

Loads data into the buffer.

Parameters
num_elementsNumber of elements
dataThe data to load into the buffer
usageA hint as to how the buffer will be accessed. Valid values are GL_{STREAM,STATIC,DYNAMIC}_{DRAW,READ,COPY}.

Definition at line 135 of file buffer.h.

◆ map()

void * sgltk::Buffer::map ( GLenum access)
inline

Maps all of a buffer object's data into the client's address space.

Parameters
accessIndicates whether it will be possible to read from, write to, or both read from and write to the buffer object's mapped data store. Must be GL_READ_ONLY, GL_WRITE_ONLY, or GL_READ_WRITE
Returns
Returns a pointer to the beginning of the mapped range once all pending operations on that buffer object have completed

Definition at line 239 of file buffer.h.

◆ replace_data() [1/2]

template<typename T>
void sgltk::Buffer::replace_data ( const std::vector< T > & data)
inline

Overwrites all data in a vertex buffer.

Parameters
dataThe data to be loaded into the buffer

Definition at line 261 of file buffer.h.

◆ replace_data() [2/2]

template<typename T>
void sgltk::Buffer::replace_data ( const T * data,
unsigned int number_elements )
inline

Overwrites all data in the buffer.

Parameters
dataThe data to be loaded into the buffer
number_elementsNumber of elements

Definition at line 283 of file buffer.h.

◆ replace_partial_data() [1/2]

template<typename T>
bool sgltk::Buffer::replace_partial_data ( unsigned int offset,
const std::vector< T > & data )
inline

Overwrites data in the buffer starting at the specified offset.

Parameters
offsetThe offset from the start of the buffer in bytes
dataThe data to be loaded into the buffer

Definition at line 305 of file buffer.h.

◆ replace_partial_data() [2/2]

template<typename T>
bool sgltk::Buffer::replace_partial_data ( unsigned int offset,
const T * data,
unsigned int number_elements )
inline

Overwrites data in the buffer starting at the specified offset.

Parameters
offsetThe offset from the start of the buffer in bytes
dataThe data to be loaded into the buffer
number_elementsNumber of elements

Definition at line 326 of file buffer.h.

◆ store()

bool sgltk::Buffer::store ( unsigned int offset,
unsigned int size,
void * storage )
inline

Writes the contents of the buffer object into the storage.

Parameters
offsetThe offset in bytes into the buffer object
sizeThe size of the storage
storageThe storage to write the data to
Returns
Returns true on success, false otherwise
Note
To ensure that the shader program has finished its operations on the buffer you should call glMemoryBarrier before calling this function.

Definition at line 154 of file buffer.h.

◆ unbind()

void sgltk::Buffer::unbind ( )
inline

Unbinds the buffer object from the target it was bound to.

Note
Exercise caution when unbinding a buffer! If you bind two buffers to the same target and then call unbind on the first one, you

Definition at line 91 of file buffer.h.

◆ unmap()

void sgltk::Buffer::unmap ( )
inline

Releases the mapping of a buffer object's data store into the client's address space.

Definition at line 250 of file buffer.h.

Member Data Documentation

◆ buffer

GLuint sgltk::Buffer::buffer

The name of the buffer object.

Definition at line 19 of file buffer.h.

◆ num_elements

unsigned int sgltk::Buffer::num_elements

Number of elements contained in the buffer.

Definition at line 29 of file buffer.h.

◆ size

unsigned int sgltk::Buffer::size

Size of the buffer in bytes.

Definition at line 24 of file buffer.h.


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