ReTo  0.3.7
reto::ShaderProgram Class Reference

Class to manage shaders and programs. More...

#include <ShaderProgram.h>

+ Collaboration diagram for reto::ShaderProgram:

Public Member Functions

bool load (const std::string &vsFile, const std::string &fsFile)
 Method to load and add a vertex and fragment shaders from file. More...
 
bool loadVertexShader (const std::string &file)
 Method to load and add a vertex shader from file. More...
 
bool loadFragmentShader (const std::string &file)
 Method to load and add a fragment shader from file. More...
 
bool loadFromText (const std::string &vsSource, const std::string &fsSource)
 Method to load and add a vertex and fragment shaders from text. More...
 
bool loadVertexShaderFromText (const std::string &source)
 Method to load and add a vertex shader from text. More...
 
bool loadFragmentShaderFromText (const std::string &source)
 Method to load and add a fragment shader from text. More...
 
bool compileAndLink (void)
 Method to compile a program. More...
 
unsigned int program (void)
 Method to get Program id. More...
 
void use (void)
 Method to enable a program.
 
void unuse (void)
 Method to disable a program (not necessary)
 
void addAttribute (const std::string &attr)
 Method to catching an attribute value of a vertex shader. More...
 
void addAttributes (const std::vector< char * > attrs)
 Method to catching an array of attribute values of a vertex shader. More...
 
void bindAttribute (const std::string &attr, unsigned int index)
 Method to bind a specific index to a attribute value. More...
 
void addUniform (const std::string &unifs)
 Method to catching an uniform value. More...
 
void addUniforms (const std::vector< char * > uniforms)
 Method to catching an array of uniform values. More...
 
void bindUniform (const std::string &unif, unsigned int index)
 Method to bind a specific index to a uniform value. More...
 
bool isUniformCached (const std::string &unif) const
 Method to check if uniform exist (only check in uniform cache) More...
 
bool isAttributeCached (const std::string &attr) const
 Method to check if attribute exist (only check in attribute cache) More...
 
void addUbo (const std::string &ubo)
 Method to catching an uniform buffer object. More...
 
int attribute (const std::string &_attr)
 Method to get a attribute index in cache. More...
 
int uniform (const std::string &_unif)
 Method to get a uniform index in cache. More...
 
int ubo (const std::string &ubo)
 Method to get a Uniform Buffer Object index in cache. More...
 
int subprogram (const std::string &name, int shaderType)
 Method to get a subprogram index of a specific kind of shader in cache. More...
 
int operator() (const std::string &_attr)
 Method to get a attribute index in cache. More...
 
int operator[] (const std::string &_unif)
 Method to get a uniform index in cache. More...
 
void sendUniformb (const std::string &uniform, bool val)
 Method to send a boolean. More...
 
void sendUniformi (const std::string &uniform, int val)
 Method to send an integer. More...
 
void sendUniformu (const std::string &uniform, unsigned int val)
 Method to send an unsigned integer. More...
 
void sendUniformf (const std::string &uniform, float val)
 Method to send a float. More...
 
void sendUniform (const std::string &uniform, float x, float y, float z)
 Method to send a vec3 with separated data. More...
 
void sendUniform2v (const std::string &uniform, const std::vector< float > &data)
 Method to send a vec2. More...
 
void sendUniform2v (const std::string &uniform, const float *data)
 Method to send a vec2. More...
 
void sendUniform3v (const std::string &uniform, const std::vector< float > &data)
 Method to send a vec3. More...
 
void sendUniform3v (const std::string &uniform, const float *data)
 Method to send a vec3. More...
 
void sendUniform4v (const std::string &uniform, const std::vector< float > &data)
 Method to send a vec4. More...
 
void sendUniform4v (const std::string &uniform, const float *data)
 Method to send a vec4. More...
 
void sendUniform2iv (const std::string &uniform, const unsigned int *data)
 Method to send a ivec2. More...
 
void sendUniform2iv (const std::string &uniform, const std::vector< unsigned int > &data)
 Method to send a ivec2. More...
 
void sendUniform3iv (const std::string &uniform, const unsigned int *data)
 Method to send a ivec3. More...
 
void sendUniform3iv (const std::string &uniform, const std::vector< unsigned int > &data)
 Method to send a ivec3. More...
 
void sendUniform4iv (const std::string &uniform, const unsigned int *data)
 Method to send a ivec4. More...
 
