CUGL 2.1
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
cugl::UniformBuffer Class Reference

#include <CUUniformBuffer.h>

Public Member Functions

 UniformBuffer ()
 
 ~UniformBuffer ()
 
void dispose ()
 
bool init (GLsizei capacity)
 
bool init (GLsizei capacity, GLuint blocks)
 
void setName (std::string name)
 
const std::string & getName () const
 
GLenum getDrawType () const
 
void setDrawType (GLenum type)
 
bool isReady () const
 
GLuint getBlockCount () const
 
GLsizei getBlockSize () const
 
GLsizei getBlockStride () const
 
char * getData ()
 
bool getAutoflush () const
 
void setAutoflush (bool style)
 
GLuint getBuffer () const
 
GLuint getBindPoint () const
 
void setBindPoint (GLuint point)
 
void bind (bool activate=true)
 
void unbind ()
 
void activate ()
 
void deactivate ()
 
bool isBound () const
 
bool isActive () const
 
GLuint getBlock () const
 
void setBlock (GLuint block)
 
void flush ()
 
void setOffset (const std::string name, GLsizei offset)
 
GLsizei getOffset (const std::string name) const
 
std::vector< std::string > getOffsets () const
 
void setUniformVec2 (GLint block, GLsizei offset, const Vec2 vec)
 
void setUniformVec2 (GLint block, const std::string name, const Vec2 vec)
 
bool getUniformVec2 (GLuint block, GLsizei offset, Vec2 &vec) const
 
bool getUniformVec2 (GLuint block, const std::string name, Vec2 &vec) const
 
void setUniformVec3 (GLint block, GLsizei offset, const Vec3 vec)
 
void setUniformVec3 (GLint block, const std::string name, const Vec3 vec)
 
bool getUniformVec3 (GLuint block, GLsizei offset, Vec3 &vec) const
 
bool getUniformVec3 (GLuint block, const std::string name, Vec3 &vec) const
 
void setUniformVec4 (GLint block, GLsizei offset, const Vec4 vec)
 
void setUniformVec4 (GLint block, const std::string name, const Vec4 vec)
 
bool getUniformVec4 (GLuint block, GLsizei offset, Vec4 &vec) const
 
bool getUniformVec4 (GLuint block, const std::string name, Vec4 &vec) const
 
void setUniformColor4 (GLint block, GLsizei offset, const Color4 color)
 
void setUniformColor4 (GLint block, const std::string name, const Color4 color)
 
bool getUniformColor4 (GLuint block, GLsizei offset, Color4 &color) const
 
bool getUniformColor4 (GLuint block, const std::string name, Color4 &color) const
 
void setUniformColor4f (GLint block, GLsizei offset, const Color4f color)
 
void setUniformColor4f (GLint block, const std::string name, const Color4f color)
 
bool getUniformColor4f (GLuint block, GLsizei offset, Color4f &color) const
 
bool getUniformColor4f (GLuint block, const std::string name, Color4f &color) const
 
void setUniformMat4 (GLint block, GLsizei offset, const Mat4 &mat)
 
void setUniformMat4 (GLint block, const std::string name, const Mat4 &mat)
 
bool getUniformMat4 (GLuint block, GLsizei offset, Mat4 &mat) const
 
bool getUniformMat4 (GLuint block, const std::string name, Mat4 &mat) const
 
void setUniformAffine2 (GLint block, GLsizei offset, const Affine2 &mat)
 
void setUniformAffine2 (GLint block, const std::string name, const Affine2 &mat)
 
bool getUniformAffine2 (GLuint block, GLsizei offset, Affine2 &mat) const
 
bool getUniformAffine2 (GLuint block, const std::string name, Affine2 &mat) const
 
void setUniformQuaternion (GLint block, GLsizei offset, const Quaternion &quat)
 
void setUniformQuaternion (GLint block, const std::string name, const Quaternion &quat)
 
bool getUniformQuaternion (GLuint block, GLsizei offset, Quaternion &quat) const
 
bool getUniformQuaternion (GLuint block, const std::string name, Quaternion &quat) const
 
void setUniformfv (GLint block, GLsizei offset, GLsizei size, const GLfloat *values)
 
void setUniformfv (GLint block, const std::string name, GLsizei size, const GLfloat *values)
 
bool getUniformfv (GLuint block, GLsizei offset, GLsizei size, GLfloat *values) const
 
bool getUniformfv (GLuint block, const std::string name, GLsizei size, GLfloat *values) const
 
void setUniformiv (GLint block, GLsizei offset, GLsizei size, const GLint *values)
 
