Maria GDK 5.0.0.738
Documentation of native code in develop branch
Loading...
Searching...
No Matches
STK::ShaderProgram Class Reference

#include <StkShaderProgram.h>

Public Member Functions

 ShaderProgram (const std::string &vertex_shader_file="", const std::string &fragment_shader_file="", const std::string &geometry_shader_file="")
 
const std::string & getVertexShaderFileName () const
 
const std::string & getFragmentShaderFileName () const
 
const std::string & getGeometryShaderFileName () const
 
const std::string & getVertexShaderSource () const
 
const std::string & getFragmentShaderSource () const
 
const std::string & getGeometryShaderSource () const
 
void setVertexShaderFileName (const std::string &vertex_shader_file)
 
void setFragmentShaderFileName (const std::string &fragment_shader_file)
 
void setGeometryShaderFileName (const std::string &geometry_shader_file)
 
void setVertexShaderSource (const std::string &vertex_shader_src)
 
void setFragmentShaderSource (const std::string &fragment_shader_src)
 
void setGeometryShaderSource (const std::string &geometry_shader_src)
 
void clearShader ()
 
bool initShader ()
 
bool parseShader (const std::string &filename, std::string &source)
 
bool compileShader (const std::string &vertex_shader_src, const GLuint &vtxShader)
 
bool linkProgram ()
 
void clearAttributeLocations ()
 
void clearUniformLocations ()
 
bool updateShader ()
 Initialize or re-link the shader as required.
 
bool isValid () const
 
void bind ()
 
GLuint handle () const
 
void setPositionAttributeName (const std::string &attrib_name)
 
const std::string & getPositionAttributeName () const
 Get attribute name for vertex positions.
 
int getAttributeLocation (const std::string &attrib_name) const
 
int getPositionAttributeLocation ()
 
void setPositionAttributePointer (int stride=0, int offset=0, int size=3)
 
void disablePositionAttributeArray ()
 
void setNormalAttributeName (const std::string &attrib_name)
 
const std::string & getNormalAttributeName () const
 Get attribute name for normal vectors.
 
int getNormalAttributeLocation ()
 
void setNormalAttributePointer (int stride=0, int offset=0, int size=3)
 
void disableNormalAttributeArray ()
 
void setTangentAttributeName (const std::string &attrib_name)
 
const std::string & getTangentAttributeName () const
 Get attribute name for tangent vectors.
 
int getTangentAttributeLocation ()
 
void setTangentAttributePointer (int stride=0, int offset=0, int size=3)
 
void disableTangentAttributeArray ()
 
void setVertexColorAttributeName (const std::string &attrib_name)
 
const std::string & getVertexColorAttributeName () const
 Get attribute name for color vectors.
 
int getVertexColorAttributeLocation ()
 
void setVertexColorAttributePointer (int stride=0, int offset=0, int size=4)
 
void disableVertexColorAttributeArray ()
 
void setTextureCoordinateAttributeName (const std::string &attrib_name)
 
const std::string & getTextureCoordinateAttributeName () const
 Get attribute name for texture coordinates.
 
int getTextureCoordinateAttributeLocation ()
 
void setTextureCoordinateAttributePointer (int stride=0, int offset=0, int size=2)
 
void disableTextureCoordinateAttributeArray ()
 
void setBoneWeightsAttributeName (const std::string &attrib_name)
 
const std::string & getBoneWeightsAttributeName () const
 Get attribute name for bone weights.
 
int getBoneWeightsAttributeLocation ()
 
void setBoneWeightsAttributePointer (int stride=0, int offset=0, int size=4)
 
void disableBoneWeightsAttributeArray ()
 
void setBoneIndicesAttributeName (const std::string &attrib_name)
 
const std::string & getBoneIndicesAttributeName () const
 Get attribute name for bone weights.
 
int getBoneIndicesAttributeLocation ()
 
void setBoneIndicesAttributePointer (int stride=0, int offset=0, int size=4)
 
void disableBoneIndicesAttributeArray ()
 
void bindAttributeLocation (const std::string &name, int loc)
 
void setAttributeLocation (const std::string &name, int loc)
 
void setUniformName (int uni_type, const std::string &name)
 
const std::string & getUniformName (int uni_type)
 
const std::map< int, std::string > & getUniformNames () const
 
int getUniformLocation (int ptype)
 
int getUniformLocation (const std::string &name)
 