void sendUniform4iv (const std::string &uniform, const std::vector< unsigned int > &data)
 Method to send a ivec4. More...
 
void sendUniform3m (const std::string &uniform, const std::vector< float > &data)
 Method to send a mat3. More...
 
void sendUniform3m (const std::string &uniform, const float *data)
 Method to send a mat3. More...
 
void sendUniform4m (const std::string &uniform, const std::vector< float > &data, bool inverse=false)
 Method to send a mat4. More...
 
void sendUniform4m (const std::string &uniform, const float *data, bool inverse=false)
 Method to send a mat4. More...
 
void create (void)
 Method to create program and attach all shaders.
 
bool link (void)
 Method to link program and check status.
 
bool isLinked (void) const
 
void autocatching (bool attributes=true, bool uniforms=true)
 Autocatching attributes and uniforms. More...
 

Protected Member Functions

void _destroy ()
 
bool _load (const std::string &file, int type)
 
bool _loadFromText (const std::string &source, int type)
 

Protected Attributes

unsigned int _program
 
std::map< std::string, unsigned int > _attrsList
 
std::map< std::string, unsigned int > _uniformList
 
std::map< std::string, unsigned int > _uboList
 
std::vector< unsigned int > _shaders
 
bool _isLinked
 

Detailed Description

Class to manage shaders and programs.

Definition at line 48 of file ShaderProgram.h.

Member Function Documentation

void reto::ShaderProgram::addAttribute ( const std::string &  attr)

Method to catching an attribute value of a vertex shader.

Parameters
attrAttribute name
void reto::ShaderProgram::addAttributes ( const std::vector< char * >  attrs)

Method to catching an array of attribute values of a vertex shader.

Parameters
attrsAttribute vector names
void reto::ShaderProgram::addUbo ( const std::string &  ubo)

Method to catching an uniform buffer object.

Parameters
uboUniform Buffer Object name
void reto::ShaderProgram::addUniform ( const std::string &  unifs)

Method to catching an uniform value.

Parameters
unifsUniform name
void reto::ShaderProgram::addUniforms ( const std::vector< char * >  uniforms)

Method to catching an array of uniform values.

Parameters
uniformsUniform vector names
int reto::ShaderProgram::attribute ( const std::string &  _attr)

Method to get a attribute index in cache.

Parameters
_attrAttribute name
Returns
Attribute index
void reto::ShaderProgram::autocatching ( bool  attributes = true,
bool  uniforms = true 
)

Autocatching attributes and uniforms.

Parameters
attributesAutocatching attributes (default= true)
uniformsAutocatching attributes (default= true)
void reto::ShaderProgram::bindAttribute ( const std::string &  attr,
unsigned int  index 
)

Method to bind a specific index to a attribute value.

Parameters
attrAttribute name
indexAttribute index
void reto::ShaderProgram::bindUniform ( const std::string &  unif,
unsigned int  index 
)

Method to bind a specific index to a uniform value.

Parameters
unifUniform name
indexUniform index
bool reto::ShaderProgram::compileAndLink ( void  )

Method to compile a program.

Returns
If program compile and link OK
bool reto::ShaderProgram::isAttributeCached ( const std::string &  attr) const

Method to check if attribute exist (only check in attribute cache)

Parameters
attrAttribute name
Returns
bool
bool reto::ShaderProgram::isUniformCached ( const std::string &  unif) const

Method to check if uniform exist (only check in uniform cache)

Parameters
unifUniform name
Returns
bool
bool reto::ShaderProgram::load ( const std::string &  vsFile,
const std::string &  fsFile 
)

Method to load and add a vertex and fragment shaders from file.

Parameters
vsFileVertex shader file source
fsFileFragment shader source
Returns
Shader loaded
bool reto::ShaderProgram::loadFragmentShader ( const std::string &  file)

Method to load and add a fragment shader from file.

Parameters
fileShader file source
Returns
Shader loaded
bool reto::ShaderProgram::loadFragmentShaderFromText ( const std::string &  source)

Method to load and add a fragment shader from text.

Parameters
sourceShader source
Returns
Shader loaded
bool reto::ShaderProgram::loadFromText ( const std::string &  vsSource,
const std::string &  fsSource 
)

Method to load and add a vertex and fragment shaders from text.

Parameters
vsSourceVertex shader source
fsSourceFragment shader source
Returns
Shader loaded
bool reto::ShaderProgram::loadVertexShader ( const std::string &  file)

