NGL  6.5
The NCCA Graphics Library
ngl::ShaderLib Class Reference

Singleton Class to init and Use GLSL Shaders the class stores the shaders as a map of shader objects and they can be found by name Updated to use templated singleton Updated to use a map to store the shaders by name and hence removed the name from the ShaderObject Class Also Added methods to adjust shader parameters by shader / param name, at present use only 1-4 Floats and a few others need to think of a better way of doing this. More...

#include <ShaderLib.h>

+ Inheritance diagram for ngl::ShaderLib:
+ Collaboration diagram for ngl::ShaderLib:

Public Member Functions

void createShaderProgram (const std::string &_name) noexcept
 create an empty ShaderProgram for us to attach shaders etc to More...
 
void attachShader (const std::string &_name, ShaderType _type) noexcept
 attatch a Shader to the ShaderProgram referenced by _name More...
 
void attachShaderToProgram (const std::string &_program, const std::string &_shader) noexcept
 attatch a Shader to the ShaderProgram referenced by _name More...
 
GLuint getProgramID (const std::string &_name) noexcept
 get the Program ID of the GL Program by name More...
 
void compileShader (const std::string &_name) noexcept
 compile the shader from _name More...
 
void linkProgramObject (const std::string &_name) noexcept
 link the program Object from _name More...
 
void toggleDebug () noexcept
 toggle debug mode More...
 
