CUGL 2.3
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::Shader Class Reference

#include <CUShader.h>

Public Member Functions

 Shader ()
 
 ~Shader ()
 
virtual void dispose ()
 
bool init (const std::string vsource, std::string fsource)
 
void bind ()
 
void unbind ()
 
bool isReady () const
 
bool isBound () const
 
const std::string getVertSource () const
 
const std::string getFragSource () const
 
GLuint getProgram () const
 
std::vector< std::string > getAttributes () const
 
GLint getAttributeLocation (const std::string name) const
 
GLint getAttributeSize (const std::string name) const
 
GLenum getAttributeType (const std::string name) const
 
GLint getOutputLocation (const std::string name) const
 
std::vector< std::string > getUniforms () const
 
GLint getUniformLocation (const std::string name) const
 
GLint getUniformSize (const std::string name) const
 
GLenum getUniformType (const std::string name) const
 
std::vector< std::string > getSamplers () const
 
GLint getSamplerLocation (const std::string name) const
 
void setSampler (GLint pos, GLuint bpoint)
 
void setSampler (const std::string name, GLuint bpoint)
 
void setSampler (GLint pos, const std::shared_ptr< Texture > &texture)
 
void setSampler (const std::string name, const std::shared_ptr< Texture > &texture)
 
GLuint getSampler (GLint pos) const
 
GLuint getSampler (const std::string name) const
 
std::vector< std::string > getUniformBlocks () const
 
std::vector< std::string > getUniformsForBlock (GLint pos) const
 
std::vector< std::string > getUniformsForBlock (std::string name) const
 
void setUniformBlock (GLint pos, GLuint bpoint)
 
void setUniformBlock (const std::string name, GLuint bpoint)
 
void setUniformBlock (GLint pos, const std::shared_ptr< UniformBuffer > &buffer)
 
void setUniformBlock (const std::string name, const std::shared_ptr< UniformBuffer > &buffer)
 
GLuint getUniformBlock (GLint pos) const
 
GLuint getUniformBlock (const std::string name) const
 
void setUniformVec2 (GLint pos, const Vec2 vec)
 
void setUniformVec2 (const std::string name, const Vec2 vec)
 
bool getUniformVec2 (GLint pos, Vec2 &vec) const
 
bool getUniformVec2 (const std::string name, Vec2 &vec) const
 
void setUniformVec3 (GLint pos, const Vec3 vec)
 
void setUniformVec3 (const std::string name, const Vec3 vec)
 
bool getUniformVec3 (GLint pos, Vec3 &vec) const
 
bool getUniformVec3 (const std::string name, Vec3 &vec) const
 
void setUniformVec4 (GLint pos, const Vec4 vec)
 
void setUniformVec4 (const std::string name, const Vec4 vec)
 
bool getUniformVec4 (GLint pos, Vec4 &vec) const
 
bool getUniformVec4 (const std::string name, Vec4 &vec) const
 
void setUniformColor4 (GLint pos, const Color4 color)
 
void setUniformColor4 (const std::string name, const Color4 color)
 
bool getUniformColor4 (GLint pos, Color4 &color) const
 
bool getUniformColor4 (const std::string name, Color4 &color) const
 
void setUniformColor4f (GLint pos, const Color4f color)
 
void setUniformColor4f (const std::string name, const Color4f color)
 
bool getUniformColor4f (GLint pos, Color4f &color) const
 
bool getUniformColor4f (const std::string name, Color4f &color) const
 
void setUniformMat4 (GLint pos, const Mat4 &mat)
 
void setUniformMat4 (const std::string name, const Mat4 &mat)
 
bool getUniformMat4 (GLint pos, Mat4 &mat) const
 
bool getUniformMat4 (const std::string name, Mat4 &mat) const
 
void setUniformAffine2 (GLint pos, const Affine2 &mat)
 
void setUniformAffine2 (const std::string name, const Affine2 &mat)
 
bool getUniformAffine2 (GLint pos, Affine2 &mat) const
 
bool getUniformAffine2 (const std::string name, Affine2 &mat) const
 
void setUniformQuaternion (GLint pos, const Quaternion &quat)
 
void setUniformQuaternion (const std::string name, const Quaternion &quat)
 
bool getUniformQuaternion (GLint pos, Quaternion &quat) const
 
bool getUniformQuaternion (const std::string name, Quaternion &quat) const
 
void setUniform1f (GLint pos, GLfloat v0)
 
void setUniform1f (const std::string name, GLfloat v0)
 
void setUniform2f (GLint pos, GLfloat v0, GLfloat v1)
 
void setUniform2f (const std::string name, GLfloat v0, GLfloat v1)
 
void setUniform3f (GLint pos, GLfloat v0, GLfloat v1, GLfloat v2)
 
void setUniform3f (const std::string name, GLfloat v0, GLfloat v1, GLfloat v2)
 