void setUniformiv (GLint block, const std::string name, GLsizei size, const GLint *values)
 
bool getUniformiv (GLuint block, GLsizei offset, GLsizei size, GLint *values) const
 
bool getUniformiv (GLuint block, const std::string name, GLsizei size, GLint *values) const
 
void setUniformuiv (GLint block, GLsizei offset, GLsizei size, const GLuint *values)
 
void setUniformuiv (GLint block, const std::string name, GLsizei size, const GLuint *values)
 
bool getUniformuiv (GLuint block, GLsizei offset, GLsizei size, GLuint *values) const
 
bool getUniformuiv (GLuint block, const std::string name, GLsizei size, GLuint *values) const
 

Static Public Member Functions

static std::shared_ptr< UniformBufferalloc (GLsizei capacity)
 
static std::shared_ptr< UniformBufferalloc (GLsizei capacity, GLuint blocks)
 

Static Public Attributes

static GLsizei INVALID_OFFSET
 

Detailed Description

This class defines a uniform block buffer for shader optimization.

Like Texture, shaders and uniform buffers have a many-to-many relationship. This many-to-many relationship is captured by bind points. A uniform buffer is associated with a bind point and a shader associates a binding point with a uniform struct. That uniform struct then pulls data from the uniform buffer.

When discussing the relationship between a shader and a uniform buffer, we talk about a buffer being bound and a buffer being active. A bound buffer is one that is associated with a shader; the shader will pull from the uniform buffer to populate its uniform variables. An active buffer is one that is capable of receiving data from the CPU. A buffer must be active if the user wants to change any of the data in the buffer. These are two separate concepts and are treated separately in this class.

Technically, a shader is associated with a uniform block, not a uniform buffer, since a uniform buffer may have multiple blocks. In the case of a uniform buffer with multiple blocks, the current block is managed by the method setBlock.

Uniform buffers are ideal in two use cases. First of all, they are great for uniforms that are shared across multiple shaders. But it is also worthwhile to have a buffer for a single shader if (1) that shader has a large number of uniforms and (2) those uniforms change semi-frequently through out a render pass. In that case, the uniform buffer should be allocated with enough blocks so that all of the possible uniform values can be assigned at the start of the render pass, each to a different block. Once the shader starts to receive vertices, the uniforms should be managed via the setBlock method.

Constructor & Destructor Documentation

◆ UniformBuffer()

cugl::UniformBuffer::UniformBuffer ( )

Creates an uninitialized uniform buffer.

You must initialize the uniform buffer to allocate memory.

◆ ~UniformBuffer()

cugl::UniformBuffer::~UniformBuffer ( )

Deletes this uniform buffer, disposing all resources.

Member Function Documentation

◆ activate()

void cugl::UniformBuffer::activate ( )

Activates this uniform block so that if can receive data.

This method makes this uniform block the active uniform buffer. This means that changes made to the data in this uniform buffer will be pushed to the graphics card. If there were are any pending changes to the uniform buffer (made when it was not active), they will be pushed immediately when this method is called.

This method does not bind the uniform block to a bind point. That must be done with a call to bind.

This call is reentrant. If can be safely called multiple times.

◆ alloc() [1/2]

static std::shared_ptr<UniformBuffer> cugl::UniformBuffer::alloc ( GLsizei  capacity)
inlinestatic

Returns a new uniform block to support a block of the given capacity.

This uniform buffer will only support a single block. The block capacity is measured in bytes. In std140 format, all scalars are 4 bytes, vectors are 8 or 16 bytes, and matrices are treated as an array of 8 or 16 byte column vectors.

The drawtype is GL_STATIC_DRAW, GL_DYNAMIC_DRAW, or GL_STREAM_DRAW. If the uniform values change often, the difference between GL_STATIC_DRAW and GL_STREAM_DRAW is 1-2 orders of magnitude.

Parameters
capacityThe block capacity in bytes
Returns
a new uniform block to support a block of the given capacity.

◆ alloc() [2/2]

static std::shared_ptr<UniformBuffer> cugl::UniformBuffer::alloc ( GLsizei  capacity,
GLuint  blocks 
)
inlinestatic

Returns a new uniform buffer to support multiple blocks of the given capacity.

The block capacity is measured in bytes. In std140 format, all scalars are 4 bytes, vectors are 8 or 16 bytes, and matrices are treated as an array of 8 or 16 byte column vectors.

Keep in mind that uniform buffer blocks must be aligned, and so this may take significantly more memory than the number of blocks times the capacity. If the graphics card cannot support that many blocks, this method will return nullptr.