bool hasUniform (int ptype)
 
bool hasUniform (const std::string &name)
 
void setUniform (const STK::Uniform &uni)
 
void setUniform (int ptype, const STK::Matrix4x4f &m)
 Apply matrix value to the given uniform parameter.
 
void setUniform (int ptype, const std::vector< STK::Matrix4x4f > &marr)
 
void setUniform (int ptype, const STK::Vector3f &v)
 Apply vector value to the given uniform parameter.
 
void setUniform (int ptype, const STK::Vector2f &v)
 Apply vector value to the given uniform parameter.
 
void setUniform (int ptype, float val)
 Apply float value to the given uniform parameter.
 
void setUniform (int ptype, float x, float y)
 Apply 2D float value to the given uniform parameter.
 
void setUniform (int ptype, float x, float y, float z)
 Apply 3D float value to the given uniform parameter.
 
void setUniform (int ptype, float x, float y, float z, float w)
 Apply 4D float value to the given uniform parameter.
 
void setUniform (int ptype, const STK::Vector4f &v)
 Apply 4D float value to the given uniform parameter.
 
void setUniform (int ptype, GLint val)
 Apply integer value to the given uniform parameter.
 
void setUniform (int ptype, GLuint val)
 Apply integer value to the given uniform parameter.
 
void setUniform (const std::string &name, const STK::Matrix4x4f &m)
 Apply matrix value to the given uniform parameter.
 
void setUniform (const std::string &name, const STK::Vector4f &v)
 Apply vector value to the given uniform parameter.
 
void setUniform (const std::string &name, const STK::Color4f &c)
 Apply color value to the given uniform parameter.
 
void setUniform (const std::string &name, const STK::Vector3f &v)
 Apply vector value to the given uniform parameter.
 
void setUniform (const std::string &name, const STK::Vector2f &v)
 Apply vector value to the given uniform parameter.
 
void setUniform (const std::string &name, float val)
 Apply float value to the given uniform parameter.
 
void setUniform (const std::string &name, float x, float y)
 Apply 2D float value to the given uniform parameter.
 
void setUniform (const std::string &name, float x, float y, float z)
 Apply 3D float value to the given uniform parameter.
 
void setUniform (const std::string &name, float x, float y, float z, float w)
 Apply 4D float value to the given uniform parameter.
 
void setUniform (const std::string &name, GLint val)
 Apply integer value to the given uniform parameter.
 
void setUniform (const std::string &name, GLuint val)
 Apply integer value to the given uniform parameter.
 
void define (const std::string &define)
 
void undefine (const std::string &define)
 
bool isDefined (const std::string &define) const
 

Static Public Member Functions

static const std::string & getDefaultUniformName (int param)
 
static const std::set< std::string > & getGlobalDefines ()
 
static void setGlobalDefine (const std::string &define)
 
static void unsetGlobalDefine (const std::string &define)
 
static bool getGlobalDefine (const std::string &define)
 

Static Public Attributes

static std::string defaultPositionAttributeName = "a_position"
 
static std::string defaultNormalAttributeName = "a_normal"
 
static std::string defaultTangentAttributeName = "a_tangent"
 
static std::string defaultTextureCoordinateAttributeName = "a_texcoord"
 
static std::string defaultVertexColorAttributeName = "a_color"
 
static std::string defaultBoneWeightsAttributeName = "a_boneWeights"
 
static std::string defaultBoneIndicesAttributeName = "a_boneIndices"
 

Protected Member Functions

bool readShaderFile (const std::string &filename, std::string &source)
 
void applyAttribLocations ()
 

Static Protected Member Functions

static void initDefaultUniformNames ()
 

Protected Attributes

GLuint shader_program_
 
std::string vertex_shader_file_
 
std::string fragment_shader_file_
 
std::string geometry_shader_file_
 
std::string vertex_shader_src_
 
std::string fragment_shader_src_
 
std::string geometry_shader_src_
 
std::string pos_attrib_name_
 
std::string normal_attrib_name_
 
std::string tangent_attrib_name_
 
std::string texcoord_attrib_name_
 
std::string color_attrib_name_
 
std::string bone_wt_attrib_name_
 
std::string bone_idx_attrib_name_
 
int pos_attrib_loc_
 
int normal_attrib_loc_
 
int tangent_attrib_loc_
 
int texcoord_attrib_loc_
 