void use (const std::string &_name) noexcept
 set active shader to name (if not found sets glProgramObject(0) More...
 
void bindAttribute (const std::string &_programName, GLuint _index, const std::string &_attribName) noexcept
 bind an attribute at index by name More...
 
void bindFragDataLocation (const std::string &_programName, GLuint _index, const std::string &_attribName) noexcept
 fragment shader output location More...
 
ShaderProgramoperator[] (const std::string &_name) noexcept
 accessor to the shader program using the subscript operatoir More...
 
ShaderProgramoperator[] (const char *_name) noexcept
 accessor to the shader program using the subscript operatoir More...
 
void loadShader (const std::string &_shaderName, const std::string &_vert, const std::string &_frag, const std::string &_geo="", const bool _exitOnError=false) noexcept
 method to load shaders More...
 
bool loadFromJson (const std::string &_fname) noexcept
 method to load multiple shaders from a json file More...
 
void debugOn () noexcept
 Toggle debug mode on. More...
 
void debugOff () noexcept
 Toggle debug mode off. More...
 
size_t getNumShaders () const noexcept
 get the number of shaders stored More...
 
void setShaderParamFromMat4 (const std::string &_paramName, Mat4 _p1) noexcept
 set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniformFromMat4 (const std::string &_registeredUniformName, Mat4 _p1) noexcept
 set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail More...
 
void setShaderParamFromMat3 (const std::string &_paramName, Mat3 _p1) noexcept
 set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniformFromMat3 (const std::string &_paramName, Mat3 _p1) noexcept
 set the registered uniform from Max3x3 More...
 
void setShaderParamFromVec4 (const std::string &_paramName, Vec4 _p1) noexcept
 set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniformVec4 (const std::string &_paramName, Vec4 _p1) noexcept
 set the pre-registered uniform from an Vec4 More...
 
void setShaderParamFromColour (const std::string &_paramName, Colour _p1) noexcept
 set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniformFromColour (const std::string &_paramName, Colour _p1) noexcept
 set the pre-registered uniform from an Colour More...
 
void setRegisteredUniformVec3 (const std::string &_paramName, Vec3 _p1) noexcept
 set the pre-registered uniform from an Vector More...
 
void setRegisteredUniformVec2 (const std::string &_paramName, Vec2 _p1) noexcept
 set the pre-registered uniform from a Vector More...
 
void setShaderParam1i (const std::string &_paramName, int _p1) noexcept
 set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform1i (const std::string &_paramName, int _p1) noexcept
 set the pre-registered uniform More...
 
void setShaderParam1f (const std::string &_paramName, float _p1) noexcept
 set a shader param by name for 1 float param note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform1f (const std::string &_paramName, float _p1) noexcept
 set the pre-registered uniform More...
 
void setShaderParam2f (const std::string &_paramName, float _p1, float _p2) noexcept
 set a shader param by name for 2 float params note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform2f (const std::string &_paramName, float _p1, float _p2) noexcept
 set the pre-registered uniform More...
 
void setShaderParam3f (const std::string &_paramName, float _p1, float _p2, float _p3) noexcept
 set a shader param by name for 3 float params note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform3f (const std::string &_paramName, float _p1, float _p2, float _p3) noexcept
 set the pre-registered uniform More...
 
void setShaderParam4f (const std::string &_paramName, float _p1, float _p2, float _p3, float _p4) noexcept
 set a shader param by name for 4 float params note that the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform4f (const std::string &_paramName, float _p1, float _p2, float _p3, float _p4) noexcept
 set the pre-registered uniform More...
 
void printProperties () const noexcept
 print the properties of the currently active shader More...
 
void reset () noexcept
 reset the Shader manager which will delete all shader objects More...
 
GLint getAttribLocation (const std::string &_shaderName, const std::string &_paramName) noexcept
 return the index to the shader attribute location More...
 
void loadShaderSource (std::string _shaderName, std::string _sourceFile) noexcept
 Load shader source from text file the path will be relative from current dir unless a full path is specified. More...
 
void loadShaderSourceFromString (const std::string &_shaderName, const std::string &_string) noexcept
 load shader from a C string, useful for including code in headers etc More...
 
void useNullProgram () noexcept
 use the null program (this will turn off any shaders), if using some drivers this will go to the fixed function pipeline More...
 
GLuint getUniformBlockIndex (const std::string &_uniformBlockName) const noexcept
 grab the index of the unifrom block, this may not be supported on all GPU's More...
 
void registerUniform (const std::string &_shaderName, const std::string &_uniformName) noexcept
 register a uniform so we don't have to call glGet functions when using More...
 
void autoRegisterUniforms (const std::string &_shaderName) noexcept
 will parse the shader source and find any uniforms it can and register them More...
 
void printRegisteredUniforms (const std::string &_shader) const noexcept
 debug print any registered uniforms More...
 
void setUniform (const std::string &_paramName, Real _v0) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Real _v0) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Real _v0, Real _v1) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Real _v0, Real _v1) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Real _v0, Real _v1, Real _v2) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Real _v0, Real _v1, Real _v2) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Real _v0, Real _v1, Real _v2, Real _v3) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Real _v0, Real _v1, Real _v2, Real _v3) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, GLint _v0) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, GLint _v0) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, GLint _v0, GLint _v1) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, GLint _v0, GLint _v1) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, GLint _v0, GLint _v1, GLint _v2) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, GLint _v0, GLint _v1, GLint _v2) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, GLint _v0, GLint _v1, GLint _v2, GLint _v3) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, GLint _v0, GLint _v1, GLint _v2, GLint _v3) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Colour _v0) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Colour _v0) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Vec2 _v0) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Vec2 _v0) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Vec3 _v0) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Vec3 _v0) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Vec4 _v0) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Vec4 _v0) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Mat3 _v0) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Mat3 _v0) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
void setUniform (const std::string &_paramName, Mat4 _v0) noexcept
 overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail More...
 
void setRegisteredUniform (const std::string &_paramName, Mat4 _v0) noexcept
 overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail More...
 
GLuint getShaderID (const std::string &_shaderName) noexcept
 method to return a shader ID More...
 
ngl::ShadergetShader (const std::string &_shaderName) noexcept
 method to return the specified shader object More...
 
- Public Member Functions inherited from ngl::Singleton< ShaderLib >
 Singleton (const Singleton &)=delete
 
Singletonoperator= (const Singleton &)=delete
 

Protected Member Functions

ShaderType getShaderType (const std::string &type) noexcept
 get shader type from string (used for json parsing) More...
 
void loadTextShaders () noexcept
 this will load the pre-defined text rendering shaders these are stored in the file src/shaders/TextShaders.h More...
 
void loadColourShaders () noexcept
 this will load the pre-defined text rendering shaders these are stored in the file src/shaders/ColourShaders.h More...
 
void loadDiffuseShaders () noexcept
 this will load the pre-defined text rendering shaders these are stored in the file src/shaders/DiffuseShaders.h More...
 
void loadToonShaders () noexcept
 this will load the pre-defined text rendering shaders these are stored in the file src/shaders/ToonShaders.h More...
 
 ShaderLib () noexcept
 default ctor private as a singleton More...
 
