hx3d  1
2D/3D Simple Game Framework
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
hx3d::graphics::Shader Class Reference

Shader definition class. More...

#include <shader.hpp>

Public Member Functions

 Shader (std::string pathToShader)
 Create a shader from a path. The path must be without extension, e.g. shaders/test. More...
 
 Shader (std::string vert, std::string frag)
 Create a shader from a vertex shader and a fragment shader in text form. More...
 
GLuint getProgramID () const
 Get the program ID. More...
 
void setUniform1f (std::string uniform, float value)
 Send a single float to the shader. More...
 
void setUniform2f (std::string uniform, glm::vec2 vector)
 Send a vec2 to the shader. More...
 
void setUniform3f (std::string uniform, glm::vec3 vector)
 Send a vec3 to the shader. More...
 
void setUniform4f (std::string uniform, glm::vec4 vector)
 Send a vec4 to the shader. More...
 
void setUniformMatrix3f (std::string uniform, glm::mat3 matrix)
 Send a mat3 to the shader. More...
 
void setUniformMatrix4f (std::string uniform, glm::mat4 matrix)
 Send a mat4 to the shader. More...
 
GLint getAttribute (std::string name)
 Get the wanted attribute id. More...
 
GLint getUniform (std::string name)
 Get the wanted uniform id. More...
 

Static Public Member Functions

static void use (Ptr< Shader > shader)
 Use the shader as the current shader. More...
 
static void disable ()
 Clear the current shader.
 
static void setProgramAnalyzing (bool value)
 Analyse the shaders (debug mode). More...
 

Protected Member Functions

bool compile (const std::string &vert, const std::string &frag)
 Compile the vertex and fragment shaders. More...
 
bool compile (GLuint &shaderId, GLenum type, const std::string &content)
 Compile one shader using it's id, type and content. More...
 
bool createProgram ()
 Create the shader program. More...
 
void analyzeAttributes ()
 Analyze the shader attributes (debug mode).
 
void analyzeUniforms ()
 Analyze the shader uniforms (debug mode).
 
std::string getParameterType (GLenum type)
 Get the parameter type (debug mode). More...
 

Protected Attributes

GLuint _vertexID
 Vertex shader ID.
 
GLuint _fragmentID
 Fragment shader ID.
 
GLuint _programID
 Shader program ID.
 
std::map< std::string, GLint > _activeAttributes
 Active attributes map.
 
std::map< std::string, GLint > _activeUniforms
 Active uniforms map.
 

Static Protected Attributes

static bool _programsAnalyzed = false
 Are the programs analyzed ?
 

Detailed Description

Shader definition class.

Manage vertex and fragment shader.

Definition at line 42 of file shader.hpp.

Constructor & Destructor Documentation

hx3d::graphics::Shader::Shader ( std::string  pathToShader)
explicit

Create a shader from a path. The path must be without extension, e.g. shaders/test.

This class will load the fragment and the vertex shader, using the extensions .frag.glsl and .vert.glsl.

Parameters
pathToShaderPath to shader

Definition at line 33 of file shader.cpp.

hx3d::graphics::Shader::Shader ( std::string  vert,
std::string  frag 
)

Create a shader from a vertex shader and a fragment shader in text form.

Parameters
vertVertex shader code
fragFragment shader code

Definition at line 57 of file shader.cpp.

Member Function Documentation

bool hx3d::graphics::Shader::compile ( const std::string &  vert,
const std::string &  frag 
)
protected

Compile the vertex and fragment shaders.

Parameters
vertVertex shader code
fragFragment shader code
Returns
All good / Error

Definition at line 77 of file shader.cpp.

bool hx3d::graphics::Shader::compile ( GLuint &  shaderId,
GLenum  type,
const std::string &  content 
)
protected

Compile one shader using it's id, type and content.

Parameters
shaderIdID
typeShader type
contentShader code
Returns
All good / Error

Definition at line 99 of file shader.cpp.

bool hx3d::graphics::Shader::createProgram ( )
protected

Create the shader program.

Returns
All good / Error

Definition at line 129 of file shader.cpp.

GLint hx3d::graphics::Shader::getAttribute ( std::string  name)

Get the wanted attribute id.

Parameters
nameName
Returns
Attribute ID

Definition at line 171 of file shader.cpp.

std::string hx3d::graphics::Shader::getParameterType ( GLenum  type)
protected

Get the parameter type (debug mode).

Parameters
typeType
Returns
Parameter type

Definition at line 264 of file shader.cpp.

GLuint hx3d::graphics::Shader::getProgramID ( ) const

Get the program ID.

Returns
Program ID.

Definition at line 325 of file shader.cpp.

GLint hx3d::graphics::Shader::getUniform ( std::string  name)

Get the wanted uniform id.

Parameters
nameName
Returns
Attribute ID

Definition at line 180 of file shader.cpp.

void hx3d::graphics::Shader::setProgramAnalyzing ( bool  value)
static

Analyse the shaders (debug mode).

Parameters
valueTrue/False

Definition at line 320 of file shader.cpp.

void hx3d::graphics::Shader::setUniform1f ( std::string  uniform,
float  value 
)

Send a single float to the shader.

Parameters
uniformUniform name
valueValue

Definition at line 329 of file shader.cpp.

void hx3d::graphics::Shader::setUniform2f ( std::string  uniform,
glm::vec2  vector 
)

Send a vec2 to the shader.

Parameters
uniformUniform name
vectorValues

Definition at line 334 of file shader.cpp.

void hx3d::graphics::Shader::setUniform3f ( std::string  uniform,
glm::vec3  vector 
)

Send a vec3 to the shader.

Parameters
uniformUniform name
vectorValues

Definition at line 339 of file shader.cpp.

void hx3d::graphics::Shader::setUniform4f ( std::string  uniform,
glm::vec4  vector 
)

Send a vec4 to the shader.

Parameters
uniformUniform name
vectorValues

Definition at line 344 of file shader.cpp.

void hx3d::graphics::Shader::setUniformMatrix3f ( std::string  uniform,
glm::mat3  matrix 
)

Send a mat3 to the shader.

Parameters
uniformUniform name
matrixValues

Definition at line 349 of file shader.cpp.

void hx3d::graphics::Shader::setUniformMatrix4f ( std::string  uniform,
glm::mat4  matrix 
)

Send a mat4 to the shader.

Parameters
uniformUniform name
matrixValues

Definition at line 354 of file shader.cpp.

void hx3d::graphics::Shader::use ( Ptr< Shader shader)
static

Use the shader as the current shader.

Parameters
shaderShader (Ptr)

Definition at line 312 of file shader.cpp.


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