The drawtype is GL_STATIC_DRAW, GL_DYNAMIC_DRAW, or GL_STREAM_DRAW. If the uniform values change often, the difference between GL_STATIC_DRAW and GL_STREAM_DRAW is 1-2 orders of magnitude.

Parameters
capacityThe block capacity in bytes
blocksThe number of blocks to support
Returns
a new uniform buffer to support multiple blocks of the given capacity.

◆ bind()

void cugl::UniformBuffer::bind ( bool  activate = true)

Binds this uniform buffer to its bind point.

Unlike Texture, it is possible to bind a uniform buffer to its bind point without making it the active uniform buffer. An inactive buffer will still stream data to the shader, though its data cannot be altered without making it active.

Binding a buffer to a bind point replaces the uniform block originally there. So this buffer can be unbound without a call to unbind. However, if another buffer is bound to a different bind point than this block, it will not affect this buffer's relationship with the shader.

For compatibility reasons with Texture we allow this method to both bind and activate the uniform buffer in one call.

This call is reentrant. If can be safely called multiple times.

Parameters
activateWhether to activate this buffer in addition to binding.

◆ deactivate()

void cugl::UniformBuffer::deactivate ( )

Deactivates this uniform block, making it no longer active.

This method will not unbind the buffer from its bind point (assuming it is bound to one). It simply means that it is no longer the active uniform buffer and cannot receive new data. Data sent to this buffer will be cached and sent to the graphics card once the buffer is reactivated. However, the shader will use the current graphics card data until that happens.

This call is reentrant. If can be safely called multiple times.

◆ dispose()

void cugl::UniformBuffer::dispose ( )

Deletes the uniform buffer, freeing all resources.

You must reinitialize the uniform buffer to use it.

◆ flush()

void cugl::UniformBuffer::flush ( )

Flushes any changes in the backing byte buffer to the graphics card.

This method must be called if any changes have been made to the buffer data and auto-flush is not turned on (which is the default). Even if auto-flush is turned on, it must be called if the user has accessed the backing byte buffer directly via getData.

This method requires the byte buffer to be active.

◆ getAutoflush()

bool cugl::UniformBuffer::getAutoflush ( ) const
inline

Returns true if this uniform buffer supports autoflushing.

Active, auto-flushed buffers write data directly to the graphics card as soon as it is provided to the buffer. A buffer than does not auto-flush will not write to the graphics card until flush is called, even if it is active.

By default, autoflushing is turned off.

Returns
true if this uniform buffer supports autoflushing.

◆ getBindPoint()

GLuint cugl::UniformBuffer::getBindPoint ( ) const
inline

Returns the bind point for this uniform buffer.

Uniform buffers and shaders have a many-to-many relationship. This means that connecting them requires an intermediate table. The positions in this table are called bind points. A uniform buffer is associated with a bind point and a shader associates a bind point with a uniform struct. That uniform struct then pulls data from the active block of the uniform buffer. By default this value is 0.

Returns
the bind point for for this uniform block.

◆ getBlock()

GLuint cugl::UniformBuffer::getBlock ( ) const
inline

Returns the active uniform block in this buffer.

The active uniform block is the block from which the shader will pull uniform values. This value can be altered even if the buffer is not active (or even bound)

Returns
the active uniform block in this buffer.

◆ getBlockCount()

GLuint cugl::UniformBuffer::getBlockCount ( ) const
inline

Returns the number of blocks supported by this buffer.

A uniform buffer can support multiple uniform blocks at once. The active block is identify by the method getBlock.

Returns
the number of blocks supported by this buffer.

◆ getBlockSize()

GLsizei cugl::UniformBuffer::getBlockSize ( ) const
inline

Returns the capacity of a single block in this uniform buffer.

The block size is the amount of data necessary to populate the uniforms for a single block. It is measured in bytes.

Returns
the capacity of a single block in this uniform buffer.

◆ getBlockStride()

GLsizei cugl::UniformBuffer::getBlockStride ( ) const
inline

Returns the stride of a single block in this uniform buffer.

The stride measures the alignment (in bytes) of a block. It is at least as large as the block capacity, but may be more.

Returns
the stride of a single block in this uniform buffer.

◆ getBuffer()

GLuint cugl::UniformBuffer::getBuffer ( ) const
inline

Returns the OpenGL buffer for this uniform buffer.

The buffer is a value assigned by OpenGL when the uniform buffer was allocated. This method will return 0 if the block is not initialized. This method is provided to allow the user direct access to the buffer for maximum flexibility.

Returns
the OpenGL buffer for this unform block.

◆ getData()