virtual ~ShaderLib ()
 default ctor private as a singleton More...
 
 ShaderLib (const ShaderLib &)=delete
 copy ctor private as singleton More...
 
- Protected Member Functions inherited from ngl::Singleton< ShaderLib >
 Singleton ()
 Constructor. More...
 
virtual ~Singleton ()
 Destructor. More...
 

Protected Attributes

std::unordered_map< std::string, ShaderProgram * > m_shaderPrograms
 a map of shader Programs using name as key to shader pointer More...
 
std::unordered_map< std::string, Shader * > m_shaders
 map of shaders using name as key More...
 
ShaderProgramm_nullProgram
 null ShaderProgram so we can return when shader not know; More...
 
std::string m_currentShader
 the name of the currently active shader More...
 
bool m_debugState
 flag to indicate the debug state More...
 
unsigned int m_numShaders
 the nunmber of shaders loaded More...
 

Friends

class Singleton< ShaderLib >
 

Additional Inherited Members

- Static Public Member Functions inherited from ngl::Singleton< ShaderLib >
static ShaderLibinstance ()
 Get the instance. More...
 
- Static Protected Member Functions inherited from ngl::Singleton< ShaderLib >
static void killSingleton ()
 
- Static Protected Attributes inherited from ngl::Singleton< ShaderLib >
static ShaderLibs_instance
 unique instance of the singleton More...
 

Detailed Description

Singleton Class to init and Use GLSL Shaders the class stores the shaders as a map of shader objects and they can be found by name Updated to use templated singleton Updated to use a map to store the shaders by name and hence removed the name from the ShaderObject Class Also Added methods to adjust shader parameters by shader / param name, at present use only 1-4 Floats and a few others need to think of a better way of doing this.

Author
Jonathan Macey
Version
3.0
Date
Last Revision 20/04/10 used templated singleton

Definition at line 55 of file ShaderLib.h.

Constructor & Destructor Documentation

ngl::ShaderLib::ShaderLib ( )
protectednoexcept

default ctor private as a singleton

Definition at line 231 of file ShaderLib.cpp.

References loadColourShaders(), loadDiffuseShaders(), loadTextShaders(), loadToonShaders(), m_currentShader, m_debugState, m_nullProgram, m_numShaders, and m_shaderPrograms.

+ Here is the call graph for this function:

virtual ngl::ShaderLib::~ShaderLib ( )
inlineprotectedvirtual

default ctor private as a singleton

Definition at line 668 of file ShaderLib.h.

ngl::ShaderLib::ShaderLib ( const ShaderLib )
protecteddelete

copy ctor private as singleton

Member Function Documentation

void ngl::ShaderLib::attachShader ( const std::string _name,
ShaderType  _type 
)
noexcept

attatch a Shader to the ShaderProgram referenced by _name

Parameters
_namethe name of the ShaderProgram to attach

Definition at line 279 of file ShaderLib.cpp.

References m_debugState, and m_shaders.

+ Here is the caller graph for this function:

void ngl::ShaderLib::attachShaderToProgram ( const std::string _program,
const std::string _shader 
)
noexcept

attatch a Shader to the ShaderProgram referenced by _name

Parameters
_programthe name of the ShaderProgram to attach to
_shaderthe name of the Shader to attach to Program

Definition at line 308 of file ShaderLib.cpp.

References m_debugState, m_shaderPrograms, and m_shaders.

+ Here is the caller graph for this function:

void ngl::ShaderLib::autoRegisterUniforms ( const std::string _shaderName)
noexcept

will parse the shader source and find any uniforms it can and register them

Parameters
[in]_shaderNamethe name of the shader to set the param for

Definition at line 544 of file ShaderLib.cpp.

References m_shaderPrograms.

+ Here is the caller graph for this function:

void ngl::ShaderLib::bindAttribute ( const std::string _programName,
GLuint  _index,
const std::string _attribName 
)
noexcept

bind an attribute at index by name

Parameters
_programNamethe name of the ShaderProgram to use
_indexthe attribute index to bind
_attribNamethe name of the attribute in the shader to be bound to this index
Note
if using glsl > 400 we can use layout qualifiers and don't need this

Definition at line 559 of file ShaderLib.cpp.

References m_shaderPrograms.

+ Here is the caller graph for this function:

void ngl::ShaderLib::bindFragDataLocation ( const std::string _programName,
GLuint  _index,
const std::string _attribName 
)
noexcept

