Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::ShaderProgram Class Reference

A wrapper over OpenGL's shader programs. More...

#include <shader_program.hpp>

Inheritance diagram for ToyMaker::ShaderProgram:
ToyMaker::Resource< ShaderProgram > ToyMaker::IResource

Public Member Functions

 ShaderProgram (GLuint program)
 Constructs a new shader program out of an OpenGL shader program already present in memory.
 
 ~ShaderProgram ()
 Shader destructor; deletes shader from memory.
 
 ShaderProgram (const ShaderProgram &other)=delete
 
ShaderProgramoperator= (const ShaderProgram &other)=delete
 
 ShaderProgram (ShaderProgram &&other) noexcept
 Shader move constructor.
 
ShaderProgramoperator= (ShaderProgram &&other) noexcept
 Shader move assignment.
 
void use () const
 Makes this shader the active one in this program's OpenGL context.
 
GLint getLocationAttribArray (const std::string &name) const
 Retrieves the location (ID) of an attrib array with a given name.
 
void enableAttribArray (const std::string &name) const
 Enables an attrib array with a given name.
 
void enableAttribArray (GLint locationAttrib) const
 Enables an attrib array with a given ID.
 
void disableAttribArray (const std::string &name) const
 Disables an attrib array with a given name.
 
void disableAttribArray (GLint locationAttrib) const
 Disables an attrib array with a given ID.
 
GLint getLocationUniform (const std::string &name) const
 Gets the location (ID) of a uniform with a given name.
 
void setUBool (const std::string &name, bool value) const
 Sets a uniform boolean value.
 
void setUInt (const std::string &name, int value) const
 Sets an int uniform's value.
 
void setUFloat (const std::string &name, float value) const
 Sets a float uniform's value.
 
void setUVec2 (const std::string &name, const glm::vec2 &value) const
 Sets a vec2 uniform's value.
 
void setUVec3 (const std::string &name, const glm::vec3 &value) const
 Sets a vec3 uniform's value.
 
void setUVec4 (const std::string &name, const glm::vec4 &value) const
 Sets a vec4 uniform's value.
 
void setUMat4 (const std::string &name, const glm::mat4 &value) const
 Sets a mat4 uniform's value.
 
GLint getLocationUniformBlock (const std::string &name) const
 Gets the ID of one of this shader's uniform blocks with a certain name.
 
void setUniformBlock (const std::string &name, GLuint bindingPoint) const
 Binds this shader's named uniform block to a specific uniform binding point.
 
GLuint getProgramID () const
 Returns the ID of the OpenGL shader program this class is a wrapper over.
 
- Public Member Functions inherited from ToyMaker::Resource< ShaderProgram >
std::string getResourceTypeName_ () const override
 Get the resource type string for this resource.
 
- Public Member Functions inherited from ToyMaker::IResource
virtual ~IResource ()=default
 Destroy the IResource object.
 

Static Public Member Functions

static std::string getResourceTypeName ()
 The resource type string associated with this class.
 

Private Member Functions

void destroyResource ()
 Destroys the shader resource associated with this object.
 
void releaseResource ()
 Releases the shader resource associated with this object, assuming that it will be picked up by another object or part of the program.
 

Private Attributes

GLuint mID
 The ID of the shader program this object is a wrapper over.
 

Additional Inherited Members

- Protected Member Functions inherited from ToyMaker::Resource< ShaderProgram >
 Resource (int explicitlyInitializeMe)
 Construct a new resource object.
 
- Protected Member Functions inherited from ToyMaker::IResource
 IResource ()=default
 Construct a new IResource object.
 
- Static Protected Member Functions inherited from ToyMaker::IResource
template<typename TResource>
static void RegisterResource ()
 Registers this resource as a Resource type with the ResourceDatabase.
 

Detailed Description

A wrapper over OpenGL's shader programs.

Constructor & Destructor Documentation

◆ ShaderProgram()

ShaderProgram::ShaderProgram ( GLuint program)

Constructs a new shader program out of an OpenGL shader program already present in memory.

Parameters
programThe ID of the OpenGL program.

Member Function Documentation

