11#pragma warning( disable : 4290 )
24 {
".vs" , GL_VERTEX_SHADER },
25 {
".vert" , GL_VERTEX_SHADER },
26 {
".fs" , GL_FRAGMENT_SHADER },
27 {
".frag" , GL_FRAGMENT_SHADER },
34 template<
unsigned int Dim >
static void glUniformiv ( GLint location , GLsizei count ,
const GLint* value );
36 template<
unsigned int Dim >
static void glUniformfv ( GLint location , GLsizei count ,
const GLfloat* value );
38 template<
unsigned int Dim >
static void glUniformMatrixfv( GLint location , GLsizei count , GLboolean transpose ,
const GLfloat* value );
53 static bool FileExists(
const std::string & fileName );
55 static std::string
GetExtension(
const std::string & fileName );
61 GLSLProgram(
const std::string &vs_filename ,
const std::string &fs_filename );
66 void compileShader(
const std::string & source , GLenum type );
84 void setUniform(
const std::string &name ,
int val ,
bool showWarning=
true );
87 void setUniform(
const std::string &name ,
float val ,
bool showWarning=
true );
90 void setUniform(
const std::string &name ,
double val ,
bool showWarning=
true );
93 template<
unsigned int >
void setUniform(
const std::string &name ,
const int* v ,
bool showWarning=
true );
96 template<
unsigned int >
void setUniform(
const std::string &name ,
const float* v ,
bool showWarning=
true );
99 template<
unsigned int >
void setUniform(
const std::string &name ,
const double* v ,
bool showWarning=
true );
102 template<
unsigned int >
void setUniformMatrix(
const std::string &name ,
const float* m ,
bool showWarning=
true );
105 template<
unsigned int >
void setUniformMatrix(
const std::string &name ,
const double* m ,
bool showWarning=
true );
111template<
unsigned int Dim >
114 GLint loc = glGetUniformLocation(
_handle , name.c_str() );
115 if( loc>=0 ) glUniformiv< Dim >( loc , 1 , v );
116 else if( showWarning )
WARN(
"Non-existant uniform: %s" , name.c_str() );
119template<
unsigned int Dim >
122 GLint loc = glGetUniformLocation(
_handle , name.c_str() );
123 if( loc>=0 ) glUniformfv< Dim >( loc , 1 , v );
124 else if( showWarning )
WARN(
"Non-existant uniform: %s" , name.c_str() );
127template<
unsigned int Dim >
131 for(
int i=0 ; i<Dim ; i++ ) _v[i] = (
float)v[i];
132 setUniform< Dim >( name , _v , showWarning );
135template<
unsigned int Dim >
138 GLint loc = glGetUniformLocation(
_handle , name.c_str() );
139 if( loc>=0 ) glUniformMatrixfv< Dim >( loc , 1 , GL_FALSE , m );
140 else if( showWarning )
WARN(
"Non-existant uniform: %s" , name.c_str() );
143template<
unsigned int Dim >
147 for(
int i=0 ; i<Dim*Dim ; i++ ) _m[i] = (
float)m[i];
148 setUniformMatrix< Dim >( name , _m , showWarning );
Definition: GLSLProgram.h:33
void init(void)
Definition: GLSLProgram.cpp:250
bool linked(void) const
Definition: GLSLProgram.h:81
GLSLProgram(const GLSLProgram &other)
Definition: GLSLProgram.h:41
GLuint _handle
Definition: GLSLProgram.h:45
void setUniform(const std::string &name, int val, bool showWarning=true)
Definition: GLSLProgram.cpp:192
bool _linked
Definition: GLSLProgram.h:47
GLuint handle(void) const
Definition: GLSLProgram.h:78
static void glUniformiv(GLint location, GLsizei count, const GLint *value)
static bool FileExists(const std::string &fileName)
Definition: GLSLProgram.cpp:241
void use(void)
Definition: GLSLProgram.cpp:186
static GLenum GetShaderType(const std::string &fileName)
Definition: GLSLProgram.cpp:100
void validate(void)
Definition: GLSLProgram.cpp:213
~GLSLProgram(void)
Definition: GLSLProgram.cpp:79
std::string _fragmentSource
Definition: GLSLProgram.h:51
void link(void)
Definition: GLSLProgram.cpp:156
static void glUniformfv(GLint location, GLsizei count, const GLfloat *value)
std::string _vertexSource
Definition: GLSLProgram.h:49
static std::string GetExtension(const std::string &fileName)
Definition: GLSLProgram.cpp:111
GLSLProgram & operator=(const GLSLProgram &other)
Definition: GLSLProgram.h:43
static std::string GetShaderTypeString(GLenum type)
Definition: GLSLProgram.cpp:266
void compileShader(const std::string &source, GLenum type)
Definition: GLSLProgram.cpp:118
static void glUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
void setUniformMatrix(const std::string &name, const float *m, bool showWarning=true)
Definition: GLSLProgram.h:136
Definition: GLSLProgram.h:16
std::string ext
Definition: GLSLProgram.h:18
GLenum type
Definition: GLSLProgram.h:19
#define WARN(...)
Definition: exceptions.h:145
Definition: GLSLProgram.h:14
const shader_file_extension extensions[]
Definition: GLSLProgram.h:22