fragment shader output location

Parameters
_programNamethe name of the ShaderProgram to use
_indexthe attribute index to bind
_attribNamethe name of the attribute in the shader to be bound to this index
Note
if using glsl > 420 we can use layout qualifiers and don't need this

Definition at line 572 of file ShaderLib.cpp.

References m_shaderPrograms.

void ngl::ShaderLib::compileShader ( const std::string _name)
noexcept

compile the shader from _name

Parameters
_namethe name of the ShaderProgram to compile

Definition at line 287 of file ShaderLib.cpp.

References m_shaders.

+ Here is the caller graph for this function:

void ngl::ShaderLib::createShaderProgram ( const std::string _name)
noexcept

create an empty ShaderProgram for us to attach shaders etc to

Parameters
_namethe name of the ShaderProgram to link

Definition at line 301 of file ShaderLib.cpp.

References m_debugState, and m_shaderPrograms.

+ Here is the caller graph for this function:

void ngl::ShaderLib::debugOff ( )
inlinenoexcept

Toggle debug mode off.

Definition at line 156 of file ShaderLib.h.

void ngl::ShaderLib::debugOn ( )
inlinenoexcept

Toggle debug mode on.

Definition at line 152 of file ShaderLib.h.

GLint ngl::ShaderLib::getAttribLocation ( const std::string _shaderName,
const std::string _paramName 
)
noexcept

return the index to the shader attribute location

Parameters
_shaderNamethe name of the shader program
_paramNamethe name of the parameter to find
Returns
the Attrib index location

Definition at line 206 of file ShaderLib.cpp.

References glGetAttribLocation, and m_shaderPrograms.

size_t ngl::ShaderLib::getNumShaders ( ) const
inlinenoexcept

get the number of shaders stored

Returns
the number of shaders

Definition at line 161 of file ShaderLib.h.

GLuint ngl::ShaderLib::getProgramID ( const std::string _name)
noexcept

get the Program ID of the GL Program by name

Parameters
_namethe name of the ShaderProgram to find
Returns
the id of the program found or -1 on error

Definition at line 528 of file ShaderLib.cpp.

References m_shaderPrograms.

ngl::Shader * ngl::ShaderLib::getShader ( const std::string _shaderName)
noexcept

method to return the specified shader object

Parameters
_shaderNamethe name of the shader to return

Definition at line 262 of file ShaderLib.cpp.

References m_currentShader, and m_shaders.

GLuint ngl::ShaderLib::getShaderID ( const std::string _shaderName)
noexcept

method to return a shader ID

Parameters
_shaderNamethe name of the shader who's ID to return

Definition at line 246 of file ShaderLib.cpp.

References m_currentShader, and m_shaders.

ShaderType ngl::ShaderLib::getShaderType ( const std::string type)
protectednoexcept

get shader type from string (used for json parsing)

Definition at line 345 of file ShaderLib.cpp.

References ngl::COMPUTE, ngl::FRAGMENT, ngl::GEOMETRY, ngl::NONE, ngl::TESSCONTROL, ngl::TESSEVAL, and ngl::VERTEX.

+ Here is the caller graph for this function:

GLuint ngl::ShaderLib::getUniformBlockIndex ( const std::string _uniformBlockName) const
noexcept

grab the index of the unifrom block, this may not be supported on all GPU's

Parameters
_uniformBlockNamethe name of the block to get the index for
Returns
the index of the block or -1 on error

Definition at line 639 of file ShaderLib.cpp.

References m_currentShader, and m_shaderPrograms.

void ngl::ShaderLib::linkProgramObject ( const std::string _name)
noexcept

link the program Object from _name

Parameters
_namethe name of the ShaderProgram to link

Definition at line 492 of file ShaderLib.cpp.

References m_shaderPrograms.

+ Here is the caller graph for this function:

void ngl::ShaderLib::loadColourShaders ( )
protectednoexcept

this will load the pre-defined text rendering shaders these are stored in the file src/shaders/ColourShaders.h

Definition at line 689 of file ShaderLib.cpp.

References attachShader(), attachShaderToProgram(), autoRegisterUniforms(), bindAttribute(), colourFragmentShader, colourVertexShader, compileShader(), createShaderProgram(), ngl::FRAGMENT, linkProgramObject(), loadShaderSourceFromString(), use(), and ngl::VERTEX.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::ShaderLib::loadDiffuseShaders ( )
protectednoexcept

