CGVIS Utils
Loading...
Searching...
No Matches
GLBuffer Class Reference

#include <GLBuffer.h>

Public Member Functions

 GLBuffer (GLenum target)
 Create a buffer object for the given OpenGL target.
 ~GLBuffer ()
 Destroy and delete the GL buffer name.
void setData (const std::vector< GLfloat > &data, size_t valuesPerElement, GLenum usage=GL_STATIC_DRAW)
 Upload interleaved float data and define element stride.
void setData (const std::vector< GLuint > &data)
 Upload unsigned-int data (e.g., element indices).
void setData (const float data[], size_t elemCount, size_t valuesPerElement, GLenum usage=GL_STATIC_DRAW)
 Upload interleaved float data from a raw pointer.
void setData (const GLuint data[], size_t elemCount)
 Upload unsigned-int data from a raw pointer.
void connectVertexAttrib (GLuint location, size_t elemCount, size_t offset=0, GLuint divisor=0) const
 Describe a vertex attribute array for the current buffer contents.
void bind () const
 Bind the buffer to its target with glBindBuffer(target, id).

Constructor & Destructor Documentation

◆ GLBuffer()

GLBuffer::GLBuffer ( GLenum target)

Create a buffer object for the given OpenGL target.

Parameters
targetBuffer binding target (e.g., GL_ARRAY_BUFFER).
Postcondition
A GL name is generated via glGenBuffers.

◆ ~GLBuffer()

GLBuffer::~GLBuffer ( )

Destroy and delete the GL buffer name.

Member Function Documentation

◆ bind()

void GLBuffer::bind ( ) const

Bind the buffer to its target with glBindBuffer(target, id).

Here is the caller graph for this function:

◆ connectVertexAttrib()

void GLBuffer::connectVertexAttrib ( GLuint location,
size_t elemCount,
size_t offset = 0,
GLuint divisor = 0 ) const

Describe a vertex attribute array for the current buffer contents.

Parameters
locationAttribute location as retrieved from the shader.
elemCountNumber of components per attribute (e.g., 2,3,4).
offsetOffset (in elements, not bytes) from the beginning of each record.
divisorAdvanced: instance divisor for instanced rendering (0 = per-vertex).
Exceptions
GLExceptionIf no prior setData call has established an element type.

Binds the buffer to its target, enables the attribute array, and calls glVertexAttribPointer with the stride and byte offset computed from the previously uploaded data.

Here is the caller graph for this function:

◆ setData() [1/4]

void GLBuffer::setData ( const float data[],
size_t elemCount,
size_t valuesPerElement,
GLenum usage = GL_STATIC_DRAW )

Upload interleaved float data from a raw pointer.

Parameters
dataPointer to elemCount*valuesPerElement floats.
elemCountNumber of logical elements.
valuesPerElementNumber of floats per element (stride in values).
usageGL usage hint.

◆ setData() [2/4]

void GLBuffer::setData ( const GLuint data[],
size_t elemCount )

Upload unsigned-int data from a raw pointer.

Parameters
dataPointer to elemCount indices.
elemCountNumber of indices.

◆ setData() [3/4]

void GLBuffer::setData ( const std::vector< GLfloat > & data,
size_t valuesPerElement,
GLenum usage = GL_STATIC_DRAW )

Upload interleaved float data and define element stride.

Parameters
dataFlat vector of floats.
valuesPerElementNumber of float values that make up one logical element (stride in values).
usageGL usage hint (e.g., GL_STATIC_DRAW).
Postcondition
Internal bookkeeping (elemSize/stride/type) is updated for later attribute binding.

◆ setData() [4/4]

void GLBuffer::setData ( const std::vector< GLuint > & data)

Upload unsigned-int data (e.g., element indices).

Parameters
dataFlat vector of GLuint values.
Postcondition
Element size/stride/type are set for index-style data (stride = 1, type = GL_UNSIGNED_INT).

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