A shader class that represents a program to be run on the GPU. More...

#include <Shader.h>

Classes

struct  Attrib
 

Public Types

typedef std::unordered_map< std::string, GLint > LocationMap
 
typedef std::unordered_map< std::string, AttribAttribMap
 

Public Member Functions

 Shader (const IShaderData &shaderData)
 Constructor. More...
 
virtual ~Shader ()
 Virtual destructor. More...
 
virtual void bind ()
 Binds the shader and its attributes. More...
 
virtual void setUniform (const std::string &name, const vmml::Matrix4f &arg)
 Pass a 4 dimensional matrix to the shader. More...
 
virtual void setUniform (const std::string &name, const vmml::Matrix3f &arg)
 Pass a 3 dimensional matrix to the shader. More...
 
virtual void setUniform (const std::string &name, const vmml::Vector4f &arg)
 Pass a 4 dimensional vector to the shader. More...
 
virtual void setUniform (const std::string &name, const vmml::Vector3f &arg)
 Pass a 3 dimensional vector to the shader. More...
 
virtual void setUniform (const std::string &name, GLfloat arg)
 Pass a floating-point number to the shader. More...
 
virtual void setUniform (const std::string &name, TexturePtr texture)
 Pass a texture to the shader. More...
 
virtual GLint registerUniform (const std::string &name)
 Register a uniform. More...
 
virtual GLint registerAttrib (const std::string &name, GLint size, GLenum type, GLsizei stride, size_t offset)
 Register an attribute. More...
 
GLuint getProgramID ()
 Returns the shader ID. More...
 
virtual GLint findUniformLocation (const std::string &name)
 Returns uniform location (tries to register uniform if not already available) More...
 
virtual GLint findAttribLocation (const std::string &name, GLint size, GLenum type, GLsizei stride, size_t offset)
 Returns attribute location (tries to register attribute if not already available) More...
 
virtual GLint getUniformLocation (const std::string &name)
 Returns uniform location. More...
 
virtual GLint getAttribLocation (const std::string &name)
 Returns attribute location. More...
 
GLuint getMaxLights ()
 Get the maximum number of lights used. More...
 
bool supportsVariableNumberOfLights () const
 Returns true if the number of lights is variable in the shader. More...
 
bool supportsAmbientLighting () const
 Returns true if the shader supports ambient lighting. More...
 
bool supportsDiffuseLighting () const
 Returns true if the shader supports diffuse lighting. More...
 
bool supportsSpecularLighting () const
 Returns true if the shader supports specular lighting. More...
 
bool supportsCubicReflectionMap () const
 Returns true if the shader supports a cubic reflection map. More...
 
template<typename T >
void setUniforms (const T &arg)
 Sets multiple uniforms. More...
 
GLint getCurrentTexUnit ()
 Returns the current texture unit used in the shader. More...
 
virtual void deleteShader ()
 Deletes the shader. More...
 

Protected Member Functions

virtual void resetTexUnit ()
 
virtual bool compile (GLuint *shader, GLenum type, const std::string &src)
 
virtual bool link ()
 
virtual bool validate ()
 

Detailed Description

A shader class that represents a program to be run on the GPU.

Author
Rahul Mukhi, David Steiner

Member Typedef Documentation

typedef std::unordered_map< std::string, Attrib > Shader::AttribMap
typedef std::unordered_map< std::string, GLint > Shader::LocationMap

Constructor & Destructor Documentation

Shader::Shader ( const IShaderData shaderData)

Constructor.

Parameters
[in]shaderData
virtual Shader::~Shader ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

void Shader::bind ( )
virtual

Binds the shader and its attributes.

bool Shader::compile ( GLuint *  shader,
GLenum  type,
const std::string &  src 
)
protectedvirtual
virtual void Shader::deleteShader ( )
inlinevirtual

Deletes the shader.

GLint Shader::findAttribLocation ( const std::string &  name,
GLint  size,
GLenum  type,
GLsizei  stride,
size_t  offset 
)
virtual

Returns attribute location (tries to register attribute if not already available)

Parameters
[in]nameAttribute name
[in]size
[in]type
[in]stride
[in]offset
GLint Shader::findUniformLocation ( const std::string &  name)
virtual

Returns uniform location (tries to register uniform if not already available)

Parameters
[in]nameUniform name
GLint Shader::getAttribLocation ( const std::string &  name)
virtual

Returns attribute location.

Parameters
[in]nameAttribute name
GLint Shader::getCurrentTexUnit ( )
inline

Returns the current texture unit used in the shader.

GLuint Shader::getMaxLights ( )
inline

Get the maximum number of lights used.

GLuint Shader::getProgramID ( )
inline

Returns the shader ID.

GLint Shader::getUniformLocation ( const std::string &  name)
virtual

Returns uniform location.

Parameters
[in]nameUniform name
bool Shader::link ( )
protectedvirtual
GLint Shader::registerAttrib ( const std::string &  name,
GLint  size,
GLenum  type,
GLsizei  stride,
size_t  offset 
)
virtual

Register an attribute.

Parameters
[in]nameAttribute name
[in]size
[in]type
[in]stride
[in]offset
GLint Shader::registerUniform ( const std::string &  name)
virtual

Register a uniform.

Parameters
[in]nameUniform name
void Shader::resetTexUnit ( )
protectedvirtual
void Shader::setUniform ( const std::string &  name,
const vmml::Matrix4f &  arg 
)
virtual

Pass a 4 dimensional matrix to the shader.

Parameters
[in]nameUniform name
[in]arg4 dimensional matrix
void Shader::setUniform ( const std::string &  name,
const vmml::Matrix3f &  arg 
)
virtual

Pass a 3 dimensional matrix to the shader.

Parameters
[in]nameUniform name
[in]arg3 dimensional matrix
void Shader::setUniform ( const std::string &  name,
const vmml::Vector4f &  arg 
)
virtual

Pass a 4 dimensional vector to the shader.

Parameters
[in]nameUniform name
[in]arg4 dimensional vector
void Shader::setUniform ( const std::string &  name,
const vmml::Vector3f &  arg 
)
virtual

Pass a 3 dimensional vector to the shader.

Parameters
[in]nameUniform name
[in]arg3 dimensional vector
void Shader::setUniform ( const std::string &  name,
GLfloat  arg 
)
virtual

Pass a floating-point number to the shader.

Parameters
[in]nameUniform name
[in]argFloating-point number
void Shader::setUniform ( const std::string &  name,
TexturePtr  texture 
)
virtual

Pass a texture to the shader.

Parameters
[in]nameUniform name
[in]argTexture
template<typename T >
void Shader::setUniforms ( const T &  arg)
inline

Sets multiple uniforms.

Parameters
[in]argData to pass to the shader
bool Shader::supportsAmbientLighting ( ) const
inline

Returns true if the shader supports ambient lighting.

bool Shader::supportsCubicReflectionMap ( ) const
inline

Returns true if the shader supports a cubic reflection map.

bool Shader::supportsDiffuseLighting ( ) const
inline

Returns true if the shader supports diffuse lighting.

bool Shader::supportsSpecularLighting ( ) const
inline

Returns true if the shader supports specular lighting.

bool Shader::supportsVariableNumberOfLights ( ) const
inline

Returns true if the number of lights is variable in the shader.

bool Shader::validate ( )
protectedvirtual