char* cugl::UniformBuffer::getData ( )
inline

Returns the backing byte-buffer for the uniform buffer

The byte buffer is used to store pending changes while the buffer is active (and is kept synchronized when it is active). This method allows direct access for bulk writes the buffer. However, the graphics card will not be aware of any of these changes until flush() is called.

The buffer returned will have a capacity of (block count) x (block stride).

Returns
the backing byte-buffer for the uniform buffer

◆ getDrawType()

GLenum cugl::UniformBuffer::getDrawType ( ) const
inline

Returns the draw type for this buffer

The drawtype is GL_STATIC_DRAW, GL_DYNAMIC_DRAW, or GL_STREAM_DRAW. If the uniform values change often, the difference between GL_STATIC_DRAW and GL_STREAM_DRAW is 1-2 orders of magnitude.

By default, the draw type is GL_STREAM_DRAW.

Returns
the draw type for this buffer

◆ getName()

const std::string& cugl::UniformBuffer::getName ( ) const
inline

Returns the name of this uniform buffer.

A name is a user-defined way of identifying a buffer. It is typically the appropriate shader variable name, but this is not necessary for it to function properly.

Returns
the name of this uniform block.

◆ getOffset()

GLsizei cugl::UniformBuffer::getOffset ( const std::string  name) const

Returns the byte offset for the given name.

This method requires that name be previously associated with an offset via setOffset. If it has not been associated with an offset, then this method will return INVALID_OFFSET instead.

Parameters
nameThe variable name to query for an offset
Returns
the byte offset of the given struct variable.

◆ getOffsets()

std::vector<std::string> cugl::UniformBuffer::getOffsets ( ) const

Returns the offsets defined for this buffer

The vector returned will include the name of every variable set by the method setOffset.

Returns
the offsets defined for this buffer

◆ getUniformAffine2() [1/2]

bool cugl::UniformBuffer::getUniformAffine2 ( GLuint  block,
const std::string  name,
Affine2 mat 
) const

Returns true if it can access the given uniform variable as an affine transform.

Affine transforms are read from a uniform block as a 4x3 matrix on homogenous coordinates. That is because the columns must be 4*sizeof(float) bytes for alignment reasons. The buffer must have 12*sizeof(float) bytes available for this read.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
matThe matrix to store the result
Returns
true if it can access the given uniform variable as an affine transform.

◆ getUniformAffine2() [2/2]

bool cugl::UniformBuffer::getUniformAffine2 ( GLuint  block,
GLsizei  offset,
Affine2 mat 
) const

Returns true if it can access the given uniform variable as an affine transform.

Affine transforms are read from a uniform block as a 4x3 matrix on homogenous coordinates. That is because the columns must be 4*sizeof(float) bytes for alignment reasons. The buffer must have 12*sizeof(float) bytes available for this read.

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
matThe matrix to store the result
Returns
true if it can access the given uniform variable as an affine transform.

◆ getUniformColor4() [1/2]

bool cugl::UniformBuffer::getUniformColor4 ( GLuint  block,
const std::string  name,
Color4 color 
) const

Returns true if it can access the given uniform variable as a color.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will read the color as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
colorThe color to store the result
Returns
true if it can access the given uniform variable as a vector.

◆ getUniformColor4() [2/2]

bool cugl::UniformBuffer::getUniformColor4 ( GLuint  block,
GLsizei  offset,
Color4 color 
) const

Returns true if it can access the given uniform variable as a color.

This method will read the color as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
colorThe color to store the result
Returns
true if it can access the given uniform variable as a color.

◆ getUniformColor4f() [1/2]

bool cugl::UniformBuffer::getUniformColor4f ( GLuint  block,
const std::string  name,
Color4f color 
) const

Returns true if it can access the given uniform variable as a color.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will read the color as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
colorThe color to store the result
Returns
true if it can access the given uniform variable as a color.

◆ getUniformColor4f() [2/2]

bool cugl::UniformBuffer::getUniformColor4f ( GLuint  block,
GLsizei  offset,
Color4f color 
) const

Returns true if it can access the given uniform variable as a color.

This method will read the color as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
colorThe color to store the result
Returns
true if it can access the given uniform variable as a color.

◆ getUniformfv() [1/2]

bool cugl::UniformBuffer::getUniformfv ( GLuint  block,
const std::string  name,
GLsizei  size,
GLfloat *  values 
) const

Returns true if it can access the given buffer location as an array of floats

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
sizeThe available size of the value array
valuesThe array to receive the values
Returns
true if data was successfully read into values

◆ getUniformfv() [2/2]