this will load the pre-defined text rendering shaders these are stored in the file src/shaders/DiffuseShaders.h

Definition at line 715 of file ShaderLib.cpp.

References attachShader(), attachShaderToProgram(), autoRegisterUniforms(), bindAttribute(), compileShader(), createShaderProgram(), diffuseFragmentShader, diffuseVertexShader, ngl::FRAGMENT, linkProgramObject(), loadShaderSourceFromString(), use(), and ngl::VERTEX.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ngl::ShaderLib::loadFromJson ( const std::string _fname)
noexcept

method to load multiple shaders from a json file

Parameters
[in]_shaderNamethe name of the json resource file

Definition at line 372 of file ShaderLib.cpp.

References attachShader(), attachShaderToProgram(), compileShader(), createShaderProgram(), getShaderType(), linkProgramObject(), loadShaderSourceFromString(), and SizeType.

+ Here is the call graph for this function:

void ngl::ShaderLib::loadShader ( const std::string _shaderName,
const std::string _vert,
const std::string _frag,
const std::string _geo = "",
const bool  _exitOnError = false 
)
noexcept

method to load shaders

Parameters
[in]_shaderNamethe name of the shader to be stored in the Manager
[in]_vertthe vertex shader to load
[in]_fragthe fragment shader to load
[in]_geoan optional geo shader to load
[in]_exitOnErrorexit if there is an error in the shader

Definition at line 167 of file ShaderLib.cpp.

References ngl::FRAGMENT, ngl::GEOMETRY, NGL_UNUSED, and ngl::VERTEX.

void ngl::ShaderLib::loadShaderSource ( std::string  _shaderName,
std::string  _sourceFile 
)
noexcept

Load shader source from text file the path will be relative from current dir unless a full path is specified.

Parameters
_shaderNamethe name of the shader program
_sourceFilethe path of the file to load

Definition at line 332 of file ShaderLib.cpp.

References m_shaders.

void ngl::ShaderLib::loadShaderSourceFromString ( const std::string _shaderName,
const std::string _string 
)
noexcept

load shader from a C string, useful for including code in headers etc

Parameters
_shaderNamethe name of the shader program
_stringthe text array of shader data

Definition at line 477 of file ShaderLib.cpp.

References m_shaders.

+ Here is the caller graph for this function:

void ngl::ShaderLib::loadTextShaders ( )
protectednoexcept

this will load the pre-defined text rendering shaders these are stored in the file src/shaders/TextShaders.h

Definition at line 660 of file ShaderLib.cpp.

References attachShader(), attachShaderToProgram(), autoRegisterUniforms(), bindAttribute(), compileShader(), createShaderProgram(), ngl::FRAGMENT, linkProgramObject(), loadShaderSourceFromString(), textFragmentShader, textVertexShader, use(), and ngl::VERTEX.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::ShaderLib::loadToonShaders ( )
protectednoexcept

this will load the pre-defined text rendering shaders these are stored in the file src/shaders/ToonShaders.h

Definition at line 743 of file ShaderLib.cpp.

References attachShader(), attachShaderToProgram(), autoRegisterUniforms(), bindAttribute(), compileShader(), createShaderProgram(), ngl::FRAGMENT, linkProgramObject(), loadShaderSourceFromString(), toonFragmentShader, toonVertexShader, use(), and ngl::VERTEX.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ShaderProgram * ngl::ShaderLib::operator[] ( const std::string _name)
noexcept

accessor to the shader program using the subscript operatoir

Parameters
_namethe name of the ShaderProgram to use
Returns
a ShaderProgram if name exist else null shader program

Definition at line 594 of file ShaderLib.cpp.

References m_currentShader, m_nullProgram, and m_shaderPrograms.

ShaderProgram * ngl::ShaderLib::operator[] ( const char *  _name)
noexcept

accessor to the shader program using the subscript operatoir

Parameters
_namethe name of the ShaderProgram to use
Returns
a ShaderProgram if name exist else null shader program

Definition at line 613 of file ShaderLib.cpp.

References m_currentShader, m_nullProgram, and m_shaderPrograms.

void ngl::ShaderLib::printProperties ( ) const
noexcept

print the properties of the currently active shader

Definition at line 781 of file ShaderLib.cpp.

References m_currentShader, and m_shaderPrograms.