int color_attrib_loc_
 
int bone_wt_attrib_loc_
 
int bone_idx_attrib_loc_
 
int uniform_loc_ [Uniform::NumParameters]
 
std::map< int, std::string > uniform_names_
 
std::set< std::string > defines_
 
std::map< int, std::string > attribs_
 
std::map< std::string, int > generic_uniform_loc_
 

Static Protected Attributes

static std::set< std::string > s_global_defines_
 
static std::string s_default_uniform_names_ [STK::Uniform::NumParameters]
 

Detailed Description

ShaderProgram - Wrapper class for an OpenGL shader program You can specify the shader source either by file name or by a source code string. If a file name is given, this will be read and parsed to the source string variable. If you want to re-parse the source file, you need to clear the source string.

Geometry shaders are currently unsupported on the GL ES targets.

Member Function Documentation

◆ bindAttributeLocation()

void STK::ShaderProgram::bindAttributeLocation ( const std::string &  name,
int  loc 
)
inline

Bind attribute name to specifict attrib location.

Note
You need to re-link the program afterwards!

◆ disableBoneIndicesAttributeArray()

void STK::ShaderProgram::disableBoneIndicesAttributeArray ( )
inline

Disable client state for BoneIndices vector attribute array. This method should be called after before switching to a new vertex attribute array configuration.

◆ disableBoneWeightsAttributeArray()

void STK::ShaderProgram::disableBoneWeightsAttributeArray ( )
inline

Disable client state for BoneWeights vector attribute array. This method should be called after before switching to a new vertex attribute array configuration.

◆ disableNormalAttributeArray()

void STK::ShaderProgram::disableNormalAttributeArray ( )
inline

Disable client state for normal vector attribute array. This method should be called after before switching to a new vertex attribute array configuration.

◆ disablePositionAttributeArray()

void STK::ShaderProgram::disablePositionAttributeArray ( )
inline

Disable client state for position attribute array. This method should be called after before switching to a new vertex attribute array configuration.

◆ disableTangentAttributeArray()

void STK::ShaderProgram::disableTangentAttributeArray ( )
inline

Disable client state for tangent vector attribute array. This method should be called after before switching to a new vertex attribute array configuration.

◆ disableTextureCoordinateAttributeArray()

void STK::ShaderProgram::disableTextureCoordinateAttributeArray ( )
inline

Disable client state for texture coordinate attribute array. This method should be called after before switching to a new vertex attribute array configuration.

◆ disableVertexColorAttributeArray()

void STK::ShaderProgram::disableVertexColorAttributeArray ( )
inline

Disable client state for color vector attribute array. This method should be called after before switching to a new vertex attribute array configuration.

◆ getAttributeLocation()

int STK::ShaderProgram::getAttributeLocation ( const std::string &  attrib_name) const
inline

Wrapper method to get address for unstandard attribute arrays. Use this method if your shader needs access to custom attribute arrays.

◆ getBoneIndicesAttributeLocation()

int STK::ShaderProgram::getBoneIndicesAttributeLocation ( )
inline

Get attribute handle for bone weights.

◆ getBoneWeightsAttributeLocation()

int STK::ShaderProgram::getBoneWeightsAttributeLocation ( )
inline

Get attribute handle for bone weights.

◆ getNormalAttributeLocation()

int STK::ShaderProgram::getNormalAttributeLocation ( )
inline

Get attribute handle for normal vectors.

◆ getPositionAttributeLocation()

int STK::ShaderProgram::getPositionAttributeLocation ( )
inline

Get attribute handle for vertex positions.

◆ getTangentAttributeLocation()

int STK::ShaderProgram::getTangentAttributeLocation ( )
inline

Get attribute handle for tangent vectors.

◆ getTextureCoordinateAttributeLocation()

int STK::ShaderProgram::getTextureCoordinateAttributeLocation ( )
inline

Get attribute handle for texture coordinates.

◆ getUniformLocation()

int STK::ShaderProgram::getUniformLocation ( int  ptype)
inline

Get address for a uniform variable.

◆ getUniformName()

const std::string & STK::ShaderProgram::getUniformName ( int  uni_type)
inline

Get registered name for this uniform parameter. This method returns the registered name for the uniform, either specified through setUniformName() or the default name

◆ getVertexColorAttributeLocation()

int STK::ShaderProgram::getVertexColorAttributeLocation ( )
inline

