SuperTuxKart
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Shader< T, Args > Class Template Reference

The main templated base class for all shaders that do not use textures. More...

#include <shader.hpp>

Inheritance diagram for Shader< T, Args >:
Inheritance graph
[legend]

Public Member Functions

void setUniforms (const Args &... args) const
 Sets the uniforms for this shader. More...
 
template<typename... T1>
void assignTextureUnit (GLuint index, const char *uniform, T1... rest)
 Variadic top level/public interface. More...
 
 Shader ()
 Constructor. More...
 
template<typename ... Types>
void loadProgram (AttributeType type, Types ... args)
 Load a list of shaders and links them all together.
 
void drawFullScreenEffect (Args...args)
 
- Public Member Functions inherited from ShaderBase
 ShaderBase ()
 Constructor, which adds the shader to all instantiated shaders (for the reload-all-shaders debug option).
 
int loadTFBProgram (const std::string &vertex_file_path, const char **varyings, unsigned varyingscount)
 Loads a transform feedback buffer shader with a given number of varying parameters.
 
GLuint createVAO ()
 
void use ()
 Activates the shader calling glUseProgram. More...
 
GLuint getUniformLocation (const char *name)
 

Protected Member Functions

template<typename... U>
void assignUniforms (U... rest)
 This variadic template collects all names of uniforms in a std::vector. More...
 
template<typename ... Types>
void printFileList (GLint shader_type, const char *filepath, Types ... args)
 Variadic template to print a list of file names. More...
 
- Protected Member Functions inherited from ShaderBase
template<typename ... Types>
void loadAndAttachShader ()
 Ends recursion. More...
 
template<typename ... Types>
void loadAndAttachShader (GLint shader_type, const std::string &name, Types ... args)
 
template<typename ... Types>
void loadAndAttachShader (GLint shader_type, const char *name, Types ... args)
 Convenience interface using const char. More...
 
- Protected Member Functions inherited from Singleton< T >
 Singleton ()
 Constructor.
 
virtual ~Singleton ()
 Destructor.
 

Private Member Functions

void bindPoint (const char *name, int index)
 Finds the specified uniform block and assigns a binding point to it. More...
 
void assignUniformsImpl ()
 End of recursive implementation of assignUniforms. More...
 
template<typename... U>
void assignUniformsImpl (const char *name, U... rest)
 Recursive implementation of assignniforms. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const std::vector< float > &v, Args1... arg) const
 Implementation for setUniforms for a vector<float> uniform. More...
 
template<unsigned N = 0>
void setUniformsImpl () const
 End of recursion for setUniforms implementation.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::core::matrix4 &mat, Args1... arg) const
 Implementation for setUniforms for a matrix uniform. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::video::SColorf &col, Args1... arg) const
 Implementation for setUniforms for a matrix SColorF values. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::video::SColor &col, Args1... arg) const
 Implementation for setUniforms for a SColor uniform. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const std::array< float, 4 > &ff, Args1... arg) const
 Implementation for setUniforms for a 4 floats uniform. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::core::vector3df &v, Args1... arg) const
 Implementation for setUniforms for a vector3df uniform. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::core::vector2df &v, Args1... arg) const
 Implementation for setUniforms for a vector2df uniform. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::core::dimension2df &v, Args1... arg) const
 Implementation for setUniforms for a dimension2df uniform. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (float f, Args1... arg) const
 Implementation for setUniforms for a float uniform. More...
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (int f, Args1... arg) const
 Implementation for setUniforms for an int uniform. More...
 
template<typename ... Types>
void printFileList ()
 End recursion for variadic template. More...
 
void assignTextureUnitNoUse ()
 End of recursion. More...
 
template<typename... T1>
void assignTextureUnitNoUse (GLuint index, const char *uniform, T1... rest)
 Recursive implementation of assignTextureUnit, but without the call to gluseProgram (which is done by the public interface). More...
 

Private Attributes

std::vector< GLuint > m_uniforms
 

Additional Inherited Members

- Static Public Member Functions inherited from ShaderBase
static void killShaders ()
 
- Static Public Member Functions inherited from Singleton< T >
static T * getInstance ()
 Used to get the instance.
 
static void kill ()
 Used to kill the singleton, if needed.
 
- Protected Types inherited from ShaderBase
enum  AttributeType { OBJECT, PARTICLES_SIM, PARTICLES_RENDERING, SKINNED_MESH }
 
- Protected Attributes inherited from ShaderBase
GLuint m_program
 OpenGL's program id. More...
 
std::vector< std::shared_ptr< GLuint > > m_shaders
 