void ngl::ShaderLib::printRegisteredUniforms ( const std::string _shader) const
noexcept

debug print any registered uniforms

Definition at line 771 of file ShaderLib.cpp.

References m_shaderPrograms.

void ngl::ShaderLib::registerUniform ( const std::string _shaderName,
const std::string _uniformName 
)
noexcept

register a uniform so we don't have to call glGet functions when using

Parameters
[in]_shaderNamethe name of the shader to set the param for
[in]_uniformNamethe name of the uniform to register
void ngl::ShaderLib::reset ( )
noexcept

reset the Shader manager which will delete all shader objects

Definition at line 195 of file ShaderLib.cpp.

References m_shaderPrograms, and m_shaders.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Real  _v0 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the float value of the parameter to set

Definition at line 806 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Real  _v0,
Real  _v1 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the float value of the parameter to set
[in]_v1the float value of the parameter to set

Definition at line 816 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Real  _v0,
Real  _v1,
Real  _v2 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the float value of the parameter to set
[in]_v1the float value of the parameter to set
[in]_v2the float value of the parameter to set

Definition at line 827 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Real  _v0,
Real  _v1,
Real  _v2,
Real  _v3 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the float value of the parameter to set
[in]_v1the float value of the parameter to set
[in]_v2the float value of the parameter to set
[in]_v3the float value of the parameter to set

Definition at line 836 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
GLint  _v0 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the int value of the parameter to set

Definition at line 845 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
GLint  _v0,
GLint  _v1 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the int value of the parameter to set
[in]_v1the int value of the parameter to set

Definition at line 854 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
GLint  _v0,
GLint  _v1,
GLint  _v2 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the int value of the parameter to set
[in]_v1the int value of the parameter to set
[in]_v2the int value of the parameter to set

Definition at line 863 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
GLint  _v0,
GLint  _v1,
GLint  _v2,
GLint  _v3 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the int value of the parameter to set
[in]_v1the int value of the parameter to set
[in]_v2the int value of the parameter to set
[in]_v3the int value of the parameter to set

Definition at line 872 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Colour  _v0 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Colour value of the parameter to set

Definition at line 881 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Vec2  _v0 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Vec2 value of the parameter to set

Definition at line 889 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Vec3  _v0 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Vec3 value of the parameter to set

Definition at line 897 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Vec4  _v0 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Vec4 value of the parameter to set

Definition at line 905 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Mat3  _v0 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Mat3 value of the parameter to set

Definition at line 915 of file ShaderLib.cpp.

References GL_FALSE, and m_currentShader.

void ngl::ShaderLib::setRegisteredUniform ( const std::string _paramName,
Mat4  _v0 
)
noexcept

overloaded method to set shader Uniforms that have been pre-registered using auto-register uniforms method must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Mat4 value of the parameter to set

Definition at line 925 of file ShaderLib.cpp.

References GL_FALSE, and m_currentShader.

void ngl::ShaderLib::setRegisteredUniform1f ( const std::string _paramName,
float  _p1 
)
noexcept

set the pre-registered uniform

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set

Definition at line 160 of file ShaderLib.cpp.

+ Here is the caller graph for this function:

void ngl::ShaderLib::setRegisteredUniform1i ( const std::string _paramName,
int  _p1 
)
noexcept

set the pre-registered uniform

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set

Definition at line 145 of file ShaderLib.cpp.

void ngl::ShaderLib::setRegisteredUniform2f ( const std::string _paramName,
float  _p1,
float  _p2 
)
noexcept

set the pre-registered uniform

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set
[in]_p2the float value of the parameter to set

Definition at line 133 of file ShaderLib.cpp.

+ Here is the caller graph for this function:

void ngl::ShaderLib::setRegisteredUniform3f ( const std::string _paramName,
float  _p1,
float  _p2,
float  _p3 
)
noexcept

set the pre-registered uniform

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set
[in]_p2the float value of the parameter to set
[in]_p3the float value of the parameter to set

Definition at line 120 of file ShaderLib.cpp.

+ Here is the caller graph for this function:

void ngl::ShaderLib::setRegisteredUniform4f ( const std::string _paramName,
float  _p1,
float  _p2,
float  _p3,
float  _p4 
)
noexcept

set the pre-registered uniform

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set
[in]_p2the float value of the parameter to set
[in]_p3the float value of the parameter to set