◆ disableAttribArray() [1/2]

void ShaderProgram::disableAttribArray ( const std::string & name) const

Disables an attrib array with a given name.

Parameters
nameThe name of the attrib array being disabled.

◆ disableAttribArray() [2/2]

void ShaderProgram::disableAttribArray ( GLint locationAttrib) const

Disables an attrib array with a given ID.

Parameters
locationAttribThe ID of the attrib array being disabled.

◆ enableAttribArray() [1/2]

void ShaderProgram::enableAttribArray ( const std::string & name) const

Enables an attrib array with a given name.

Parameters
nameThe name of the array being enabled.

◆ enableAttribArray() [2/2]

void ShaderProgram::enableAttribArray ( GLint locationAttrib) const

Enables an attrib array with a given ID.

Parameters
locationAttribThe ID of the array being enabled.

◆ getLocationAttribArray()

GLint ShaderProgram::getLocationAttribArray ( const std::string & name) const

Retrieves the location (ID) of an attrib array with a given name.

Parameters
nameThe name of the attrib array.
Returns
GLint The ID of the attrib array.

◆ getLocationUniform()

GLint ShaderProgram::getLocationUniform ( const std::string & name) const

Gets the location (ID) of a uniform with a given name.

Parameters
nameThe name of the uniform location being retrieved.
Returns
GLint The ID of the uniform.

◆ getLocationUniformBlock()

GLint ShaderProgram::getLocationUniformBlock ( const std::string & name) const

Gets the ID of one of this shader's uniform blocks with a certain name.

This ID can then be set to a UBO binding point, which lets the program find the associated uniform buffer.

Parameters
nameThe name of this shader's uniform block.
Returns
GLint The ID of the shader's uniform block.

◆ getProgramID()

GLuint ShaderProgram::getProgramID ( ) const

Returns the ID of the OpenGL shader program this class is a wrapper over.

Returns
GLuint The ID of this object's OpenGL shader program.

◆ getResourceTypeName()

static std::string ToyMaker::ShaderProgram::getResourceTypeName ( )
inlinestatic

The resource type string associated with this class.

Returns
std::string This class' resource type string.

◆ setUBool()

void ShaderProgram::setUBool ( const std::string & name,
bool value ) const

Sets a uniform boolean value.

Parameters
nameThe name of the boolean uniform.
valueThe value of the uniform.

◆ setUFloat()

void ShaderProgram::setUFloat ( const std::string & name,
float value ) const

Sets a float uniform's value.

Parameters
nameThe name of the float uniform.
valueThe value of the uniform.

◆ setUInt()

void ShaderProgram::setUInt ( const std::string & name,
int value ) const

Sets an int uniform's value.

Parameters
nameThe name of the int uniform.
valueThe value of the uniform.

◆ setUMat4()

void ShaderProgram::setUMat4 ( const std::string & name,
const glm::mat4 & value ) const

Sets a mat4 uniform's value.

Parameters
nameThe name of the mat4 uniform.
valueThe value of the uniform.

◆ setUniformBlock()

void ShaderProgram::setUniformBlock ( const std::string & name,
GLuint bindingPoint ) const

Binds this shader's named uniform block to a specific uniform binding point.

The binding point lets the shader program find the uniform buffer associated with the binding point via the uniform variable naming the uniform block.

Parameters
nameThe name of the uniform block.
bindingPointThe uniform binding point the block should be bound to.

◆ setUVec2()

void ShaderProgram::setUVec2 ( const std::string & name,
const glm::vec2 & value ) const

Sets a vec2 uniform's value.

Parameters
nameThe name of the vec2 uniform.
valueThe value of the uniform.

◆ setUVec3()

void ShaderProgram::setUVec3 ( const std::string & name,
const glm::vec3 & value ) const

Sets a vec3 uniform's value.

Parameters
nameThe name of the vec3 uniform.
valueThe value of the uniform.

◆ setUVec4()

void ShaderProgram::setUVec4 ( const std::string & name,
const glm::vec4 & value ) const

Sets a vec4 uniform's value.

Parameters
nameThe name of the vec4 uniform.
valueThe value of the uniform.

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