SOFA API  cba138a4
Open source framework for multi-physics simuation
sofa::helper::gl::GLSLShader Class Reference

#include <GLSLShader.h>

Classes

struct  ShaderContents
 A shader is a source code, as such it can be loaded either directly by its source or a filename (containing the source) More...
 

Protected Attributes

std::string header
 
std::map< GLint, ShaderContentsm_hShaderContents
 
std::map< GLint, GLhandleARB > m_hShaders
 
GLhandleARB m_hProgramObject
 This handle stores our program information which encompasses our shader. More...
 
std::shared_ptr< sofa::helper::system::FileEventListenerm_filelistener
 

Public Member Functions

 GLSLShader ()
 
 ~GLSLShader ()
 
void AddHeader (const std::string &header)
 This builds a header before any shader contents. More...
 
void AddDefineMacro (const std::string &name, const std::string &value)
 
void SetShaderFileName (GLint target, const std::string &fileName)
 This function loads and returns a text file for our shaders. More...
 
void SetShaderFromString (GLint target, const std::string &shaderContent)
 
void SetVertexShaderFileName (const std::string &fileName)
 
void SetVertexShaderFromString (const std::string &string)
 
void SetFragmentShaderFileName (const std::string &fileName)
 
void SetFragmentShaderFromString (const std::string &string)
 
std::string GetShaderStageName (GLint target)
 
std::string LoadTextFile (const std::string &strFile)
 This loads our text file for each shader and returns it in a string. More...
 
void InitShaders ()
 This function loads a vertex and fragment shader file. More...
 
void forceReloadShaderFromFile (const std::string &filename)
 
void InitShaders (const std::string &strVertex, const std::string &strFragment)
 This loads a vertex and fragment shader. More...
 
GLint GetVariable (std::string strVariable)
 This returns an ID for a variable in our shader. More...
 
GLint GetAttributeVariable (std::string strVariable)
 This returns an ID for an attribute variable in our shader. More...
 
void Release ()
 This releases our memory for our shader. More...
 
bool IsReady () const
 
GLhandleARB GetProgram () const
 
std::string GetShaderFileName (GLint type) const
 
std::string GetShaderString (GLint type) const
 
std::string GetHeader () const
 
bool IsSet (GLint type) const
 
GLhandleARB GetShaderID (GLint type) const
 
std::string GetVertexShaderFileName () const
 
GLhandleARB GetVertexShaderID () const
 
std::string GetFragmentShaderFileName () const
 
GLhandleARB GetFragmentShaderID () const
 
void SetInt (GLint variable, int newValue)
 
void SetFloat (GLint variable, float newValue)
 
void SetInt2 (GLint variable, int i1, int i2)
 
void SetInt3 (GLint variable, int i1, int i2, int i3)
 
void SetInt4 (GLint variable, int i1, int i2, int i3, int i4)
 
void SetFloat2 (GLint variable, float v0, float v1)
 
void SetFloat3 (GLint variable, float v0, float v1, float v2)
 
void SetFloat4 (GLint variable, float v0, float v1, float v2, float v3)
 
void SetIntVector (GLint variable, GLsizei count, const GLint *value)
 
void SetIntVector2 (GLint variable, GLsizei count, const GLint *value)
 
void SetIntVector3 (GLint variable, GLsizei count, const GLint *value)
 
void SetIntVector4 (GLint variable, GLsizei count, const GLint *value)
 
void SetFloatVector (GLint variable, GLsizei count, const float *value)
 
void SetFloatVector2 (GLint variable, GLsizei count, const float *value)
 
void SetFloatVector3 (GLint variable, GLsizei count, const float *value)
 
void SetFloatVector4 (GLint variable, GLsizei count, const float *value)
 