Definition at line 108 of file ShaderLib.cpp.

void ngl::ShaderLib::setRegisteredUniformFromColour ( const std::string _paramName,
Colour  _p1 
)
noexcept

set the pre-registered uniform from an Colour

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the vector to set from

Definition at line 82 of file ShaderLib.cpp.

void ngl::ShaderLib::setRegisteredUniformFromMat3 ( const std::string _paramName,
Mat3  _p1 
)
noexcept

set the registered uniform from Max3x3

Parameters
[in]_uniformNamethe name of the uniform in the shader to set
[in]_p1the matrix to set from (float 16) value of the parameter to set

Definition at line 57 of file ShaderLib.cpp.

References GL_FALSE.

void ngl::ShaderLib::setRegisteredUniformFromMat4 ( const std::string _registeredUniformName,
Mat4  _p1 
)
noexcept

set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail

Parameters
[in]_registeredUniformNamethe name of the registered uniform in the shader to set
[in]_p1the matrix to set from (float 16) value of the parameter to set

Definition at line 45 of file ShaderLib.cpp.

References GL_FALSE.

void ngl::ShaderLib::setRegisteredUniformVec2 ( const std::string _paramName,
Vec2  _p1 
)
noexcept

set the pre-registered uniform from a Vector

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the vector to set from

Definition at line 93 of file ShaderLib.cpp.

void ngl::ShaderLib::setRegisteredUniformVec3 ( const std::string _paramName,
Vec3  _p1 
)
noexcept

set the pre-registered uniform from an Vector

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the vector to set from

Definition at line 87 of file ShaderLib.cpp.

void ngl::ShaderLib::setRegisteredUniformVec4 ( const std::string _paramName,
Vec4  _p1 
)
noexcept

set the pre-registered uniform from an Vec4

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the vector to set from

Definition at line 69 of file ShaderLib.cpp.

void ngl::ShaderLib::setShaderParam1f ( const std::string _paramName,
float  _p1 
)
noexcept

set a shader param by name for 1 float param note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set

Definition at line 153 of file ShaderLib.cpp.

+ Here is the caller graph for this function:

void ngl::ShaderLib::setShaderParam1i ( const std::string _paramName,
int  _p1 
)
noexcept

set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set

Definition at line 138 of file ShaderLib.cpp.

void ngl::ShaderLib::setShaderParam2f ( const std::string _paramName,
float  _p1,
float  _p2 
)
noexcept

set a shader param by name for 2 float params note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set
[in]_p2the float value of the parameter to set

Definition at line 126 of file ShaderLib.cpp.

void ngl::ShaderLib::setShaderParam3f ( const std::string _paramName,
float  _p1,
float  _p2,
float  _p3 
)
noexcept

set a shader param by name for 3 float params note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set
[in]_p2the float value of the parameter to set
[in]_p3the float value of the parameter to set

Definition at line 114 of file ShaderLib.cpp.

+ Here is the caller graph for this function:

void ngl::ShaderLib::setShaderParam4f ( const std::string _paramName,
float  _p1,
float  _p2,
float  _p3,
float  _p4 
)
noexcept

set a shader param by name for 4 float params note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the float value of the parameter to set
[in]_p2the float value of the parameter to set
[in]_p3the float value of the parameter to set
[in]_p4the float value of the parameter to set

Definition at line 102 of file ShaderLib.cpp.

+ Here is the caller graph for this function:

void ngl::ShaderLib::setShaderParamFromColour ( const std::string _paramName,
Colour  _p1 
)
noexcept

set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the vector to set from (float 4) value of the parameter to set

Definition at line 75 of file ShaderLib.cpp.

void ngl::ShaderLib::setShaderParamFromMat3 ( const std::string _paramName,
Mat3  _p1 
)
noexcept

set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the matrix to set from (float 16) value of the parameter to set

Definition at line 51 of file ShaderLib.cpp.

References GL_FALSE.

void ngl::ShaderLib::setShaderParamFromMat4 ( const std::string _paramName,
Mat4  _p1 
)
noexcept

set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the matrix to set from (float 16) value of the parameter to set

Definition at line 39 of file ShaderLib.cpp.

References GL_FALSE.

+ Here is the caller graph for this function:

void ngl::ShaderLib::setShaderParamFromVec4 ( const std::string _paramName,
Vec4  _p1 
)
noexcept

