SOFA API  ca665544
Open source framework for multi-physics simuation
sofa::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

◆ header

std::string sofa::gl::GLSLShader::header
protected

◆ m_filelistener

std::shared_ptr<sofa::helper::system::FileEventListener> sofa::gl::GLSLShader::m_filelistener
protected

◆ m_hProgramObject

GLhandleARB sofa::gl::GLSLShader::m_hProgramObject
protected

This handle stores our program information which encompasses our shader.

◆ m_hShaderContents

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

◆ m_hShaders

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

Constructor details

◆ GLSLShader()

sofa::gl::GLSLShader::GLSLShader ( )

◆ ~GLSLShader()

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

Function details

◆ AddDefineMacro()

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

◆ AddHeader()

void sofa::gl::GLSLShader::AddHeader ( const std::string &  header)

This builds a header before any shader contents.

◆ CompileShader()

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

This function compiles a shader and check the log.

◆ forceReloadShaderFromFile()

void sofa::gl::GLSLShader::forceReloadShaderFromFile ( const std::string &  filename)

◆ GetActiveShaderProgram()

GLhandleARB sofa::gl::GLSLShader::GetActiveShaderProgram ( )
static

◆ GetAttributeVariable()

GLint sofa::gl::GLSLShader::GetAttributeVariable ( std::string  strVariable)

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

◆ GetFragmentShaderFileName()

std::string sofa::gl::GLSLShader::GetFragmentShaderFileName ( ) const
inline

◆ GetFragmentShaderID()

GLhandleARB sofa::gl::GLSLShader::GetFragmentShaderID ( ) const
inline

◆ GetHeader()

std::string sofa::gl::GLSLShader::GetHeader ( ) const

◆ GetProgram()

GLhandleARB sofa::gl::GLSLShader::GetProgram ( ) const
inline

◆ GetShaderFileName()

std::string sofa::gl::GLSLShader::GetShaderFileName ( GLint  type) const

◆ GetShaderID()

GLhandleARB sofa::gl::GLSLShader::GetShaderID ( GLint  type) const

◆ GetShaderStageName()

std::string sofa::gl::GLSLShader::GetShaderStageName ( GLint  target)

◆ GetShaderString()

std::string sofa::gl::GLSLShader::GetShaderString ( GLint  type) const

◆ GetVariable()

GLint sofa::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.

◆ GetVertexShaderFileName()

std::string sofa::gl::GLSLShader::GetVertexShaderFileName ( ) const
inline

◆ GetVertexShaderID()

GLhandleARB sofa::gl::GLSLShader::GetVertexShaderID ( ) const
inline

◆ InitGLSL()

bool sofa::gl::GLSLShader::InitGLSL ( )
static

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

◆ InitShaders() [1/2]

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

This function loads a vertex and fragment shader file.

◆ InitShaders() [2/2]

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

This loads a vertex and fragment shader.

◆ IsReady()

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

These are our basic get functions for our private data

◆ IsSet()

bool sofa::gl::GLSLShader::IsSet ( GLint  type) const

◆ LoadTextFile()

std::string sofa::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.

◆ Release()

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

This releases our memory for our shader.

This function frees all of our shader data.

◆ SetActiveShaderProgram()

void sofa::gl::GLSLShader::SetActiveShaderProgram ( GLhandleARB  s)
static

◆ SetFloat()

void sofa::gl::GLSLShader::SetFloat ( GLint  variable,
float  newValue 
)

◆ SetFloat2()

void sofa::gl::GLSLShader::SetFloat2 ( GLint  variable,
float  v0,
float  v1 
)

◆ SetFloat3()

void sofa::gl::GLSLShader::SetFloat3 ( GLint  variable,
float  v0,
float  v1,
float  v2 
)

◆ SetFloat4()

void sofa::gl::GLSLShader::SetFloat4 ( GLint  variable,
float  v0,
float  v1,
float  v2,
float  v3 
)

◆ SetFloatVector()

void sofa::gl::GLSLShader::SetFloatVector ( GLint  variable,
GLsizei  count,
const float value 
)

