SuperTuxKart
Loading...
Searching...
No Matches
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.
 
template<typename... T1>
void assignTextureUnit (GLuint index, const char *uniform, T1... rest)
 Variadic top level/public interface.
 
 Shader ()
 Constructor.
 
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.
 
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.
 
template<typename ... Types>
void printFileList (GLint shader_type, const char *filepath, Types ... args)
 Variadic template to print a list of file names.
 
- Protected Member Functions inherited from ShaderBase
template<typename ... Types>
void loadAndAttachShader ()
 Ends recursion.
 
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.
 
- 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.
 
void assignUniformsImpl ()
 End of recursive implementation of assignUniforms.
 
template<typename... U>
void assignUniformsImpl (const char *name, U... rest)
 Recursive implementation of assignniforms.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const std::vector< float > &v, Args1... arg) const
 Implementation for setUniforms for a vector<float> uniform.
 
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.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::video::SColorf &col, Args1... arg) const
 Implementation for setUniforms for a matrix SColorF values.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::video::SColor &col, Args1... arg) const
 Implementation for setUniforms for a SColor uniform.
 
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.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::core::vector3df &v, Args1... arg) const
 Implementation for setUniforms for a vector3df uniform.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::core::vector2df &v, Args1... arg) const
 Implementation for setUniforms for a vector2df uniform.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (const irr::core::dimension2df &v, Args1... arg) const
 Implementation for setUniforms for a dimension2df uniform.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (float f, Args1... arg) const
 Implementation for setUniforms for a float uniform.
 
template<unsigned N = 0, typename... Args1>
void setUniformsImpl (int f, Args1... arg) const
 Implementation for setUniforms for an int uniform.
 
template<typename ... Types>
void printFileList ()
 End recursion for variadic template.
 
void assignTextureUnitNoUse ()
 End of recursion.
 
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).
 

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.
 
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.
 

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.

◆ 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()

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.

◆ printFileList()

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.

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