The ShaderProgram is a GLSL program which combines two shaders - the vertex shader and the fragment shader - to allow rendering. Each renderer should have its own program. More...
#include <ShaderProgram.hpp>
Collaboration diagram for BARE2D::ShaderProgram:Public Member Functions | |
| ShaderProgram () | |
| ~ShaderProgram () | |
| void | compileShaders (const char *vertexShaderPath, const char *fragmentShaderPath) |
| Compiles the shaders. Does not link them. More... | |
| void | compileShadersFromSource (const char *vertexSource, const char *fragmentSource) |
| Similar to compileShaders, this just compiles the shaders. More... | |
| void | linkShaders (std::initializer_list< std::string > attributes) |
| Links the compiled shaders together to create a coherent shader program. More... | |
| template<class T > | |
| void | setUniform (const std::string uniform, T *data, unsigned int num=1) |
| A generalized wrapper to find and set a uniform for this shader. More... | |
| template<class T > | |
| void | setUniformMatrix (const std::string uniform, bool transpose, T *data, unsigned int num=1) |
| Similar to setUniform. More... | |
| bool | doesUniformExist (const std::string uniform) |
| void | bindFragOutputLocation (std::string outputVariableName, unsigned int location) |
| A call to glBindFragDataLocation() - Causes an output variable of the fragment shader to output to a specific location. This is roughly equivalent to modern GLSL's layout(location=n) specifier, which is unusable until GLSL 330. More... | |
| void | use () |
| Activates this shader program for the renderer to use. More... | |
| void | unuse () |
| Deactivates this shader program. More... | |
| void | destroy () |
| Releases all bound objects and deletes any allocated stuff. More... | |
| template<> | |
| void | setUniform (const std::string uniform, int *data, unsigned int num) |
| template<> | |
| void | setUniform (const std::string uniform, unsigned int *data, unsigned int num) |
| template<> | |
| void | setUniform (const std::string uniform, float *data, unsigned int num) |
Private Member Functions | |
| void | compileShaderFromSource (const char *source, const std::string &name, GLuint id) |
| Compiles a shader from source with OpenGL id. More... | |
| GLint | getUniformLocation (const std::string &uniform) |
| Gets the location of a uniform in a program. More... | |
Private Attributes | |
| unsigned int | m_numberAttributes = 0 |
| GLuint | m_programID |
| GLuint | m_vertexShaderID |
| GLuint | m_fragmentShaderID |
The ShaderProgram is a GLSL program which combines two shaders - the vertex shader and the fragment shader - to allow rendering. Each renderer should have its own program.
Definition at line 14 of file ShaderProgram.hpp.
| BARE2D::ShaderProgram::ShaderProgram | ( | ) |
Definition at line 14 of file ShaderProgram.cpp.
| BARE2D::ShaderProgram::~ShaderProgram | ( | ) |
Definition at line 19 of file ShaderProgram.cpp.
| void BARE2D::ShaderProgram::bindFragOutputLocation | ( | std::string | outputVariableName, |
| unsigned int | location | ||
| ) |
A call to glBindFragDataLocation() - Causes an output variable of the fragment shader to output to a specific location. This is roughly equivalent to modern GLSL's layout(location=n) specifier, which is unusable until GLSL 330.
| outputVariableName | The name of the output variable (oftentimes just colour or something) |
| location | The output location, corresponding to a colour attachment. Must be less than GL_MAX_DRAW_BUFFERS. |
Definition at line 141 of file ShaderProgram.cpp.
References m_programID.
Referenced by BARE2D::Renderer::link().
Here is the caller graph for this function:
|
private |
Compiles a shader from source with OpenGL id.
| source | The source to compile from. |
| name | The name of the shader. This is normally associated with the key in the cache. |
| id | The ID of the shader that has been created with OpenGL calls. |
Definition at line 183 of file ShaderProgram.cpp.
References BARE2D::SHADER_COMPILE_FAILURE, and BARE2D::throwFatalError().
Referenced by compileShadersFromSource().
Here is the call graph for this function:
Here is the caller graph for this function:| void BARE2D::ShaderProgram::compileShaders | ( | const char * | vertexShaderPath, |
| const char * | fragmentShaderPath | ||
| ) |
Compiles the shaders. Does not link them.
| vertexShaderPath | The path to the vertex shader |
| fragmentShaderPath | The path to the fragment shader. |
Definition at line 23 of file ShaderProgram.cpp.
References compileShadersFromSource(), BARE2D::ResourceManager::getAssetsPathPrefix(), and BARE2D::IOManager::readFileToBuffer().
Referenced by BARE2D::BasicRenderer::init(), BARE2D::FBORenderer::init(), BARE2D::TexturelessRenderer::init(), and BARE2D::ResourceManager::loadShaders().
Here is the call graph for this function:
Here is the caller graph for this function:| void BARE2D::ShaderProgram::compileShadersFromSource | ( | const char * | vertexSource, |
| const char * | fragmentSource | ||
| ) |
Similar to compileShaders, this just compiles the shaders.
| vertexSource | The source code for the vertex shader |
| fragmentSource | The source code for the fragment shader |
Definition at line 38 of file ShaderProgram.cpp.
References compileShaderFromSource(), destroy(), BARE2D::FRAGMENT_SHADER_FAILURE, BARE2D::GLSL_PROGRAM_FAILURE, m_fragmentShaderID, m_programID, m_vertexShaderID, BARE2D::throwFatalError(), and BARE2D::VERTEX_SHADER_FAILURE.
Referenced by compileShaders(), BARE2D::DebugRenderer::init(), and BARE2D::ResourceManager::loadShadersFromSource().
Here is the call graph for this function:
Here is the caller graph for this function:| void BARE2D::ShaderProgram::destroy | ( | ) |
Releases all bound objects and deletes any allocated stuff.
Definition at line 172 of file ShaderProgram.cpp.
References m_fragmentShaderID, m_numberAttributes, m_programID, and m_vertexShaderID.
Referenced by compileShadersFromSource(), and BARE2D::Renderer::destroy().
Here is the caller graph for this function:| bool BARE2D::ShaderProgram::doesUniformExist | ( | const std::string | uniform | ) |
| uniform | The uniform to check for |
Definition at line 213 of file ShaderProgram.cpp.
References getUniformLocation().
Referenced by BARE2D::FBORenderer::initUniforms().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Gets the location of a uniform in a program.
| uniform | The name of the uniform to find. |
Definition at line 125 of file ShaderProgram.cpp.
References m_programID, BARE2D::throwError(), and BARE2D::UNIFORM_NOT_FOUND.
Referenced by doesUniformExist(), and setUniform().
Here is the call graph for this function:
Here is the caller graph for this function:| void BARE2D::ShaderProgram::linkShaders | ( | std::initializer_list< std::string > | attributes | ) |
Links the compiled shaders together to create a coherent shader program.
| attributes | An initializer_list of std::string type of attributes to add to the program. These must link up with the renderer used to draw with this program. |
Definition at line 75 of file ShaderProgram.cpp.
References m_fragmentShaderID, m_numberAttributes, m_programID, m_vertexShaderID, BARE2D::SHADER_LINK_FAILURE, and BARE2D::throwFatalError().
Referenced by BARE2D::Renderer::link().
Here is the call graph for this function:
Here is the caller graph for this function:| void BARE2D::ShaderProgram::setUniform | ( | const std::string | uniform, |
| float * | data, | ||
| unsigned int | num | ||
| ) |
Definition at line 248 of file ShaderProgram.cpp.
References getUniformLocation().
Here is the call graph for this function:| void BARE2D::ShaderProgram::setUniform | ( | const std::string | uniform, |
| int * | data, | ||
| unsigned int | num | ||
| ) |
Definition at line 224 of file ShaderProgram.cpp.
References getUniformLocation().
Here is the call graph for this function:| void BARE2D::ShaderProgram::setUniform | ( | const std::string | uniform, |
| T * | data, | ||
| unsigned int | num = 1 |
||
| ) |
A generalized wrapper to find and set a uniform for this shader.
| uniform | The name of the uniform in the shader |
| data | The variable to actually set the uniform's value to. This can be a glm::{i,ui,f}vec{1,2,3,4}, an unsigned int, an int, or a float |
Referenced by BARE2D::FBORenderer::initUniforms(), BARE2D::BumpyRenderer::initUniforms(), and BARE2D::BasicRenderer::preRender().
Here is the caller graph for this function:| void BARE2D::ShaderProgram::setUniform | ( | const std::string | uniform, |
| unsigned int * | data, | ||
| unsigned int | num | ||
| ) |
Definition at line 236 of file ShaderProgram.cpp.
References getUniformLocation().
Here is the call graph for this function:| void BARE2D::ShaderProgram::setUniformMatrix | ( | const std::string | uniform, |
| bool | transpose, | ||
| T * | data, | ||
| unsigned int | num = 1 |
||
| ) |
Similar to setUniform.
| uniform | The name of the uniform in the shader |
| transpose | Should the matrix be transposed when converted? If false, each matrix is assumed to be supplied in column major order. Else, row major order |
| data | A pointer to the matrix, which is a 1D array of floats, ints, or unsigned ints. |
Referenced by BARE2D::BasicRenderer::preRender(), BARE2D::TexturelessRenderer::preRender(), BARE2D::BumpyRenderer::preRender(), and BARE2D::FBORenderer::preRender().
Here is the caller graph for this function:| void BARE2D::ShaderProgram::unuse | ( | ) |
Deactivates this shader program.
Definition at line 160 of file ShaderProgram.cpp.
References m_numberAttributes.
Referenced by BARE2D::Renderer::end(), BARE2D::FBORenderer::end(), BARE2D::FBORenderer::init(), BARE2D::Renderer::init(), BARE2D::BumpyRenderer::render(), BARE2D::FBORenderer::render(), BARE2D::Renderer::render(), and BARE2D::DebugRenderer::render().
Here is the caller graph for this function:| void BARE2D::ShaderProgram::use | ( | ) |
Activates this shader program for the renderer to use.
Definition at line 147 of file ShaderProgram.cpp.
References m_numberAttributes, and m_programID.
Referenced by BARE2D::Renderer::begin(), BARE2D::FBORenderer::begin(), BARE2D::FBORenderer::init(), BARE2D::Renderer::init(), BARE2D::BumpyRenderer::render(), BARE2D::FBORenderer::render(), BARE2D::Renderer::render(), and BARE2D::DebugRenderer::render().
Here is the caller graph for this function:
|
private |
Definition at line 90 of file ShaderProgram.hpp.
Referenced by compileShadersFromSource(), destroy(), and linkShaders().
|
private |
Definition at line 86 of file ShaderProgram.hpp.
Referenced by destroy(), linkShaders(), unuse(), and use().
|
private |
Definition at line 88 of file ShaderProgram.hpp.
Referenced by bindFragOutputLocation(), compileShadersFromSource(), destroy(), getUniformLocation(), linkShaders(), and use().
|
private |
Definition at line 89 of file ShaderProgram.hpp.
Referenced by compileShadersFromSource(), destroy(), and linkShaders().