- Static Protected Attributes inherited from ShaderBase
static std::vector< void(*)()> m_all_kill_functions
 Maintains a list of all shaders. More...
 

Detailed Description

template<typename T, typename... Args>
class Shader< T, Args >

The main templated base class for all shaders that do not use textures.

The template arguments are the types of the shader's uniforms. This allows compile time checks for the number of arguments when setting the name of the shader arguments.

Constructor & Destructor Documentation

◆ Shader()

template<typename T, typename... Args>
Shader< T, Args >::Shader ( )
inline

Constructor.

Adds the static kill function of this shader to the list of all kill function, which is used for the debugging feature of reloading all shaders.

Member Function Documentation

◆ assignTextureUnit()

template<typename T, typename... Args>
template<typename... T1>
void Shader< T, Args >::assignTextureUnit ( GLuint  index,
const char *  uniform,
T1...  rest 
)
inline

Variadic top level/public interface.

It does the calls to glUseProgram and uses assignTextureUnitNoUse() in recursion to avoid unnecessary calls to glUseProgram.

Parameters
indexIndex of the texture.
uniformUniform name.

◆ assignTextureUnitNoUse() [1/2]

template<typename T, typename... Args>
void Shader< T, Args >::assignTextureUnitNoUse ( )
inlineprivate

End of recursion.

◆ assignTextureUnitNoUse() [2/2]

template<typename T, typename... Args>
template<typename... T1>
void Shader< T, Args >::assignTextureUnitNoUse ( GLuint  index,
const char *  uniform,
T1...  rest 
)
inlineprivate

Recursive implementation of assignTextureUnit, but without the call to gluseProgram (which is done by the public interface).

◆ assignUniforms()

template<typename T, typename... Args>
template<typename... U>
void Shader< T, Args >::assignUniforms ( U...  rest)
inlineprotected

This variadic template collects all names of uniforms in a std::vector.

It used assignUnfiromsImpl for the actual recursive implementation.

◆ assignUniformsImpl() [1/2]

template<typename T, typename... Args>
void Shader< T, Args >::assignUniformsImpl ( )
inlineprivate

End of recursive implementation of assignUniforms.

◆ assignUniformsImpl() [2/2]

template<typename T, typename... Args>
template<typename... U>
void Shader< T, Args >::assignUniformsImpl ( const char *  name,
U...  rest 
)
inlineprivate

Recursive implementation of assignniforms.

It collects the unfirom locations in m_uniform, then recursing.

Parameters
nameName of the uniform.

◆ bindPoint()

template<typename T, typename... Args>
void Shader< T, Args >::bindPoint ( const char *  name,
int  index 
)
inlineprivate

Finds the specified uniform block and assigns a binding point to it.

◆ printFileList() [1/2]

template<typename T, typename... Args>
template<typename ... Types>
void Shader< T, Args >::printFileList ( GLint  shader_type,
const char *  filepath,
Types ...  args 
)
inlineprotected

Variadic template to print a list of file names.

Parameters
shader_typeIgnored (used since the variadic calling function has this parameter).
filepathName of the file to print.

◆ printFileList() [2/2]

template<typename T, typename... Args>
template<typename ... Types>
void Shader< T, Args >::printFileList ( )
inlineprivate

End recursion for variadic template.

◆ setUniforms()

template<typename T, typename... Args>
void Shader< T, Args >::setUniforms ( const Args &...  args) const
inline

Sets the uniforms for this shader.

◆ setUniformsImpl() [1/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( const std::vector< float > &  v,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a vector<float> uniform.

◆ setUniformsImpl() [2/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( const irr::core::matrix4 &  mat,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a matrix uniform.

◆ setUniformsImpl() [3/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( const irr::video::SColorf &  col,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a matrix SColorF values.

◆ setUniformsImpl() [4/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( const irr::video::SColor &  col,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a SColor uniform.

◆ setUniformsImpl() [5/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( const std::array< float, 4 > &  ff,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a 4 floats uniform.

◆ setUniformsImpl() [6/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( const irr::core::vector3df &  v,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a vector3df uniform.

◆ setUniformsImpl() [7/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( const irr::core::vector2df &  v,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a vector2df uniform.

◆ setUniformsImpl() [8/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( const irr::core::dimension2df &  v,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a dimension2df uniform.

◆ setUniformsImpl() [9/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( float  f,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for a float uniform.

◆ setUniformsImpl() [10/10]

template<typename T, typename... Args>
template<unsigned N = 0, typename... Args1>
void Shader< T, Args >::setUniformsImpl ( int  f,
Args1...  arg 
) const
inlineprivate

Implementation for setUniforms for an int uniform.


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