◆ SetFloatVector2()

void sofa::gl::GLSLShader::SetFloatVector2 ( GLint  variable,
GLsizei  count,
const float value 
)

◆ SetFloatVector3()

void sofa::gl::GLSLShader::SetFloatVector3 ( GLint  variable,
GLsizei  count,
const float value 
)

◆ SetFloatVector4()

void sofa::gl::GLSLShader::SetFloatVector4 ( GLint  variable,
GLsizei  count,
const float value 
)

◆ SetFragmentShaderFileName()

void sofa::gl::GLSLShader::SetFragmentShaderFileName ( const std::string &  fileName)
inline

◆ SetFragmentShaderFromString()

void sofa::gl::GLSLShader::SetFragmentShaderFromString ( const std::string &  string)
inline

◆ SetInt()

void sofa::gl::GLSLShader::SetInt ( GLint  variable,
int  newValue 
)

Below are functions to set an integer or a float

◆ SetInt2()

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

Below are functions to set more than 1 integer or float

◆ SetInt3()

void sofa::gl::GLSLShader::SetInt3 ( GLint  variable,
int  i1,
int  i2,
int  i3 
)

◆ SetInt4()

void sofa::gl::GLSLShader::SetInt4 ( GLint  variable,
int  i1,
int  i2,
int  i3,
int  i4 
)

◆ SetIntVector()

void sofa::gl::GLSLShader::SetIntVector ( GLint  variable,
GLsizei  count,
const GLint *  value 
)

Below are functions to set a vector of integer or float

◆ SetIntVector2()

void sofa::gl::GLSLShader::SetIntVector2 ( GLint  variable,
GLsizei  count,
const GLint *  value 
)

◆ SetIntVector3()

void sofa::gl::GLSLShader::SetIntVector3 ( GLint  variable,
GLsizei  count,
const GLint *  value 
)

◆ SetIntVector4()

void sofa::gl::GLSLShader::SetIntVector4 ( GLint  variable,
GLsizei  count,
const GLint *  value 
)

◆ SetMatrix2()

void sofa::gl::GLSLShader::SetMatrix2 ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat value 
)

Below are functions to set a matrix

◆ SetMatrix2x3()

void sofa::gl::GLSLShader::SetMatrix2x3 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat  
)
inline

◆ SetMatrix2x4()

void sofa::gl::GLSLShader::SetMatrix2x4 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat  
)
inline

◆ SetMatrix3()

void sofa::gl::GLSLShader::SetMatrix3 ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat value 
)

◆ SetMatrix3x2()

void sofa::gl::GLSLShader::SetMatrix3x2 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat  
)
inline

◆ SetMatrix3x4()

void sofa::gl::GLSLShader::SetMatrix3x4 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat  
)
inline

◆ SetMatrix4()

void sofa::gl::GLSLShader::SetMatrix4 ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat value 
)

◆ SetMatrix4x2()

void sofa::gl::GLSLShader::SetMatrix4x2 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat  
)
inline

◆ SetMatrix4x3()

void sofa::gl::GLSLShader::SetMatrix4x3 ( GLint  ,
GLsizei  ,
GLboolean  ,
const GLfloat  
)
inline

◆ SetShaderFileName()

void sofa::gl::GLSLShader::SetShaderFileName ( GLint  target,
const std::string &  fileName 
)

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

◆ SetShaderFromString()

void sofa::gl::GLSLShader::SetShaderFromString ( GLint  target,
const std::string &  shaderContent 
)

◆ SetVertexShaderFileName()

void sofa::gl::GLSLShader::SetVertexShaderFileName ( const std::string &  fileName)
inline

◆ SetVertexShaderFromString()

void sofa::gl::GLSLShader::SetVertexShaderFromString ( const std::string &  string)
inline

◆ TurnOff()

void sofa::gl::GLSLShader::TurnOff ( )

◆ TurnOn()

void sofa::gl::GLSLShader::TurnOn ( )

These 2 functions turn on and off our shader