Get attribute handle for color vectors.

◆ setAttributeLocation()

void STK::ShaderProgram::setAttributeLocation ( const std::string &  name,
int  loc 
)
inline

Set specific attribute name location. This must be done before a program is linked.

◆ setBoneIndicesAttributeName()

void STK::ShaderProgram::setBoneIndicesAttributeName ( const std::string &  attrib_name)
inline

Set attribute name for bone indices If no name is given, ShaderProgram::defaultBoneIndicesAttributeName will be used.

◆ setBoneIndicesAttributePointer()

void STK::ShaderProgram::setBoneIndicesAttributePointer ( int  stride = 0,
int  offset = 0,
int  size = 4 
)
inline

Set bone weight attribute location in the currently active vertex buffer.

◆ setBoneWeightsAttributeName()

void STK::ShaderProgram::setBoneWeightsAttributeName ( const std::string &  attrib_name)
inline

Set attribute name for bone weights If no name is given, ShaderProgram::defaultBoneWeightsAttributeName will be used.

◆ setBoneWeightsAttributePointer()

void STK::ShaderProgram::setBoneWeightsAttributePointer ( int  stride = 0,
int  offset = 0,
int  size = 4 
)
inline

Set bone weight attribute location in the currently active vertex buffer.

◆ setNormalAttributeName()

void STK::ShaderProgram::setNormalAttributeName ( const std::string &  attrib_name)
inline

Set attribute name for normal vectors. If no name is given, ShaderProgram::defaultNormalAttributeName will be used.

◆ setNormalAttributePointer()

void STK::ShaderProgram::setNormalAttributePointer ( int  stride = 0,
int  offset = 0,
int  size = 3 
)
inline

Set normal vector attribute location in the currently active vertex buffer.

◆ setPositionAttributeName()

void STK::ShaderProgram::setPositionAttributeName ( const std::string &  attrib_name)
inline

Set attribute name for vertex positions. If no name is given, ShaderProgram::defaultPositionAttributeName will be used.

◆ setPositionAttributePointer()

void STK::ShaderProgram::setPositionAttributePointer ( int  stride = 0,
int  offset = 0,
int  size = 3 
)
inline

Set position attribute location in the currently active vertex buffer.

◆ setTangentAttributeName()

void STK::ShaderProgram::setTangentAttributeName ( const std::string &  attrib_name)
inline

Set attribute name for tangent vectors. If no name is given, ShaderProgram::defaultTangentAttributeName will be used.

◆ setTangentAttributePointer()

void STK::ShaderProgram::setTangentAttributePointer ( int  stride = 0,
int  offset = 0,
int  size = 3 
)
inline

Set tangent vector attribute location in the currently active vertex buffer.

◆ setTextureCoordinateAttributeName()

void STK::ShaderProgram::setTextureCoordinateAttributeName ( const std::string &  attrib_name)
inline

Set attribute name for texture coordinates. If no name is given, ShaderProgram::defaultTextureCoordinateAttributeName will be used.

◆ setTextureCoordinateAttributePointer()

void STK::ShaderProgram::setTextureCoordinateAttributePointer ( int  stride = 0,
int  offset = 0,
int  size = 2 
)
inline

Set texture coordinate attribute location in the currently active vertex buffer.

◆ setUniform()

void STK::ShaderProgram::setUniform ( const STK::Uniform uni)
inline

Apply the uniform object to the current shader.

◆ setUniformName()

void STK::ShaderProgram::setUniformName ( int  uni_type,
const std::string &  name 
)
inline

Register a name for a uniform parameter. This name overrides the default name specified for this uniform.

See also
getDefaultUniformName()

◆ setVertexColorAttributeName()

void STK::ShaderProgram::setVertexColorAttributeName ( const std::string &  attrib_name)
inline

Set attribute name for color vectors. If no name is given, ShaderProgram::defaultcolorAttributeName will be used.

◆ setVertexColorAttributePointer()

void STK::ShaderProgram::setVertexColorAttributePointer ( int  stride = 0,
int  offset = 0,
int  size = 4 
)
inline

Set color vector attribute location in the currently active vertex buffer.

◆ updateShader()

bool STK::ShaderProgram::updateShader ( )
inline

Initialize or re-link the shader as required.

This method is used to update a shader after for example setting attribute names. It will either initialize or just re-link the shaders according to what is needed.

Returns
True on success, false on failure.

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