bool cugl::UniformBuffer::getUniformfv ( GLuint  block,
GLsizei  offset,
GLsizei  size,
GLfloat *  values 
) const

Returns true if it can access the given buffer offset as an array of floats

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
sizeThe available size of the value array
valuesThe array to receive the values
Returns
true if data was successfully read into values

◆ getUniformiv() [1/2]

bool cugl::UniformBuffer::getUniformiv ( GLuint  block,
const std::string  name,
GLsizei  size,
GLint *  values 
) const

Returns true if it can access the given buffer location as an array of integers

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
sizeThe available size of the value array
valuesThe array to receive the values
Returns
true if data was successfully read into values

◆ getUniformiv() [2/2]

bool cugl::UniformBuffer::getUniformiv ( GLuint  block,
GLsizei  offset,
GLsizei  size,
GLint *  values 
) const

Returns true if it can access the given buffer offset as an array of integers

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
sizeThe available size of the value array
valuesThe array to receive the values
Returns
true if data was successfully read into values

◆ getUniformMat4() [1/2]

bool cugl::UniformBuffer::getUniformMat4 ( GLuint  block,
const std::string  name,
Mat4 mat 
) const

Returns true if it can access the given uniform variable as a matrix.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will read the matrix as 16*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
matThe matrix to store the result
Returns
true if it can access the given uniform variable as a matrix.

◆ getUniformMat4() [2/2]

bool cugl::UniformBuffer::getUniformMat4 ( GLuint  block,
GLsizei  offset,
Mat4 mat 
) const

Returns true if it can access the given uniform variable as a matrix.

This method will read the matrix as 16*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
matThe matrix to store the result
Returns
true if it can access the given uniform variable as a matrix.

◆ getUniformQuaternion() [1/2]

bool cugl::UniformBuffer::getUniformQuaternion ( GLuint  block,
const std::string  name,
Quaternion quat 
) const

Returns true if it can access the given uniform variable as a quaternion.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will read the quaternion as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
quatThe quaternion to store the result
Returns
true if it can access the given uniform variable as a quaternion.

◆ getUniformQuaternion() [2/2]

bool cugl::UniformBuffer::getUniformQuaternion ( GLuint  block,
GLsizei  offset,
Quaternion quat 
) const

Returns true if it can access the given uniform variable as a quaternion.

This method will read the quaternion as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
quatThe quaternion to store the result
Returns
true if it can access the given uniform variable as a quaternion.

◆ getUniformuiv() [1/2]

bool cugl::UniformBuffer::getUniformuiv ( GLuint  block,
const std::string  name,
GLsizei  size,
GLuint *  values 
) const

Returns true if it can access the buffer location as an array of unsigned integers

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
sizeThe available size of the value array
valuesThe array to receive the values
Returns
true if data was successfully read into values

◆ getUniformuiv() [2/2]

bool cugl::UniformBuffer::getUniformuiv ( GLuint  block,
GLsizei  offset,
GLsizei  size,
GLuint *  values 
) const

Returns true if it can access the buffer offset as an array of unsigned integers

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
sizeThe available size of the value array
valuesThe array to receive the values
Returns
true if data was successfully read into values

◆ getUniformVec2() [1/2]

bool cugl::UniformBuffer::getUniformVec2 ( GLuint  block,
const std::string  name,
Vec2 vec 
) const

Returns true if it can access the given uniform variable as a vector.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will read the vector as 2*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
vecThe vector to store the result
Returns
true if it can access the given uniform variable as a vector.

◆ getUniformVec2() [2/2]

bool cugl::UniformBuffer::getUniformVec2 ( GLuint  block,
GLsizei  offset,
Vec2 vec 
) const

Returns true if it can access the given uniform variable as a vector.

This method will read the vector as 2*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
vecThe vector to store the result
Returns
true if it can access the given uniform variable as a vector.

◆ getUniformVec3() [1/2]

bool cugl::UniformBuffer::getUniformVec3 ( GLuint  block,
const std::string  name,
Vec3 vec 
) const

Returns true if it can access the given uniform variable as a vector.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will read the vector as 3*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
vecThe vector to store the result
Returns
true if it can access the given uniform variable as a vector.

◆ getUniformVec3() [2/2]

bool cugl::UniformBuffer::getUniformVec3 ( GLuint  block,
GLsizei  offset,
Vec3 vec 
) const

Returns true if it can access the given uniform variable as a vector.

This method will read the vector as 3*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
vecThe vector to store the result
Returns
true if it can access the given uniform variable as a vector.

◆ getUniformVec4() [1/2]