void SetMatrix2 (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 
void SetMatrix3 (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 
void SetMatrix4 (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 
void SetMatrix2x3 (GLint, GLsizei, GLboolean, const GLfloat *)
 
void SetMatrix3x2 (GLint, GLsizei, GLboolean, const GLfloat *)
 
void SetMatrix2x4 (GLint, GLsizei, GLboolean, const GLfloat *)
 
void SetMatrix4x2 (GLint, GLsizei, GLboolean, const GLfloat *)
 
void SetMatrix3x4 (GLint, GLsizei, GLboolean, const GLfloat *)
 
void SetMatrix4x3 (GLint, GLsizei, GLboolean, const GLfloat *)
 
void TurnOn ()
 
void TurnOff ()
 

Static Public Member Functions

static bool InitGLSL ()
 This is used to load all of the extensions and checks compatibility. More...
 
static GLhandleARB GetActiveShaderProgram ()
 
static void SetActiveShaderProgram (GLhandleARB s)
 

Protected Member Functions

bool CompileShader (GLint target, const ShaderContents &shaderContent, const std::string &header)
 This function compiles a shader and check the log. More...
 

Attribute details

std::string sofa::helper::gl::GLSLShader::header
protected
std::shared_ptr<sofa::helper::system::FileEventListener> sofa::helper::gl::GLSLShader::m_filelistener
protected
GLhandleARB sofa::helper::gl::GLSLShader::m_hProgramObject
protected

This handle stores our program information which encompasses our shader.

std::map<GLint, ShaderContents> sofa::helper::gl::GLSLShader::m_hShaderContents
protected
std::map<GLint, GLhandleARB> sofa::helper::gl::GLSLShader::m_hShaders
protected

Constructor details

sofa::helper::gl::GLSLShader::GLSLShader ( )
sofa::helper::gl::GLSLShader::~GLSLShader ( )

Function details

void sofa::helper::gl::GLSLShader::AddDefineMacro ( const std::string &  name,
const std::string &  value 
)
void sofa::helper::gl::GLSLShader::AddHeader ( const std::string &  header)

This builds a header before any shader contents.

bool sofa::helper::gl::GLSLShader::CompileShader ( GLint  target,
const ShaderContents shaderContent,
const std::string &  header 
)
protected

This function compiles a shader and check the log.

void sofa::helper::gl::GLSLShader::forceReloadShaderFromFile ( const std::string &  filename)
GLhandleARB sofa::helper::gl::GLSLShader::GetActiveShaderProgram ( )
static
GLint sofa::helper::gl::GLSLShader::GetAttributeVariable ( std::string  strVariable)

This returns an ID for an attribute variable in our shader.

std::string sofa::helper::gl::GLSLShader::GetFragmentShaderFileName ( ) const
inline
GLhandleARB sofa::helper::gl::GLSLShader::GetFragmentShaderID ( ) const
inline
std::string sofa::helper::gl::GLSLShader::GetHeader ( ) const
GLhandleARB sofa::helper::gl::GLSLShader::GetProgram ( ) const
inline
std::string sofa::helper::gl::GLSLShader::GetShaderFileName ( GLint  type) const
GLhandleARB sofa::helper::gl::GLSLShader::GetShaderID ( GLint  type) const
std::string sofa::helper::gl::GLSLShader::GetShaderStageName ( GLint  target)
std::string sofa::helper::gl::GLSLShader::GetShaderString ( GLint  type) const
GLint sofa::helper::gl::GLSLShader::GetVariable ( std::string  strVariable)

This returns an ID for a variable in our shader.

This function returns a variable ID for a shader variable.

std::string sofa::helper::gl::GLSLShader::GetVertexShaderFileName ( ) const
inline
GLhandleARB sofa::helper::gl::GLSLShader::GetVertexShaderID ( ) const
inline
bool sofa::helper::gl::GLSLShader::InitGLSL ( )
static

This is used to load all of the extensions and checks compatibility.

void sofa::helper::gl::GLSLShader::InitShaders ( )

This function loads a vertex and fragment shader file.

void sofa::helper::gl::GLSLShader::InitShaders ( const std::string &  strVertex,
const std::string &  strFragment 
)
inline

This loads a vertex and fragment shader.

bool sofa::helper::gl::GLSLShader::IsReady ( ) const
inline

These are our basic get functions for our private data

bool sofa::helper::gl::GLSLShader::IsSet ( GLint  type) const
std::string sofa::helper::gl::GLSLShader::LoadTextFile ( const std::string &  strFile)

This loads our text file for each shader and returns it in a string.

This function loads and returns a text file for our shaders.

void sofa::helper::gl::GLSLShader::Release ( )

This releases our memory for our shader.

This function frees all of our shader data.

void sofa::helper::gl::GLSLShader::SetActiveShaderProgram ( GLhandleARB  s)
static
void sofa::helper::gl::GLSLShader::SetFloat ( GLint  variable,
float  newValue 
)
void sofa::helper::gl::GLSLShader::SetFloat2 ( GLint  variable,
float  v0,
float  v1 
)
void sofa::helper::gl::GLSLShader::SetFloat3 ( GLint  variable,
float  v0,
float  v1,
float  v2 
)
void sofa::helper::gl::GLSLShader::SetFloat4 ( GLint  variable,
float  v0,
float  v1,
float  v2,
float  v3 
)
void sofa::helper::gl::GLSLShader::SetFloatVector ( GLint  variable,
GLsizei  count,
const float value 
)
void sofa::helper::gl::GLSLShader::SetFloatVector2 ( GLint  variable,
GLsizei  count,
const float value 
)
void sofa::helper::gl::GLSLShader::SetFloatVector3 ( GLint  variable,
GLsizei  count,
const float value 
)
void sofa::helper::gl::GLSLShader::SetFloatVector4 ( GLint  variable,
GLsizei  count,
const float value 
)
void sofa::helper::gl::GLSLShader::SetFragmentShaderFileName ( const std::string &  fileName)
inline
void sofa::helper::gl::GLSLShader::SetFragmentShaderFromString ( const std::string &  string)
inline
void sofa::helper::gl::GLSLShader::SetInt ( GLint  variable,
int  newValue 
)

Below are functions to set an integer or a float

void sofa::helper::gl::GLSLShader::SetInt2 ( GLint  variable,
int  i1,
int  i2 
)

Below are functions to set more than 1 integer or float

void sofa::helper::gl::GLSLShader::SetInt3 ( GLint  variable,
int  i1,
int  i2,
int  i3 
)
void sofa::helper::gl::GLSLShader::SetInt4 ( GLint  variable,
int  i1,
int  i2,
int  i3,
int  i4 
)
void sofa::helper::gl::GLSLShader::SetIntVector ( GLint  variable,
GLsizei  count,
const GLint *  value 
)

Below are functions to set a vector of integer or float

void sofa::helper::gl::GLSLShader::SetIntVector2 ( GLint  variable,
GLsizei  count,
const GLint *  value 
)
void sofa::helper::gl::GLSLShader::SetIntVector3 ( GLint  variable,
GLsizei  count,
const GLint *  value 
)
void sofa::helper::gl::GLSLShader::SetIntVector4 ( GLint  variable,
GLsizei  count,
const GLint *  value 
)
void sofa::helper::gl::GLSLShader::SetMatrix2 ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Below are functions to set a matrix

void sofa::helper::gl::GLSLShader::SetMatrix2x3 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat *   
)
inline
void sofa::helper::gl::GLSLShader::SetMatrix2x4 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat *   
)
inline
void sofa::helper::gl::GLSLShader::SetMatrix3 ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)
void sofa::helper::gl::GLSLShader::SetMatrix3x2 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat *   
)
inline
void sofa::helper::gl::GLSLShader::SetMatrix3x4 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat *   
)
inline
void sofa::helper::gl::GLSLShader::SetMatrix4 ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)
void sofa::helper::gl::GLSLShader::SetMatrix4x2 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat *   
)
inline
void sofa::helper::gl::GLSLShader::SetMatrix4x3 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat *   
)
inline
void sofa::helper::gl::GLSLShader::SetShaderFileName ( GLint  target,
const std::string &  fileName 
)

This function loads and returns a text file for our shaders.

void sofa::helper::gl::GLSLShader::SetShaderFromString ( GLint  target,
const std::string &  shaderContent 
)
void sofa::helper::gl::GLSLShader::SetVertexShaderFileName ( const std::string &  fileName)
inline
void sofa::helper::gl::GLSLShader::SetVertexShaderFromString ( const std::string &  string)
inline
void sofa::helper::gl::GLSLShader::TurnOff ( )
void sofa::helper::gl::GLSLShader::TurnOn ( )

These 2 functions turn on and off our shader