Method to load and add a vertex shader from file.

Parameters
fileShader file source
Returns
Shader loaded
bool reto::ShaderProgram::loadVertexShaderFromText ( const std::string &  source)

Method to load and add a vertex shader from text.

Parameters
sourceShader source
Returns
Shader loaded
int reto::ShaderProgram::operator() ( const std::string &  _attr)

Method to get a attribute index in cache.

Parameters
_attrAttribute name
Returns
Attribute index
int reto::ShaderProgram::operator[] ( const std::string &  _unif)

Method to get a uniform index in cache.

Parameters
_unifUniform name
Returns
Uniform index
unsigned int reto::ShaderProgram::program ( void  )

Method to get Program id.

Returns
program identifier.
void reto::ShaderProgram::sendUniform ( const std::string &  uniform,
float  x,
float  y,
float  z 
)

Method to send a vec3 with separated data.

Parameters
uniformUniform name
xFirst element
ySecond element
zThird element
void reto::ShaderProgram::sendUniform2iv ( const std::string &  uniform,
const unsigned int *  data 
)

Method to send a ivec2.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform2iv ( const std::string &  uniform,
const std::vector< unsigned int > &  data 
)

Method to send a ivec2.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform2v ( const std::string &  uniform,
const std::vector< float > &  data 
)

Method to send a vec2.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform2v ( const std::string &  uniform,
const float *  data 
)

Method to send a vec2.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform3iv ( const std::string &  uniform,
const unsigned int *  data 
)

Method to send a ivec3.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform3iv ( const std::string &  uniform,
const std::vector< unsigned int > &  data 
)

Method to send a ivec3.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform3m ( const std::string &  uniform,
const std::vector< float > &  data 
)

Method to send a mat3.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform3m ( const std::string &  uniform,
const float *  data 
)

Method to send a mat3.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform3v ( const std::string &  uniform,
const std::vector< float > &  data 
)

Method to send a vec3.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform3v ( const std::string &  uniform,
const float *  data 
)

Method to send a vec3.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform4iv ( const std::string &  uniform,
const unsigned int *  data 
)

Method to send a ivec4.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform4iv ( const std::string &  uniform,
const std::vector< unsigned int > &  data 
)

Method to send a ivec4.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform4m ( const std::string &  uniform,
const std::vector< float > &  data,
bool  inverse = false 
)

Method to send a mat4.

Parameters
uniformUniform name
dataData
inverseSpecifies whether to transpose the matrix as the values are loaded into the uniform variable
void reto::ShaderProgram::sendUniform4m ( const std::string &  uniform,
const float *  data,
bool  inverse = false 
)

Method to send a mat4.

Parameters
uniformUniform name
dataData
inverseSpecifies whether to transpose the matrix as the values are loaded into the uniform variable
void reto::ShaderProgram::sendUniform4v ( const std::string &  uniform,
const std::vector< float > &  data 
)

Method to send a vec4.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniform4v ( const std::string &  uniform,
const float *  data 
)

Method to send a vec4.

Parameters
uniformUniform name
dataData
void reto::ShaderProgram::sendUniformb ( const std::string &  uniform,
bool  val 
)

Method to send a boolean.

Parameters
uniformUniform name
valBoolean data
void reto::ShaderProgram::sendUniformf ( const std::string &  uniform,
float  val 
)

Method to send a float.

Parameters
uniformUniform name
valFloat data
void reto::ShaderProgram::sendUniformi ( const std::string &  uniform,
int  val 
)

Method to send an integer.

Parameters
uniformUniform name
valInt data
void reto::ShaderProgram::sendUniformu ( const std::string &  uniform,
unsigned int  val 
)

Method to send an unsigned integer.

Parameters
uniformUniform name
valUnsigned integer data
int reto::ShaderProgram::subprogram ( const std::string &  name,
int  shaderType 
)

Method to get a subprogram index of a specific kind of shader in cache.

Parameters
nameSubprogram name
shaderTypeOpenGL Shader type
Returns
Subprogram index
int reto::ShaderProgram::ubo ( const std::string &  ubo)

Method to get a Uniform Buffer Object index in cache.

Parameters
uboUniform Buffer Object name
Returns
Uniform Buffer Object index
int reto::ShaderProgram::uniform ( const std::string &  _unif)

Method to get a uniform index in cache.

Parameters
_unifUniform name
Returns
Uniform index

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