bool cugl::UniformBuffer::getUniformVec4 ( GLuint  block,
const std::string  name,
Vec4 vec 
) const

Returns true if it can access the given uniform variable as a vector.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will read the vector as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
vecThe vector to store the result
Returns
true if it can access the given uniform variable as a vector.

◆ getUniformVec4() [2/2]

bool cugl::UniformBuffer::getUniformVec4 ( GLuint  block,
GLsizei  offset,
Vec4 vec 
) const

Returns true if it can access the given uniform variable as a vector.

This method will read the vector as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not have to be active to call this method. If it is not active and there are pending changes to this uniform variable, this method will read those changes and not the current value in the graphics card.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
vecThe vector to store the result
Returns
true if it can access the given uniform variable as a vector.

◆ init() [1/2]

bool cugl::UniformBuffer::init ( GLsizei  capacity)

Initializes this uniform buffer to support a block of the given capacity.

This uniform buffer will only support a single block. The block capacity is measured in bytes. In std140 format, all scalars are 4 bytes, vectors are 8 or 16 bytes, and matrices are treated as an array of 8 or 16 byte column vectors.

Parameters
capacityThe block capacity in bytes
Returns
true if initialization was successful.

◆ init() [2/2]

bool cugl::UniformBuffer::init ( GLsizei  capacity,
GLuint  blocks 
)

Initializes this uniform buffer to support multiple blocks of the given capacity.

The block capacity is measured in bytes. In std140 format, all scalars are 4 bytes, vectors are 8 or 16 bytes, and matrices are treated as an array of 8 or 16 byte column vectors.

Keep in mind that uniform buffer blocks must be aligned, and so this may take significantly more memory than the number of blocks times the capacity. If the graphics card cannot support that many blocks, this method will return false.

The drawtype is GL_STATIC_DRAW, GL_DYNAMIC_DRAW, or GL_STREAM_DRAW. If the uniform values change often, the difference between GL_STATIC_DRAW and GL_STREAM_DRAW is 1-2 orders of magnitude.

Parameters
capacityThe block capacity in bytes
blocksThe number of blocks to support
Returns
true if initialization was successful.

◆ isActive()

bool cugl::UniformBuffer::isActive ( ) const

Returns true if this uniform buffer is currently active.

An active uniform block is the one that pushes changes in data directly to the graphics card. If the buffer is not active, then many of the setter methods in this class will cache changes but delay applying them until the buffer is reactivated.

Unlike Texture, it is possible for a uniform buffer to be active but not bound.

Returns
true if this uniform block is currently active.

◆ isBound()

bool cugl::UniformBuffer::isBound ( ) const

Returns true if this uniform buffer is currently bound.

A uniform buffer is bound if it is attached to a bind point. That means that the shader will pull its data for that bind point from this buffer. A uniform block can be bound without being active.

Returns
true if this uniform block is currently bound.

◆ isReady()

bool cugl::UniformBuffer::isReady ( ) const
inline

Returns true if this uniform buffer has been properly initialized.

Returns
true if this uniform buffer has been properly initialized.

◆ setAutoflush()

void cugl::UniformBuffer::setAutoflush ( bool  style)
inline

Sets whether this uniform buffer supports autoflushing.

Active, auto-flushed buffers write data directly to the graphics card as soon as it is provided to the buffer. A buffer than does not auto-flush will not write to the graphics card until flush is called, even if it is active.

By default, autoflushing is turned off.

Parameters
styleWhether this uniform buffer supports autoflushing.

◆ setBindPoint()

void cugl::UniformBuffer::setBindPoint ( GLuint  point)

Sets the bind point for this uniform buffer.

Uniform buffers and shaders have a many-to-many relationship. This means that connecting them requires an intermediate table. The positions in this table are called bind points. A uniform buffer is associated with a bind point and a shader associates a bind point with a uniform struct. That uniform struct then pulls data from the active block of the uniform buffer. By default this value is 0.

The uniform buffer does not need to be active to call this method. This method only sets the bind point preference and does not actually bind the buffer. However, if the buffer is bound to another bind point, then it will be unbound from that point.

Parameters
pointThe bind point for for this uniform buffer.

◆ setBlock()

void cugl::UniformBuffer::setBlock ( GLuint  block)

Sets the active uniform block in this buffer.

The active uniform block is the block from which the shader will pull uniform values. This value can only be altered if this buffer is bound (though it need not be active).

Parameters
blockThe active uniform block in this buffer.

◆ setDrawType()

void cugl::UniformBuffer::setDrawType ( GLenum  type)
inline

Sets the draw type for this buffer