set a shader param by name for 1 int param note that the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the parameter in the shader to set
[in]_p1the vector to set from (float 4) value of the parameter to set

Definition at line 62 of file ShaderLib.cpp.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Real  _v0 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the float value of the parameter to set

Definition at line 802 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Real  _v0,
Real  _v1 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the float value of the parameter to set
[in]_v1the float value of the parameter to set

Definition at line 812 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Real  _v0,
Real  _v1,
Real  _v2 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the float value of the parameter to set
[in]_v1the float value of the parameter to set
[in]_v2the float value of the parameter to set

Definition at line 822 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Real  _v0,
Real  _v1,
Real  _v2,
Real  _v3 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the float value of the parameter to set
[in]_v1the float value of the parameter to set
[in]_v2the float value of the parameter to set
[in]_v3the float value of the parameter to set

Definition at line 832 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
GLint  _v0 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the int value of the parameter to set

Definition at line 841 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
GLint  _v0,
GLint  _v1 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the int value of the parameter to set
[in]_v1the int value of the parameter to set

Definition at line 850 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
GLint  _v0,
GLint  _v1,
GLint  _v2 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the int value of the parameter to set
[in]_v1the int value of the parameter to set
[in]_v2the int value of the parameter to set

Definition at line 859 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
GLint  _v0,
GLint  _v1,
GLint  _v2,
GLint  _v3 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the int value of the parameter to set
[in]_v1the int value of the parameter to set
[in]_v2the int value of the parameter to set
[in]_v3the int value of the parameter to set

Definition at line 868 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Colour  _v0 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the colour value of the parameter to set

Definition at line 877 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Vec2  _v0 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Vec3 value of the parameter to set

Definition at line 885 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Vec3  _v0 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Vec3 value of the parameter to set

Definition at line 893 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Vec4  _v0 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Vec4 value of the parameter to set

Definition at line 901 of file ShaderLib.cpp.

References m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Mat3  _v0 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Mat3 value of the parameter to set

Definition at line 910 of file ShaderLib.cpp.

References GL_FALSE, and m_currentShader.

void ngl::ShaderLib::setUniform ( const std::string _paramName,
Mat4  _v0 
)
noexcept

overloaded method to set shader Uniforms the shader must be the currently active shader of else this will fail

Parameters
[in]_paramNamethe name of the Uniform to set
[in]_v0the Mat4 value of the parameter to set

Definition at line 921 of file ShaderLib.cpp.

References GL_FALSE, and m_currentShader.

void ngl::ShaderLib::toggleDebug ( )
inlinenoexcept

toggle debug mode

Definition at line 98 of file ShaderLib.h.

void ngl::ShaderLib::use ( const std::string _name)
noexcept

set active shader to name (if not found sets glProgramObject(0)

Parameters
_namethe name of the ShaderProgram to use

Definition at line 507 of file ShaderLib.cpp.

References glUseProgram, m_currentShader, and m_shaderPrograms.

+ Here is the caller graph for this function:

void ngl::ShaderLib::useNullProgram ( )
noexcept

use the null program (this will turn off any shaders), if using some drivers this will go to the fixed function pipeline

Definition at line 632 of file ShaderLib.cpp.

References m_currentShader, m_nullProgram, and ngl::ShaderProgram::use().

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class Singleton< ShaderLib >
friend

Definition at line 57 of file ShaderLib.h.

Member Data Documentation

std::string ngl::ShaderLib::m_currentShader
protected

the name of the currently active shader

Definition at line 652 of file ShaderLib.h.

bool ngl::ShaderLib::m_debugState
protected

flag to indicate the debug state

Definition at line 656 of file ShaderLib.h.

ShaderProgram* ngl::ShaderLib::m_nullProgram
protected

null ShaderProgram so we can return when shader not know;

Definition at line 648 of file ShaderLib.h.

unsigned int ngl::ShaderLib::m_numShaders
protected

the nunmber of shaders loaded

Definition at line 660 of file ShaderLib.h.

std::unordered_map<std::string,ShaderProgram *> ngl::ShaderLib::m_shaderPrograms
protected

a map of shader Programs using name as key to shader pointer

Definition at line 640 of file ShaderLib.h.

std::unordered_map<std::string,Shader *> ngl::ShaderLib::m_shaders
protected

map of shaders using name as key

Definition at line 644 of file ShaderLib.h.


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