6 #include <unordered_map>
7 #include "vmmlib/matrix.hpp"
35 typedef std::unordered_map< std::string, Attrib >
AttribMap;
59 virtual void setUniform(
const std::string &name,
const vmml::Matrix4f &arg);
65 virtual void setUniform(
const std::string &name,
const vmml::Matrix3f &arg);
71 virtual void setUniform(
const std::string &name,
const vmml::Vector4f &arg);
77 virtual void setUniform(
const std::string &name,
const vmml::Vector3f &arg);
83 virtual void setUniform(
const std::string &name, GLfloat arg);
103 virtual GLint
registerAttrib(
const std::string &name, GLint size, GLenum type, GLsizei stride,
size_t offset);
121 virtual GLint
findAttribLocation(
const std::string &name, GLint size, GLenum type, GLsizei stride,
size_t offset);
157 template<
typename T >
163 for (
auto i = arg.cbegin(); i != arg.cend(); ++i)
178 glDeleteProgram(_programID);
187 virtual bool compile(GLuint* shader, GLenum type,
const std::string &src);
195 GLuint _programID = 0;
198 GLint _maxTexUnits = 0;
200 LocationMap _uniformLocations;
203 GLuint _shaderMaxLights;
204 bool _variableNumberOfLights;
205 bool _ambientLighting;
206 bool _diffuseLighting;
207 bool _specularLighting;
208 bool _cubicReflectionMap;
bool supportsSpecularLighting() const
Returns true if the shader supports specular lighting.
Definition: Shader.h:151
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) ...
Definition: Shader.cpp:168
std::shared_ptr< Texture > TexturePtr
Definition: Texture.h:67
std::shared_ptr< Shader > ShaderPtr
Definition: Shader.h:211
std::unordered_map< std::string, Attrib > AttribMap
Definition: Shader.h:35
virtual void bind()
Binds the shader and its attributes.
Definition: Shader.cpp:197
bool supportsDiffuseLighting() const
Returns true if the shader supports diffuse lighting.
Definition: Shader.h:147
GLuint getProgramID()
Returns the shader ID.
Definition: Shader.h:107
An interface for the underlying data of a shader.
Definition: IShaderData.h:10
virtual GLint registerAttrib(const std::string &name, GLint size, GLenum type, GLsizei stride, size_t offset)
Register an attribute.
Definition: Shader.cpp:137
void setUniforms(const T &arg)
Sets multiple uniforms.
Definition: Shader.h:161
virtual void resetTexUnit()
Definition: Shader.cpp:192
size_t offset
Definition: Shader.h:29
bool supportsVariableNumberOfLights() const
Returns true if the number of lights is variable in the shader.
Definition: Shader.h:139
virtual bool validate()
Definition: Shader.cpp:272
virtual bool link()
Definition: Shader.cpp:251
virtual GLint getUniformLocation(const std::string &name)
Returns uniform location.
Definition: Shader.cpp:182
virtual ~Shader()
Virtual destructor.
Definition: Shader.h:46
virtual GLint getAttribLocation(const std::string &name)
Returns attribute location.
Definition: Shader.cpp:187
GLenum type
Definition: Shader.h:27
GLint getCurrentTexUnit()
Returns the current texture unit used in the shader.
Definition: Shader.h:171
GLint loc
Definition: Shader.h:25
GLuint getMaxLights()
Get the maximum number of lights used.
Definition: Shader.h:135
bool supportsCubicReflectionMap() const
Returns true if the shader supports a cubic reflection map.
Definition: Shader.h:155
GLint size
Definition: Shader.h:26
virtual bool compile(GLuint *shader, GLenum type, const std::string &src)
Definition: Shader.cpp:218
A shader class that represents a program to be run on the GPU.
Definition: Shader.h:17
GLsizei stride
Definition: Shader.h:28
virtual GLint findUniformLocation(const std::string &name)
Returns uniform location (tries to register uniform if not already available)
Definition: Shader.cpp:154
std::unordered_map< std::string, GLint > LocationMap
Definition: Shader.h:34
Shader(const IShaderData &shaderData)
Constructor.
Definition: Shader.cpp:6
virtual void setUniform(const std::string &name, const vmml::Matrix4f &arg)
Pass a 4 dimensional matrix to the shader.
Definition: Shader.cpp:79
virtual void deleteShader()
Deletes the shader.
Definition: Shader.h:175
virtual GLint registerUniform(const std::string &name)
Register a uniform.
Definition: Shader.cpp:126
bool supportsAmbientLighting() const
Returns true if the shader supports ambient lighting.
Definition: Shader.h:143