The drawtype is GL_STATIC_DRAW, GL_DYNAMIC_DRAW, or GL_STREAM_DRAW. If the uniform values change often, the difference between GL_STATIC_DRAW and GL_STREAM_DRAW is 1-2 orders of magnitude.

By default, the draw type is GL_STREAM_DRAW.

Parameters
typeThe draw type for this buffer

◆ setName()

void cugl::UniformBuffer::setName ( std::string  name)
inline

Sets the name of this uniform buffer.

A name is a user-defined way of identifying a buffer. It is typically the appropriate shader variable name, but this is not necessary for it to function properly.

Parameters
nameThe name of this uniform block.

◆ setOffset()

void cugl::UniformBuffer::setOffset ( const std::string  name,
GLsizei  offset 
)

Defines the byte offset of the given buffer variable.

It is not necessary to call this method to use the uniform buffer. It is always possible to pass data to the uniform block by specifying the byte offset. The shader uses byte offsets to pull data from the uniform buffer and assign it to the appropriate struct variable.

However, this method makes use of the uniform buffer easier to follow. It explicitly assigns a variable name to a byte offset. This variable name can now be used in place of the byte offset with passing data to this uniform block.

Use of this method does not require the uniform buffer to be bound or even active.

Parameters
nameThe variable name to use for this offset
offsetThe buffer offset in bytes

◆ setUniformAffine2() [1/2]

void cugl::UniformBuffer::setUniformAffine2 ( GLint  block,
const std::string  name,
const Affine2 mat 
)

Sets the given uniform variable to an affine transform.

Affine transforms are passed to a uniform block as a 4x3 matrix on homogenous coordinates. That is because the columns must be 4*sizeof(float) bytes for alignment reasons. The buffer must have 12*sizeof(float) bytes available for this write.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
matThe value for the uniform

◆ setUniformAffine2() [2/2]

void cugl::UniformBuffer::setUniformAffine2 ( GLint  block,
GLsizei  offset,
const Affine2 mat 
)

Sets the given uniform variable to an affine transform.

Affine transforms are passed to a uniform block as a 4x3 matrix on homogenous coordinates. That is because the columns must be 4*sizeof(float) bytes for alignment reasons. The buffer must have 12*sizeof(float) bytes available for this write.

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
matThe value for the uniform

◆ setUniformColor4() [1/2]

void cugl::UniformBuffer::setUniformColor4 ( GLint  block,
const std::string  name,
const Color4  color 
)

Sets the given uniform variable to a color value.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will write the color as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
colorThe value for the uniform

◆ setUniformColor4() [2/2]

void cugl::UniformBuffer::setUniformColor4 ( GLint  block,
GLsizei  offset,
const Color4  color 
)

Sets the given uniform variable to a color value.

This method will write the color as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
colorThe value for the uniform

◆ setUniformColor4f() [1/2]

void cugl::UniformBuffer::setUniformColor4f ( GLint  block,
const std::string  name,
const Color4f  color 
)

Sets the given uniform variable to a color value.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will write the color as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
colorThe value for the uniform

◆ setUniformColor4f() [2/2]

void cugl::UniformBuffer::setUniformColor4f ( GLint  block,
GLsizei  offset,
const Color4f  color 
)

Sets the given uniform variable to a color value.

This method will write the color as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
colorThe value for the uniform

◆ setUniformfv() [1/2]

void cugl::UniformBuffer::setUniformfv ( GLint  block,
const std::string  name,
GLsizei  size,
const GLfloat *  values 
)

Sets the given buffer location to an array of float values

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
sizeThe number of values to write to the buffer
valuesThe values to write

◆ setUniformfv() [2/2]

void cugl::UniformBuffer::setUniformfv ( GLint  block,
GLsizei  offset,
GLsizei  size,
const GLfloat *  values 
)

Sets the given buffer offset to an array of float values

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
sizeThe number of values to write to the buffer
valuesThe values to write

◆ setUniformiv() [1/2]

void cugl::UniformBuffer::setUniformiv ( GLint  block,
const std::string  name,
GLsizei  size,
const GLint *  values 
)

Sets the given buffer location to an array of integer values

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
sizeThe number of values to write to the buffer
valuesThe values to write

◆ setUniformiv() [2/2]

void cugl::UniformBuffer::setUniformiv ( GLint  block,
GLsizei  offset,
GLsizei  size,
const GLint *  values 
)

Sets the given buffer offset to an array of integer values

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
sizeThe number of values to write to the buffer
valuesThe values to write

◆ setUniformMat4() [1/2]

void cugl::UniformBuffer::setUniformMat4 ( GLint  block,
const std::string  name,
const Mat4 mat 
)