void setUniform4f (GLint pos, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
 
void setUniform4f (const std::string name, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
 
void setUniform1i (GLint pos, GLint v0)
 
void setUniform1i (const std::string name, GLint v0)
 
void setUniform2i (GLint pos, GLint v0, GLint v1)
 
void setUniform2i (const std::string name, GLint v0, GLint v1)
 
void setUniform3i (GLint pos, GLint v0, GLint v1, GLint v2)
 
void setUniform3i (const std::string name, GLint v0, GLint v1, GLint v2)
 
void setUniform4i (GLint pos, GLint v0, GLint v1, GLint v2, GLint v3)
 
void setUniform4i (const std::string name, GLint v0, GLint v1, GLint v2, GLint v3)
 
void setUniform1ui (GLint pos, GLuint v0)
 
void setUniform1ui (const std::string name, GLuint v0)
 
void setUniform2ui (GLint pos, GLuint v0, GLuint v1)
 
void setUniform2ui (const std::string name, GLuint v0, GLuint v1)
 
void setUniform3ui (GLint pos, GLuint v0, GLuint v1, GLuint v2)
 
void setUniform3ui (const std::string name, GLuint v0, GLuint v1, GLuint v2)
 
void setUniform4ui (GLint pos, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
 
void setUniform4ui (const std::string name, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
 
void setUniform1fv (GLint pos, GLsizei count, const GLfloat *value)
 
void setUniform1fv (const std::string name, GLsizei count, const GLfloat *value)
 
void setUniform2fv (GLint pos, GLsizei count, const GLfloat *value)
 
void setUniform2fv (const std::string name, GLsizei count, const GLfloat *value)
 
void setUniform3fv (GLint pos, GLsizei count, const GLfloat *value)
 
void setUniform3fv (const std::string name, GLsizei count, const GLfloat *value)
 
void setUniform4fv (GLint pos, GLsizei count, const GLfloat *value)
 
void setUniform4fv (const std::string name, GLsizei count, const GLfloat *value)
 
void setUniform1iv (GLint pos, GLsizei count, const GLint *value)
 
void setUniform1iv (const std::string name, GLsizei count, const GLint *value)
 
void setUniform2iv (GLint pos, GLsizei count, const GLint *value)
 
void setUniform2iv (const std::string name, GLsizei count, const GLint *value)
 
void setUniform3iv (GLint pos, GLsizei count, const GLint *value)
 
void setUniform3iv (const std::string name, GLsizei count, const GLint *value)
 
void setUniform4iv (GLint pos, GLsizei count, const GLint *value)
 
void setUniform4iv (const std::string name, GLsizei count, const GLint *value)
 
void setUniform1uiv (GLint pos, GLsizei count, const GLuint *value)
 
void setUniform1uiv (const std::string name, GLsizei count, const GLuint *value)
 
void setUniform2uiv (GLint pos, GLsizei count, const GLuint *value)
 
void setUniform2uiv (const std::string name, GLsizei count, const GLuint *value)
 
void setUniform3uiv (GLint pos, GLsizei count, const GLuint *value)
 
void setUniform3uiv (const std::string name, GLsizei count, const GLuint *value)
 
void setUniform4uiv (GLint pos, GLsizei count, const GLuint *value)
 
void setUniform4uiv (const std::string name, GLsizei count, const GLuint *value)
 
void setUniformMatrix2fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix2fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix3fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix3fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix4fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix4fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix2x3fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix2x3fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix3x2fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix3x2fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix2x4fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix2x4fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix4x2fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix4x2fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix3x4fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix3x4fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix4x3fv (GLint pos, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
void setUniformMatrix4x3fv (const std::string name, GLsizei count, const GLfloat *value, GLboolean tpose=false)
 
bool getUniformfv (GLint pos, GLsizei size, GLfloat *value) const
 
bool getUniformfv (const std::string name, GLsizei size, GLfloat *value) const
 
bool getUniformiv (GLint pos, GLsizei size, GLint *value) const
 
bool getUniformiv (const std::string name, GLsizei size, GLint *value) const
 
bool getUniformuiv (GLint pos, GLsizei size, GLuint *value) const
 
bool getUniformuiv (const std::string name, GLsizei size, GLuint *value) const
 

Static Public Member Functions

static std::shared_ptr< Shaderalloc (const std::string vsource, std::string fsource)
 

Protected Attributes

GLuint _program
 
GLuint _vertShader
 
GLuint _fragShader
 
std::string _vertSource
 
std::string _fragSource
 
std::unordered_map< std::string, GLenum > _attribtypes
 
std::unordered_map< GLint, std::string > _attribnames
 
std::unordered_map< std::string, GLint > _attribsizes
 
std::unordered_map< std::string, GLenum > _uniformtypes
 
std::unordered_map< GLint, std::string > _uniformnames
 
std::unordered_map< std::string, GLint > _uniformsizes
 
std::unordered_map< GLint, std::string > _uniblocknames
 
std::unordered_map< std::string, GLint > _uniblocksizes
 
std::unordered_map< GLint, GLint > _uniblockfields
 

Detailed Description

This class defines a GLSL shader.

This class compiles and links any well-defined GLSL shader. It also has methods for querying and binding the shader. The class is written to be agnostic about whether we are using OpenGL or OpenGLES.

However, a shader cannot be used by itself. To use a shader, it must first be attached to a VertexBuffer. When using a shader, with a vertex buffer keep in mind the "performance hit" hierarchy. From our experiments, the cost of changing data in a rendering phase going from most expensive to cheapest is as follows:

By vertex stream we mean the act of loading data into a vertex buffer. Since the cost of swapping a vertex buffer is more expensive that reloading data into it, a vertex buffer should only be swapped when the format of the vertex data changes.

Uniforms tend to be fairly cheap. However, some uniforms are samplers and those are incredibly expensive to change. A sampler is a uniform that is bound to a texture bind point. Because of how textures are loaded, it is (much) cheaper to activate a texture to an existing bind point than it is to change the bind point used in the shader.

Even the most basic uniforms are by no means cheap. The best case graphics performance is when you can load the vertex buffer once and then call a single draw command for all of the vertices (the difference is an order of magnitude).
Therefore, any properties that space only a few vertices (e.g. quads) should be pushed into the vertex data itself. For example, it is faster to transform quads in the CPU than it is in the GPU.

Because of the limitations of OpenGLES, this class only supports vertex and fragment shaders – it does not support tesselation or geometry shaders.
Furthermore, keep in mind that Apple has deprecated OpenGL. MacOS devices are stuck at OpenGL 4.1 and iOS devices are stuck at OpenGLES 3.0. So it is not safe to use any shader more recent than version 140 on desktop/laptop and version 300 on mobile.

Another side effect of OpenGLES is that this class does not support explicit binding of multiple output locations (glBindFragDataLocation). If a shader has multiple output targets, then these must be explicitly managed inside the shader with the layout keyword. Otherwise, the output bind points from the appropriate query methods.

Constructor & Destructor Documentation

◆ Shader()

cugl::Shader::Shader ( )
inline

Creates an uninitialized shader with no source.

You must initialize the shader to add a source and compile it.

◆ ~Shader()

cugl::Shader::~Shader ( )
inline

Deletes this shader, disposing all resources.

Member Function Documentation

◆ alloc()

static std::shared_ptr< Shader > cugl::Shader::alloc ( const std::string  vsource,
std::string  fsource 
)
inlinestatic

Returns a new shader with the given vertex and fragment source.

The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will be bound and active.

Parameters
vsourceThe source string for the vertex shader.
fsourceThe source string for the fragment shader.
Returns
a new shader with the given vertex and fragment source.

◆ bind()

void cugl::Shader::bind ( )

Binds this shader, making it active.

Once bound, any OpenGL calls will then be sent to this shader. This call is reentrant, and may safely be called on an active shader.

◆ dispose()

virtual void cugl::Shader::dispose ( )
virtual

Deletes the OpenGL shader and resets all attributes.

You must reinitialize the shader to use it.

◆ getAttributeLocation()

GLint cugl::Shader::getAttributeLocation ( const std::string  name) const

Returns the program offset of the given attribute

If name is not a valid attribute, this method returns -1.

Parameters
nameThe attribute variable name
Returns
the program offset of the given attribute

◆ getAttributes()

std::vector< std::string > cugl::Shader::getAttributes ( ) const

Returns a vector of all attribute variables in this shader

Returns
a vector of all attribute variables in this shader

◆ getAttributeSize()

GLint cugl::Shader::getAttributeSize ( const std::string  name) const

Returns the size (in bytes) of the given attribute

If name is not a valid attribute, this method returns -1.

Parameters
nameThe attribute variable name
Returns
the size (in bytes) of the given attribute

◆ getAttributeType()

GLenum cugl::Shader::getAttributeType ( const std::string  name) const

Returns the type of the given attribute

If name is not a valid attribute, this method returns GL_FALSE.

Parameters
nameThe attribute variable name
Returns
the type of the given attribute

◆ getFragSource()

const std::string cugl::Shader::getFragSource ( ) const
inline

Returns the source string for the fragment shader.

The string is empty if not defined.

Returns
the source string for the fragment shader.

◆ getOutputLocation()

GLint cugl::Shader::getOutputLocation ( const std::string  name) const

Returns the program offset of the given output variable.

An output variable is a variable in a fragment shader that writes to a texture. All shaders have at least one output variable. However, shaders can have more than one output variable, particularly when used in conjunction with a RenderTarget. This method is helpful for getting the number and names of these variables for setting up a RenderTarget.

To explicit set the program offset of an output variable, the shader should use the layout keyword in GLSL. Because of compatibility issues with Apple products (iOS, MacOS), it is not possible to get much information about output variables other than their location.

If name is not a valid output variable, this method returns -1.

Parameters
nameThe output variable name
Returns
the program offset of the given output variable.

◆ getProgram()

GLuint cugl::Shader::getProgram ( ) const
inline

Returns the OpenGL program associated with this shader.

This method will return 0 if the program is not initialized.

Returns
the OpenGL program associated with this shader.

◆ getSampler() [1/2]

GLuint cugl::Shader::getSampler ( const std::string  name) const

Returns the texture bindpoint associated with the given sampler variable.

The shader does not track the actual texture associated with this bindpoint, only the bindpoint itself. It is up to the software developer to keep track of what texture is currently at that bindpoint.

Parameters
nameThe name of the sampler variable
Returns
the texture bindpoint associated with the given sampler variable.

◆ getSampler() [2/2]

GLuint cugl::Shader::getSampler ( GLint  pos) const

Returns the texture bindpoint associated with the given sampler variable.

The shader does not track the actual texture associated with this bindpoint, only the bindpoint itself. It is up to the software developer to keep track of what texture is currently at that bindpoint.

Parameters
posThe location of the sampler in the shader
Returns
the texture bindpoint associated with the given sampler variable.

◆ getSamplerLocation()

GLint cugl::Shader::getSamplerLocation ( const std::string  name) const

Returns the program offset of the given sampler variable

A sampler is a variable attached to a texture. All samplers are also uniforms. Therefore this method has the same effect as the method getUniformLocation.

If name is not a valid sampler, this method returns -1.

Parameters
nameThe sampler variable name
Returns
the program offset of the given sampler variable

◆ getSamplers()

std::vector< std::string > cugl::Shader::getSamplers ( ) const

Returns a vector of all samplers used by this shader

A sampler is a variable attached to a texture. All samplers are also uniforms. Therefore this vector is a subset of the names returned by getUniforms.

Returns
a vector of all samplers used by this shader

◆ getUniformAffine2() [1/2]

bool cugl::Shader::getUniformAffine2 ( const std::string  name,
Affine2 mat 
) const

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

Affine transforms are read from a shader as a 3x3 matrix on homogenous coordinates. This method will only succeed if the shader is actively bound. It assumes that the shader variable is a mat3 (or larger).

Parameters
nameThe name of the uniform
matThe object to store the result
Returns
true if it can access the given uniform as an affine transform.

◆ getUniformAffine2() [2/2]

bool cugl::Shader::getUniformAffine2 ( GLint  pos,
Affine2 mat 
) const

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

Affine transforms are read from a shader as a 3x3 matrix on homogenous coordinates. This method will only succeed if the shader is actively bound. It assumes that the shader variable is a mat3 (or larger).

Parameters
posThe location of the uniform in the shader
matThe object to store the result
Returns
true if it can access the given uniform as an affine transform.

◆ getUniformBlock() [1/2]

GLuint cugl::Shader::getUniformBlock ( const std::string  name) const

Returns the buffer bindpoint associated with the given uniform block.

The shader does not track the actual uniform buffer associated with this bindpoint, only the bindpoint itself. It is up to the software developer to keep track of what uniform buffer is currently at that bindpoint.

Parameters
nameThe name of the uniform block in the shader
Returns
the buffer bindpoint associated with the given uniform block.

◆ getUniformBlock() [2/2]

GLuint cugl::Shader::getUniformBlock ( GLint  pos) const

Returns the buffer bindpoint associated with the given uniform block.

The shader does not track the actual uniform buffer associated with this bindpoint, only the bindpoint itself. It is up to the software developer to keep track of what uniform buffer is currently at that bindpoint.

Parameters
posThe location of the uniform block in the shader
Returns
the buffer bindpoint associated with the given uniform block.

◆ getUniformBlocks()

std::vector< std::string > cugl::Shader::getUniformBlocks ( ) const

Returns a vector of all uniform blocks used by this shader

A uniform block is a variable attached to a uniform buffer. It is not the same as a normal uniform and cannot be treated as such. In this case the uniform values are set in the UniformBuffer object and not the shader.

Returns
a vector of all uniform blocks used by this shader

◆ getUniformColor4() [1/2]

bool cugl::Shader::getUniformColor4 ( const std::string  name,
Color4 color 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec4 (or larger).

Parameters
nameThe name of the uniform
colorThe object to store the result
Returns
true if it can access the given uniform as a color.

◆ getUniformColor4() [2/2]

bool cugl::Shader::getUniformColor4 ( GLint  pos,
Color4 color 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec4 (or larger).

Parameters
posThe location of the uniform in the shader
colorThe object to store the result
Returns
true if it can access the given uniform as a color.

◆ getUniformColor4f() [1/2]

bool cugl::Shader::getUniformColor4f ( const std::string  name,
Color4f color 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec4 (or larger).

Parameters
nameThe name of the uniform
colorThe object to store the result
Returns
true if it can access the given uniform as a color.

◆ getUniformColor4f() [2/2]

bool cugl::Shader::getUniformColor4f ( GLint  pos,
Color4f color 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec4 (or larger).

Parameters
posThe location of the uniform in the shader
colorThe object to store the result
Returns
true if it can access the given uniform as a color.

◆ getUniformfv() [1/2]

bool cugl::Shader::getUniformfv ( const std::string  name,
GLsizei  size,
GLfloat *  value 
) const

Gets the given uniform as an array of float values

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
sizeThe available size of the value array
valueThe array to receive the values
Returns
true if data was successfully read into value

◆ getUniformfv() [2/2]

bool cugl::Shader::getUniformfv ( GLint  pos,
GLsizei  size,
GLfloat *  value 
) const

Gets the given uniform as an array of float values

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
sizeThe available size of the value array
valueThe array to receive the values
Returns
true if data was successfully read into value

◆ getUniformiv() [1/2]

bool cugl::Shader::getUniformiv ( const std::string  name,
GLsizei  size,
GLint *  value 
) const

Gets the given uniform as an array of integer values

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
sizeThe available size of the value array
valueThe array to receive the values
Returns
true if data was successfully read into value

◆ getUniformiv() [2/2]

bool cugl::Shader::getUniformiv ( GLint  pos,
GLsizei  size,
GLint *  value 
) const

Gets the given uniform as an array of integer values

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
sizeThe available size of the value array
valueThe array to receive the values
Returns
true if data was successfully read into value

◆ getUniformLocation()

GLint cugl::Shader::getUniformLocation ( const std::string  name) const

Returns the program offset of the given uniform

If name is not a valid uniform, this method returns -1.

Parameters
nameThe uniform variable name
Returns
the program offset of the given uniform

◆ getUniformMat4() [1/2]

bool cugl::Shader::getUniformMat4 ( const std::string  name,
Mat4 mat 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a mat4 (or larger).

Parameters
nameThe name of the uniform
matThe object to store the result
Returns
true if it can access the given uniform as a matrix.

◆ getUniformMat4() [2/2]

bool cugl::Shader::getUniformMat4 ( GLint  pos,
Mat4 mat 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a mat4 (or larger).

Parameters
posThe location of the uniform in the shader
matThe object to store the result
Returns
true if it can access the given uniform as a matrix.

◆ getUniformQuaternion() [1/2]

bool cugl::Shader::getUniformQuaternion ( const std::string  name,
Quaternion quat 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec4 (or larger).

Parameters
nameThe name of the uniform
quatThe quaternion to store the result
Returns
true if it can access the given uniform as a quaternion.

◆ getUniformQuaternion() [2/2]

bool cugl::Shader::getUniformQuaternion ( GLint  pos,
Quaternion quat 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec4 (or larger).

Parameters
posThe location of the uniform in the shader
quatThe quaternion to store the result
Returns
true if it can access the given uniform as a quaternion.

◆ getUniforms()

std::vector< std::string > cugl::Shader::getUniforms ( ) const

Returns a vector of all uniform variables in this shader

Returns
a vector of all uniform variables in this shader

◆ getUniformsForBlock() [1/2]

std::vector< std::string > cugl::Shader::getUniformsForBlock ( GLint  pos) const

Returns a vector of all uniforms for the given block.

A uniform block is a variable attached to a uniform buffer. It is not the same as a normal uniform and cannot be treated as such. In this case the uniform values are set in the UniformBuffer object and not the shader.

This method allows us to verify that at UniformBuffer object properly matches this shader.

Parameters
posThe location of the uniform block in the shader
Returns
a vector of all uniform blocks used by this shader

◆ getUniformsForBlock() [2/2]

std::vector< std::string > cugl::Shader::getUniformsForBlock ( std::string  name) const

Returns a vector of all uniforms for the given block.

A uniform block is a variable attached to a uniform buffer. It is not the same as a normal uniform and cannot be treated as such. In this case the uniform values are set in the UniformBuffer object and not the shader.

This method allows us to verify that at UniformBuffer object properly matches this shader.

Parameters
nameThe name of the uniform block in the shader
Returns
a vector of all uniform blocks used by this shader

◆ getUniformSize()

GLint cugl::Shader::getUniformSize ( const std::string  name) const

Returns the size (in bytes) of the given uniform

If name is not a valid uniform, this method returns -1.

Parameters
nameThe uniform variable name
Returns
the size (in bytes) of the given uniform

◆ getUniformType()

GLenum cugl::Shader::getUniformType ( const std::string  name) const

Returns the type of the given uniform

If name is not a valid uniform, this method returns GL_FALSE.

Parameters
nameThe uniform variable name
Returns
the type of the given uniform

◆ getUniformuiv() [1/2]

bool cugl::Shader::getUniformuiv ( const std::string  name,
GLsizei  size,
GLuint *  value 
) const

Gets the given uniform as an array of unsigned integer values

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
sizeThe available size of the value array
valueThe array to receive the values
Returns
true if data was successfully read into value

◆ getUniformuiv() [2/2]

bool cugl::Shader::getUniformuiv ( GLint  pos,
GLsizei  size,
GLuint *  value 
) const

Gets the given uniform as an array of unsigned integer values

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
sizeThe available size of the value array
valueThe array to receive the values
Returns
true if data was successfully read into value

◆ getUniformVec2() [1/2]

bool cugl::Shader::getUniformVec2 ( const std::string  name,
Vec2 vec 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec2 (or larger).

Parameters
nameThe name of the uniform
vecThe vector to store the result
Returns
true if it can access the given uniform as a vector.

◆ getUniformVec2() [2/2]

bool cugl::Shader::getUniformVec2 ( GLint  pos,
Vec2 vec 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec2 (or larger).

Parameters
posThe location of the uniform in the shader
vecThe vector to store the result
Returns
true if it can access the given uniform as a vector.

◆ getUniformVec3() [1/2]

bool cugl::Shader::getUniformVec3 ( const std::string  name,
Vec3 vec 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec3 (or larger).

Parameters
nameThe name of the uniform
vecThe vector to store the result
Returns
true if it can access the given uniform as a vector.

◆ getUniformVec3() [2/2]

bool cugl::Shader::getUniformVec3 ( GLint  pos,
Vec3 vec 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec3 (or larger).

Parameters
posThe location of the uniform in the shader
vecThe vector to store the result
Returns
true if it can access the given uniform as a vector.

◆ getUniformVec4() [1/2]

bool cugl::Shader::getUniformVec4 ( const std::string  name,
Vec4 vec 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec4 (or larger).

Parameters
nameThe name of the uniform
vecThe vector to store the result
Returns
true if it can access the given uniform as a vector.

◆ getUniformVec4() [2/2]

bool cugl::Shader::getUniformVec4 ( GLint  pos,
Vec4 vec 
) const

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

This method will only succeed if the shader is actively bound. It assumes that the shader variable is a vec4 (or larger).

Parameters
posThe location of the uniform in the shader
vecThe vector to store the result
Returns
true if it can access the given uniform as a vector.

◆ getVertSource()

const std::string cugl::Shader::getVertSource ( ) const
inline

Returns the source string for the vertex shader.

The string is empty if not defined.

Returns
the source string for the vertex shader.

◆ init()

bool cugl::Shader::init ( const std::string  vsource,
std::string  fsource 
)

Initializes this shader with the given vertex and fragment source.

The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will be bound and active.

Parameters
vsourceThe source string for the vertex shader.
fsourceThe source string for the fragment shader.
Returns
true if initialization was successful.

◆ isBound()

bool cugl::Shader::isBound ( ) const

Returns true if this shader is currently bound.

Any OpenGL calls will be sent to this shader only if it is bound.

Returns
true if this shader is currently bound.

◆ isReady()

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

Returns true if this shader has been compiled and is ready for use.

Returns
true if this shader has been compiled and is ready for use.

◆ setSampler() [1/4]

void cugl::Shader::setSampler ( const std::string  name,
const std::shared_ptr< Texture > &  texture 
)

Sets the given sampler variable to the bindpoint of the given texture.

A sampler is a variable attached to a texture. All samplers are also uniforms. Therefore this method has the same effect as the method setUniform1ui.

This method will bind the sampler to the current bindpoint of the texture. The shader will not be aware if the texture changes its bindpoint in the future.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the sampler variable
textureThe texture to initialize the bindpoint

◆ setSampler() [2/4]

void cugl::Shader::setSampler ( const std::string  name,
GLuint  bpoint 
)

Sets the given sampler variable to a texture bindpoint.

A sampler is a variable attached to a texture. All samplers are also uniforms. Therefore this method has the same effect as the method setUniform1ui.

This method will only succeed if the shader is actively bound.

Note that changing this value is causes a significant performance hit to a shader. Whenever possible, it is better to keep the bindpoint the same while binding a different texture to the same point.

Parameters
nameThe name of the sampler variable
bpointThe bindpoint for the sampler

◆ setSampler() [3/4]

void cugl::Shader::setSampler ( GLint  pos,
const std::shared_ptr< Texture > &  texture 
)

Sets the given sampler variable to the bindpoint of the given texture.

A sampler is a variable attached to a texture. All samplers are also uniforms. Therefore this method has the same effect as the method setUniform1ui.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the sampler in the shader
textureThe texture to initialize the bindpoint

◆ setSampler() [4/4]

void cugl::Shader::setSampler ( GLint  pos,
GLuint  bpoint 
)

Sets the given sampler variable to a texture bindpoint.

A sampler is a variable attached to a texture. All samplers are also uniforms. Therefore this method has the same effect as the method setUniform1ui.

This method will only succeed if the shader is actively bound.

Note that changing this value is causes a significant performance hit to a shader. Whenever possible, it is better to keep the bindpoint the same while binding a different texture to the same point.

Parameters
posThe location of the sampler in the shader
bpointThe bindpoint for the sampler

◆ setUniform1f() [1/2]

void cugl::Shader::setUniform1f ( const std::string  name,
GLfloat  v0 
)

Sets the given uniform to a single float value.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The value for the uniform

◆ setUniform1f() [2/2]

void cugl::Shader::setUniform1f ( GLint  pos,
GLfloat  v0 
)

Sets the given uniform to a single float value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The value for the uniform

◆ setUniform1fv() [1/2]

void cugl::Shader::setUniform1fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value 
)

Sets the given uniform to an array of 1-element floats.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of floats

◆ setUniform1fv() [2/2]

void cugl::Shader::setUniform1fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value 
)

Sets the given uniform to an array of 1-element floats.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of floats

◆ setUniform1i() [1/2]

void cugl::Shader::setUniform1i ( const std::string  name,
GLint  v0 
)

Sets the given uniform to a single int value.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The value for the uniform

◆ setUniform1i() [2/2]

void cugl::Shader::setUniform1i ( GLint  pos,
GLint  v0 
)

Sets the given uniform to a single int value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The value for the uniform

◆ setUniform1iv() [1/2]

void cugl::Shader::setUniform1iv ( const std::string  name,
GLsizei  count,
const GLint *  value 
)

Sets the given uniform to an array of 1-element ints.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of ints

◆ setUniform1iv() [2/2]

void cugl::Shader::setUniform1iv ( GLint  pos,
GLsizei  count,
const GLint *  value 
)

Sets the given uniform to an array of 1-element ints.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of ints

◆ setUniform1ui() [1/2]

void cugl::Shader::setUniform1ui ( const std::string  name,
GLuint  v0 
)

Sets the given uniform to a single unsigned value.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The value for the uniform

◆ setUniform1ui() [2/2]

void cugl::Shader::setUniform1ui ( GLint  pos,
GLuint  v0 
)

Sets the given uniform to a single unsigned value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The value for the uniform

◆ setUniform1uiv() [1/2]

void cugl::Shader::setUniform1uiv ( const std::string  name,
GLsizei  count,
const GLuint *  value 
)

Sets the given uniform to an array of 1-element unsigned ints.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of unsigned ints

◆ setUniform1uiv() [2/2]

void cugl::Shader::setUniform1uiv ( GLint  pos,
GLsizei  count,
const GLuint *  value 
)

Sets the given uniform to an array of 1-element unsigned ints.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of unsigned ints

◆ setUniform2f() [1/2]

void cugl::Shader::setUniform2f ( const std::string  name,
GLfloat  v0,
GLfloat  v1 
)

Sets the given uniform to a pair of float values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform

◆ setUniform2f() [2/2]

void cugl::Shader::setUniform2f ( GLint  pos,
GLfloat  v0,
GLfloat  v1 
)

Sets the given uniform to a pair of float values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform

◆ setUniform2fv() [1/2]

void cugl::Shader::setUniform2fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value 
)

Sets the given uniform to an array of 2-element floats.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of floats

◆ setUniform2fv() [2/2]

void cugl::Shader::setUniform2fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value 
)

Sets the given uniform to an array of 2-element floats.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of floats

◆ setUniform2i() [1/2]

void cugl::Shader::setUniform2i ( const std::string  name,
GLint  v0,
GLint  v1 
)

Sets the given uniform to a pair of int values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform

◆ setUniform2i() [2/2]

void cugl::Shader::setUniform2i ( GLint  pos,
GLint  v0,
GLint  v1 
)

Sets the given uniform to a pair of int values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform

◆ setUniform2iv() [1/2]

void cugl::Shader::setUniform2iv ( const std::string  name,
GLsizei  count,
const GLint *  value 
)

Sets the given uniform to an array of 2-element ints.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of ints

◆ setUniform2iv() [2/2]

void cugl::Shader::setUniform2iv ( GLint  pos,
GLsizei  count,
const GLint *  value 
)

Sets the given uniform to an array of 2-element ints.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of ints

◆ setUniform2ui() [1/2]

void cugl::Shader::setUniform2ui ( const std::string  name,
GLuint  v0,
GLuint  v1 
)

Sets the given uniform to a pair of unsigned values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform

◆ setUniform2ui() [2/2]

void cugl::Shader::setUniform2ui ( GLint  pos,
GLuint  v0,
GLuint  v1 
)

Sets the given uniform to a pair of unsigned values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform

◆ setUniform2uiv() [1/2]

void cugl::Shader::setUniform2uiv ( const std::string  name,
GLsizei  count,
const GLuint *  value 
)

Sets the given uniform to an array of 2-element unsigned ints.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of unsigned ints

◆ setUniform2uiv() [2/2]

void cugl::Shader::setUniform2uiv ( GLint  pos,
GLsizei  count,
const GLuint *  value 
)

Sets the given uniform to an array of 2-element unsigned ints.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of unsigned ints

◆ setUniform3f() [1/2]

void cugl::Shader::setUniform3f ( const std::string  name,
GLfloat  v0,
GLfloat  v1,
GLfloat  v2 
)

Sets the given uniform to a trio of float values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform

◆ setUniform3f() [2/2]

void cugl::Shader::setUniform3f ( GLint  pos,
GLfloat  v0,
GLfloat  v1,
GLfloat  v2 
)

Sets the given uniform to a trio of float values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform

◆ setUniform3fv() [1/2]

void cugl::Shader::setUniform3fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value 
)

Sets the given uniform to an array of 3-element floats.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of floats

◆ setUniform3fv() [2/2]

void cugl::Shader::setUniform3fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value 
)

Sets the given uniform to an array of 3-element floats.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of floats

◆ setUniform3i() [1/2]

void cugl::Shader::setUniform3i ( const std::string  name,
GLint  v0,
GLint  v1,
GLint  v2 
)

Sets the given uniform to a trio of int values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform

◆ setUniform3i() [2/2]

void cugl::Shader::setUniform3i ( GLint  pos,
GLint  v0,
GLint  v1,
GLint  v2 
)

Sets the given uniform to a trio of int values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform

◆ setUniform3iv() [1/2]

void cugl::Shader::setUniform3iv ( const std::string  name,
GLsizei  count,
const GLint *  value 
)

Sets the given uniform to an array of 3-element ints.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of ints

◆ setUniform3iv() [2/2]

void cugl::Shader::setUniform3iv ( GLint  pos,
GLsizei  count,
const GLint *  value 
)

Sets the given uniform to an array of 3-element ints.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of ints

◆ setUniform3ui() [1/2]

void cugl::Shader::setUniform3ui ( const std::string  name,
GLuint  v0,
GLuint  v1,
GLuint  v2 
)

Sets the given uniform to a trio of unsigned values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform

◆ setUniform3ui() [2/2]

void cugl::Shader::setUniform3ui ( GLint  pos,
GLuint  v0,
GLuint  v1,
GLuint  v2 
)

Sets the given uniform to a trio of unsigned values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform

◆ setUniform3uiv() [1/2]

void cugl::Shader::setUniform3uiv ( const std::string  name,
GLsizei  count,
const GLuint *  value 
)

Sets the given uniform to an array of 3-element unsigned ints.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of unsigned ints

◆ setUniform3uiv() [2/2]

void cugl::Shader::setUniform3uiv ( GLint  pos,
GLsizei  count,
const GLuint *  value 
)

Sets the given uniform to an array of 3-element unsigned ints.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of unsigned ints

◆ setUniform4f() [1/2]

void cugl::Shader::setUniform4f ( const std::string  name,
GLfloat  v0,
GLfloat  v1,
GLfloat  v2,
GLfloat  v3 
)

Sets the given uniform to a quartet of float values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform
v3The fourth value for the uniform

◆ setUniform4f() [2/2]

void cugl::Shader::setUniform4f ( GLint  pos,
GLfloat  v0,
GLfloat  v1,
GLfloat  v2,
GLfloat  v3 
)

Sets the given uniform to a quartet of float values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform
v3The fourth value for the uniform

◆ setUniform4fv() [1/2]

void cugl::Shader::setUniform4fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value 
)

Sets the given uniform to an array of 4-element floats.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of floats

◆ setUniform4fv() [2/2]

void cugl::Shader::setUniform4fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value 
)

Sets the given uniform to an array of 4-element floats.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of floats

◆ setUniform4i() [1/2]

void cugl::Shader::setUniform4i ( const std::string  name,
GLint  v0,
GLint  v1,
GLint  v2,
GLint  v3 
)

Sets the given uniform to a quartet of int values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform
v3The fourth value for the uniform

◆ setUniform4i() [2/2]

void cugl::Shader::setUniform4i ( GLint  pos,
GLint  v0,
GLint  v1,
GLint  v2,
GLint  v3 
)

Sets the given uniform to a quartet of int values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform
v3The fourth value for the uniform

◆ setUniform4iv() [1/2]

void cugl::Shader::setUniform4iv ( const std::string  name,
GLsizei  count,
const GLint *  value 
)

Sets the given uniform to an array of 4-element ints.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of ints

◆ setUniform4iv() [2/2]

void cugl::Shader::setUniform4iv ( GLint  pos,
GLsizei  count,
const GLint *  value 
)

Sets the given uniform to an array of 4-element ints.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of ints

◆ setUniform4ui() [1/2]

void cugl::Shader::setUniform4ui ( const std::string  name,
GLuint  v0,
GLuint  v1,
GLuint  v2,
GLuint  v3 
)

Sets the given uniform to a quartet of unsigned values.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform
v3The fourth value for the uniform

◆ setUniform4ui() [2/2]

void cugl::Shader::setUniform4ui ( GLint  pos,
GLuint  v0,
GLuint  v1,
GLuint  v2,
GLuint  v3 
)

Sets the given uniform to a quartet of unsigned values.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
v0The first value for the uniform
v1The second value for the uniform
v2The third value for the uniform
v3The fourth value for the uniform

◆ setUniform4uiv() [1/2]

void cugl::Shader::setUniform4uiv ( const std::string  name,
GLsizei  count,
const GLuint *  value 
)

Sets the given uniform to an array of 4-element unsigned ints.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of unsigned ints

◆ setUniform4uiv() [2/2]

void cugl::Shader::setUniform4uiv ( GLint  pos,
GLsizei  count,
const GLuint *  value 
)

Sets the given uniform to an array of 4-element unsigned ints.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of unsigned ints

◆ setUniformAffine2() [1/2]

void cugl::Shader::setUniformAffine2 ( const std::string  name,
const Affine2 mat 
)

Sets the given uniform to an affine transform.

Affine transforms are passed to a shader as a 3x3 matrix on homogenous coordinates.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform
matThe value for the uniform

◆ setUniformAffine2() [2/2]

void cugl::Shader::setUniformAffine2 ( GLint  pos,
const Affine2 mat 
)

Sets the given uniform to an affine transform.

Affine transforms are passed to a shader as a 3x3 matrix on homogenous coordinates.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
matThe value for the uniform

◆ setUniformBlock() [1/4]

void cugl::Shader::setUniformBlock ( const std::string  name,
const std::shared_ptr< UniformBuffer > &  buffer 
)

Sets the given uniform block variable to the bindpoint of the given uniform buffer.

A uniform block is a variable attached to a uniform buffer. It is not the same as a normal uniform and cannot be treated as such. In this case the uniform values are set in the UniformBuffer object and not the shader.

This method will bind the uniform buffer to the current bindpoint of the block object. The shader will not be aware if the buffer object changes its bindpoint in the future. However, it will verify whether the buffer object has uniform variables matching this shader.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform block in the shader
bufferThe buffer to bind to this uniform block

◆ setUniformBlock() [2/4]

void cugl::Shader::setUniformBlock ( const std::string  name,
GLuint  bpoint 
)

Sets the given uniform block variable to a uniform buffer bindpoint.

A uniform block is a variable attached to a uniform buffer. It is not the same as a normal uniform and cannot be treated as such. In this case the uniform values are set in the UniformBuffer object and not the shader.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform block in the shader
bpointThe bindpoint for the uniform block

◆ setUniformBlock() [3/4]

void cugl::Shader::setUniformBlock ( GLint  pos,
const std::shared_ptr< UniformBuffer > &  buffer 
)

Sets the given uniform block variable to the bindpoint of the given uniform buffer.

A uniform block is a variable attached to a uniform buffer. It is not the same as a normal uniform and cannot be treated as such. In this case the uniform values are set in the UniformBuffer object and not the shader.

This method will bind the uniform buffer to the current bindpoint of the block object. The shader will not be aware if the buffer object changes its bindpoint in the future. However, it will verify whether the buffer object has uniform variables matching this shader.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform block in the shader
bufferThe buffer to bind to this uniform block

◆ setUniformBlock() [4/4]

void cugl::Shader::setUniformBlock ( GLint  pos,
GLuint  bpoint 
)

Sets the given uniform block variable to a uniform buffer bindpoint.

A uniform block is a variable attached to a uniform buffer. It is not the same as a normal uniform and cannot be treated as such. In this case the uniform values are set in the UniformBuffer object and not the shader.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform block in the shader
bpointThe bindpoint for the uniform block

◆ setUniformColor4() [1/2]

void cugl::Shader::setUniformColor4 ( const std::string  name,
const Color4  color 
)

Sets the given uniform to a color value.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform
colorThe value for the uniform

◆ setUniformColor4() [2/2]

void cugl::Shader::setUniformColor4 ( GLint  pos,
const Color4  color 
)

Sets the given uniform to a color value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
colorThe value for the uniform

◆ setUniformColor4f() [1/2]

void cugl::Shader::setUniformColor4f ( const std::string  name,
const Color4f  color 
)

Sets the given uniform to a color value.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform
colorThe value for the uniform

◆ setUniformColor4f() [2/2]

void cugl::Shader::setUniformColor4f ( GLint  pos,
const Color4f  color 
)

Sets the given uniform to a color value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
colorThe value for the uniform

◆ setUniformMat4() [1/2]

void cugl::Shader::setUniformMat4 ( const std::string  name,
const Mat4 mat 
)

Sets the given uniform to a matrix value

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
matThe value for the uniform

◆ setUniformMat4() [2/2]

void cugl::Shader::setUniformMat4 ( GLint  pos,
const Mat4 mat 
)

Sets the given uniform to a matrix value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
matThe value for the uniform

◆ setUniformMatrix2fv() [1/2]

void cugl::Shader::setUniformMatrix2fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 2x2 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix2fv() [2/2]

void cugl::Shader::setUniformMatrix2fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 2x2 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix2x3fv() [1/2]

void cugl::Shader::setUniformMatrix2x3fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 2x3 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix2x3fv() [2/2]

void cugl::Shader::setUniformMatrix2x3fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 2x3 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix2x4fv() [1/2]

void cugl::Shader::setUniformMatrix2x4fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 2x4 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix2x4fv() [2/2]

void cugl::Shader::setUniformMatrix2x4fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 2x4 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix3fv() [1/2]

void cugl::Shader::setUniformMatrix3fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 3x3 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix3fv() [2/2]

void cugl::Shader::setUniformMatrix3fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 3x3 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix3x2fv() [1/2]

void cugl::Shader::setUniformMatrix3x2fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 3x2 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix3x2fv() [2/2]

void cugl::Shader::setUniformMatrix3x2fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 3x2 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix3x4fv() [1/2]

void cugl::Shader::setUniformMatrix3x4fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 3x4 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix3x4fv() [2/2]

void cugl::Shader::setUniformMatrix3x4fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 3x4 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix4fv() [1/2]

void cugl::Shader::setUniformMatrix4fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 4x4 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix4fv() [2/2]

void cugl::Shader::setUniformMatrix4fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 4x4 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix4x2fv() [1/2]

void cugl::Shader::setUniformMatrix4x2fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 4x2 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix4x2fv() [2/2]

void cugl::Shader::setUniformMatrix4x2fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 4x2 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix4x3fv() [1/2]

void cugl::Shader::setUniformMatrix4x3fv ( const std::string  name,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 4x3 matrices.

This method will only succeed if the shader is actively bound. It will silently fail (with no error) if name is does not refer to a valid uniform.

Parameters
nameThe name of the uniform
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformMatrix4x3fv() [2/2]

void cugl::Shader::setUniformMatrix4x3fv ( GLint  pos,
GLsizei  count,
const GLfloat *  value,
GLboolean  tpose = false 
)

Sets the given uniform to an array 4x3 matrices.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
countThe number of elements in the array
valueThe array of matrices
tposeWhether to transpose the matrices

◆ setUniformQuaternion() [1/2]

void cugl::Shader::setUniformQuaternion ( const std::string  name,
const Quaternion quat 
)

Sets the given uniform to a quaternion.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform
quatThe value for the uniform

◆ setUniformQuaternion() [2/2]

void cugl::Shader::setUniformQuaternion ( GLint  pos,
const Quaternion quat 
)

Sets the given uniform to a quaternion.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
quatThe value for the uniform

◆ setUniformVec2() [1/2]

void cugl::Shader::setUniformVec2 ( const std::string  name,
const Vec2  vec 
)

Sets the given uniform to a vector value.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform
vecThe value for the uniform

◆ setUniformVec2() [2/2]

void cugl::Shader::setUniformVec2 ( GLint  pos,
const Vec2  vec 
)

Sets the given uniform to a vector value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
vecThe value for the uniform

◆ setUniformVec3() [1/2]

void cugl::Shader::setUniformVec3 ( const std::string  name,
const Vec3  vec 
)

Sets the given uniform to a vector value.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform
vecThe value for the uniform

◆ setUniformVec3() [2/2]

void cugl::Shader::setUniformVec3 ( GLint  pos,
const Vec3  vec 
)

Sets the given uniform to a vector value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
vecThe value for the uniform

◆ setUniformVec4() [1/2]

void cugl::Shader::setUniformVec4 ( const std::string  name,
const Vec4  vec 
)

Sets the given uniform to a vector value.

This method will only succeed if the shader is actively bound.

Parameters
nameThe name of the uniform
vecThe value for the uniform

◆ setUniformVec4() [2/2]

void cugl::Shader::setUniformVec4 ( GLint  pos,
const Vec4  vec 
)

Sets the given uniform to a vector value.

This method will only succeed if the shader is actively bound.

Parameters
posThe location of the uniform in the shader
vecThe value for the uniform

◆ unbind()

void cugl::Shader::unbind ( )

Unbinds this shader, making it no longer active.

Once unbound, OpenGL calls will no longer be sent to this shader.

Member Data Documentation

◆ _attribnames

std::unordered_map<GLint, std::string> cugl::Shader::_attribnames
protected

The attribute variable names of this shader

◆ _attribsizes

std::unordered_map<std::string, GLint> cugl::Shader::_attribsizes
protected

The attribute locations of this shader

◆ _attribtypes

std::unordered_map<std::string, GLenum> cugl::Shader::_attribtypes
protected

The attribute locations of this shader

◆ _fragShader

GLuint cugl::Shader::_fragShader
protected

The OpenGL fragment shader for this shader

◆ _fragSource

std::string cugl::Shader::_fragSource
protected

The source string for the fragment shader

◆ _program

GLuint cugl::Shader::_program
protected

The OpenGL program for this shader

◆ _uniblockfields

std::unordered_map<GLint, GLint> cugl::Shader::_uniblockfields
protected

Mappings of uniforms to a uniform block

◆ _uniblocknames

std::unordered_map<GLint,std::string> cugl::Shader::_uniblocknames
protected

The uniform block variable names for this shader

◆ _uniblocksizes

std::unordered_map<std::string, GLint> cugl::Shader::_uniblocksizes
protected

The uniform block locations of this shader

◆ _uniformnames

std::unordered_map<GLint,std::string> cugl::Shader::_uniformnames
protected

The uniform variable names for this shader (includes samplers)

◆ _uniformsizes

std::unordered_map<std::string, GLint> cugl::Shader::_uniformsizes
protected

The uniform locations of this shader (includes samplers)

◆ _uniformtypes

std::unordered_map<std::string, GLenum> cugl::Shader::_uniformtypes
protected

The uniform locations of this shader

◆ _vertShader

GLuint cugl::Shader::_vertShader
protected

The OpenGL vertex shader for this shader

◆ _vertSource

std::string cugl::Shader::_vertSource
protected

The source string for the vertex shader


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