Sets the given uniform variable to a matrix value.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will write the matrix as 16*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
matThe value for the uniform

◆ setUniformMat4() [2/2]

void cugl::UniformBuffer::setUniformMat4 ( GLint  block,
GLsizei  offset,
const Mat4 mat 
)

Sets the given uniform variable to a matrix value.

This method will write the matrix as 16*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
matThe value for the uniform

◆ setUniformQuaternion() [1/2]

void cugl::UniformBuffer::setUniformQuaternion ( GLint  block,
const std::string  name,
const Quaternion quat 
)

Sets the given uniform variable to a quaternion

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will write the quaternion as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
quatThe value for the uniform

◆ setUniformQuaternion() [2/2]

void cugl::UniformBuffer::setUniformQuaternion ( GLint  block,
GLsizei  offset,
const Quaternion quat 
)

Sets the given uniform variable to a quaternion.

This method will write the quaternion as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
quatThe value for the uniform

◆ setUniformuiv() [1/2]

void cugl::UniformBuffer::setUniformuiv ( GLint  block,
const std::string  name,
GLsizei  size,
const GLuint *  values 
)

Sets the given buffer location to an array of unsigned integer values

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
sizeThe number of values to write to the buffer
valuesThe values to write

◆ setUniformuiv() [2/2]

void cugl::UniformBuffer::setUniformuiv ( GLint  block,
GLsizei  offset,
GLsizei  size,
const GLuint *  values 
)

Sets the given buffer offset to an array of unsigned integer values

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
sizeThe number of values to write to the buffer
valuesThe values to write

◆ setUniformVec2() [1/2]

void cugl::UniformBuffer::setUniformVec2 ( GLint  block,
const std::string  name,
const Vec2  vec 
)

Sets the given uniform variable to a vector value.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will write the vector as 2*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
vecThe value for the uniform

◆ setUniformVec2() [2/2]

void cugl::UniformBuffer::setUniformVec2 ( GLint  block,
GLsizei  offset,
const Vec2  vec 
)

Sets the given uniform variable to a vector value.

This method will write the vector as 2*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
vecThe value for the uniform

◆ setUniformVec3() [1/2]

void cugl::UniformBuffer::setUniformVec3 ( GLint  block,
const std::string  name,
const Vec3  vec 
)

Sets the given uniform variable to a vector value.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will write the vector as 3*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

The buffer does not need to be active to call this method. However, changes made while the buffer is inactive will be cached and not applied until the buffer is reactivated.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
vecThe value for the uniform

◆ setUniformVec3() [2/2]

void cugl::UniformBuffer::setUniformVec3 ( GLint  block,
GLsizei  offset,
const Vec3  vec 
)

Sets the given uniform variable to a vector value.

This method will write the vector as 3*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
vecThe value for the uniform

◆ setUniformVec4() [1/2]

void cugl::UniformBuffer::setUniformVec4 ( GLint  block,
const std::string  name,
const Vec4  vec 
)

Sets the given uniform variable to a vector value.

This method requires that the uniform name be previously bound to a byte offset with the call setOffset. This method will write the vector as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
nameThe name of the uniform variable
vecThe value for the uniform

◆ setUniformVec4() [2/2]

void cugl::UniformBuffer::setUniformVec4 ( GLint  block,
GLsizei  offset,
const Vec4  vec 
)

Sets the given uniform variable to a vector value.

This method will write the vector as 4*sizeof(float) bytes to the appropriate buffer location (and the buffer must have the appropriate capacity).

Values set by this method will not be sent to the graphics card until the buffer is flushed. However, if the buffer is active and auto-flush is turned on, it will be written immediately.

If block is -1, it sets this value in every block in this uniform buffer. This is a potentially expensive operation if the block is active. For mass changes, it is better to deactivate the buffer, and have them apply once the buffer is reactivated.

Parameters
blockThe block in this uniform buffer to access
offsetThe offset within the block
vecThe value for the uniform

◆ unbind()

void cugl::UniformBuffer::unbind ( )

Unbinds this uniform buffer disassociating it from its bind point.

This call will have no affect on the active buffer (e.g. which buffer is receiving data from the program). This method simply removes this buffer from its bind point.

Once unbound, the bind point for this buffer will no longer send data to the appropriate uniform(s) in the shader. In that case the shader will use default values according to the variable types.

This call is reentrant. If can be safely called multiple times.

Member Data Documentation

◆ INVALID_OFFSET

GLsizei cugl::UniformBuffer::INVALID_OFFSET
static

The byte position of an invalid offset


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