22 #ifndef GL_SHADER_PROGRAM
23 #define GL_SHADER_PROGRAM
25 #include <tulip/OpenGlConfigManager.h>
30 #include <tulip/tulipconf.h>
31 #include <tulip/Vector.h>
32 #include <tulip/Matrix.h>
33 #include <tulip/Color.h>
37 enum ShaderType {Vertex, Fragment, Geometry};
59 class TLP_GL_SCOPE GlShader {
61 friend class GlShaderProgram;
72 GlShader(ShaderType shaderType);
85 GlShader(GLenum inputPrimitiveType, GLenum outputPrimitiveType);
95 GLuint getShaderId()
const {
96 return shaderObjectId;
102 ShaderType getShaderType()
const {
110 GLenum getInputPrimitiveType()
const {
111 return inputPrimitiveType;
117 GLenum getOutputPrimitiveType()
const {
118 return outputPrimitiveType;
129 void setInputPrimitiveType(
const GLenum inputPrimitiveType) {
130 this->inputPrimitiveType = inputPrimitiveType;
141 void setOutputPrimitiveType(
const GLenum outputPrimitiveType) {
142 this->outputPrimitiveType = outputPrimitiveType;
150 void compileFromSourceCode(
const char *shaderSrc);
157 void compileFromSourceCode(
const std::string &shaderSrc);
164 void compileFromSourceFile(
const std::string &shaderSrcFilename);
169 bool isCompiled()
const {
170 return shaderCompiled;
176 std::string getCompilationLog()
const {
177 return compilationLog;
182 void setAnonymousCreation(
const bool anonymousCreation) {
183 this->anonymousCreation = anonymousCreation;
185 bool anonymouslyCreated()
const {
186 return anonymousCreation;
189 void compileShaderObject(
const char *shaderSrc);
191 ShaderType shaderType;
192 GLuint shaderObjectId;
193 GLenum inputPrimitiveType, outputPrimitiveType;
195 std::string compilationLog;
196 bool anonymousCreation;
210 class TLP_GL_SCOPE GlShaderProgram {
219 GlShaderProgram(
const std::string &name =
"");
229 static bool shaderProgramsSupported();
234 static bool geometryShaderSupported();
239 static GlShaderProgram *getCurrentActiveShader();
244 std::string getName()
const {
251 GLuint getShaderProgramId()
const {
252 return programObjectId;
260 void addShader(GlShader *shader);
268 void removeShader(GlShader *shader);
273 void removeAllShaders();
283 void addShaderFromSourceCode(
const ShaderType shaderType,
const char *shaderSrc);
293 void addShaderFromSourceCode(
const ShaderType shaderType,
const std::string &shaderSrc);
303 void addShaderFromSourceFile(
const ShaderType shaderType,
const std::string &shaderSrcFilename);
317 void addGeometryShaderFromSourceCode(
const char *geometryShaderSrc, GLenum inputPrimitiveType, GLenum outputPrimitiveType);
331 void addGeometryShaderFromSourceCode(
const std::string &geometryShaderSrc, GLenum inputPrimitiveType, GLenum outputPrimitiveType);
345 void addGeometryShaderFromSourceFile(
const std::string &geometryShaderSrcFilename, GLenum inputPrimitiveType, GLenum outputPrimitiveType);
355 bool isLinked()
const {
356 return programLinked;
374 void setUniformFloat(
const std::string &variateName,
const float f);
375 void setUniformVec2Float(
const std::string &variableName,
const Vector<float, 2> &vec2f);
376 void setUniformVec2Float(
const std::string &variableName,
const float f1,
const float f2);
377 void setUniformVec3Float(
const std::string &variableName,
const Vector<float, 3> &vec3f);
378 void setUniformVec3Float(
const std::string &variableName,
const float f1,
const float f2,
const float f3);
379 void setUniformVec4Float(
const std::string &variableName,
const Vector<float, 4> &vec4f);
380 void setUniformVec4Float(
const std::string &variableName,
const float f1,
const float f2,
const float f3,
const float f4);
381 void setUniformMat2Float(
const std::string &variableName,
const Matrix<float, 2> &mat2f,
const bool transpose =
false);
382 void setUniformMat2Float(
const std::string &variableName,
const float *f,
const bool transpose =
false);
383 void setUniformMat3Float(
const std::string &variableName,
const Matrix<float, 3> &mat3f,
const bool transpose =
false);
384 void setUniformMat3Float(
const std::string &variableName,
const float *f,
const bool transpose =
false);
385 void setUniformMat4Float(
const std::string &variableName,
const Matrix<float, 4> &mat4f,
const bool transpose =
false);
386 void setUniformMat4Float(
const std::string &variableName,
const float *f,
const bool transpose =
false);
388 void setUniformInt(
const std::string &variableName,
const int f);
389 void setUniformVec2Int(
const std::string &variableName,
const Vector<int, 2> &vec2i);
390 void setUniformVec2Int(
const std::string &variableName,
const int i1,
const int i2);
391 void setUniformVec3Int(
const std::string &variableName,
const Vector<int, 3> &vec3i);
392 void setUniformVec3Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3);
393 void setUniformVec4Int(
const std::string &variableName,
const Vector<int, 4> &vec4i);
394 void setUniformVec4Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3,
const int i4);
396 void setUniformBool(
const std::string &variableName,
const bool b);
397 void setUniformVec2Bool(
const std::string &variableName,
const Array<bool, 2> &vec2b);
398 void setUniformVec2Bool(
const std::string &variableName,
const bool b1,
const bool b2);
399 void setUniformVec3Bool(
const std::string &variableName,
const Array<bool, 3> &vec3b);
400 void setUniformVec3Bool(
const std::string &variableName,
const bool b1,
const bool b2,
const bool b3);
401 void setUniformVec4Bool(
const std::string &variableName,
const Array<bool, 4> &vec4b);
402 void setUniformVec4Bool(
const std::string &variableName,
const bool i1,
const bool i2,
const bool i3,
const bool i4);
404 void setAttributeFloat(
const std::string &variableName,
const float f);
405 void setAttributeVec2Float(
const std::string &variableName,
const Vector<float, 2> &vec2f);
406 void setAttributeVec2Float(
const std::string &variableName,
const float f1,
const float f2);
407 void setAttributeVec3Float(
const std::string &variableName,
const Vector<float, 3> &vec3f);
408 void setAttributeVec3Float(
const std::string &variableName,
const float f1,
const float f2,
const float f3);
409 void setAttributeVec4Float(
const std::string &variableName,
const Vector<float, 4> &vec4f);
410 void setAttributeVec4Float(
const std::string &variableName,
const float f1,
const float f2,
const float f3,
const float f4);
412 void setAttributeInt(
const std::string &variableName,
const int f);
413 void setAttributeVec2Int(
const std::string &variableName,
const Vector<int, 2> &vec2i);
414 void setAttributeVec2Int(
const std::string &variableName,
const int i1,
const int i2);
415 void setAttributeVec3Int(
const std::string &variableName,
const Vector<int, 3> &vec3i);
416 void setAttributeVec3Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3);
417 void setAttributeVec4Int(
const std::string &variableName,
const Vector<int, 4> &vec4i);
418 void setAttributeVec4Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3,
const int i4);
420 void setAttributeBool(
const std::string &variableName,
const bool b);
421 void setAttributeVec2Bool(
const std::string &variableName,
const Array<bool, 2> &vec2b);
422 void setAttributeVec2Bool(
const std::string &variableName,
const bool b1,
const bool b2);
423 void setAttributeVec3Bool(
const std::string &variableName,
const Array<bool, 3> &vec3b);
424 void setAttributeVec3Bool(
const std::string &variableName,
const bool b1,
const bool b2,
const bool b3);
425 void setAttributeVec4Bool(
const std::string &variableName,
const Array<bool, 4> &vec4b);
426 void setAttributeVec4Bool(
const std::string &variableName,
const bool b1,
const bool b2,
const bool b3,
const bool b4);
428 void setUniformTextureSampler(
const std::string &samplerVariateName,
const int samplerId);
429 void setUniformColor(
const std::string &variableName,
const Color &color);
430 void setAttributeColor(
const std::string &variableName,
const Color &color);
432 template <
unsigned int SIZE>
433 void setUniformFloatArray(
const std::string &variableName,
const Vector<float, SIZE> &vecf);
434 void setUniformFloatArray(
const std::string &variableName,
const unsigned int fCount,
const float *f);
436 template <
unsigned int SIZE>
437 void setUniformVec2FloatArray(
const std::string &variableName,
const Array<Vector<float, 2>, SIZE> &vecvec2f);
438 void setUniformVec2FloatArray(
const std::string &variableName,
const unsigned int vec2fCount,
const float *f);
440 template <
unsigned int SIZE>
441 void setUniformVec3FloatArray(
const std::string &variableName,
const Array<Vector<float, 3>, SIZE> &vecvec3f);
442 void setUniformVec3FloatArray(
const std::string &variableName,
const unsigned int vec3fCount,
const float *f);
444 template <
unsigned int SIZE>
445 void setUniformVec4FloatArray(
const std::string &variableName,
const Array<Vector<float, 4>, SIZE> &vecvec4f);
446 void setUniformVec4FloatArray(
const std::string &variableName,
const unsigned int vec4fCount,
const float *f);
448 template <
unsigned int SIZE>
449 void setUniformMat2FloatArray(
const std::string &variableName,
const Vector<Matrix<float, 2>, SIZE> &vecmat2f,
const bool transpose =
false);
450 void setUniformMat2FloatArray(
const std::string &variableName,
const unsigned int mat2fCount,
const float *f,
const bool transpose =
false);
452 template <
unsigned int SIZE>
453 void setUniformMat3FloatArray(
const std::string &variableName,
const Vector<Matrix<float, 3>, SIZE> &vecmat3f,
const bool transpose =
false);
454 void setUniformMat3FloatArray(
const std::string &variableName,
const unsigned int mat3fCount,
const float *f,
const bool transpose =
false);
456 template <
unsigned int SIZE>
457 void setUniformMat4FloatArray(
const std::string &variableName,
const Vector<Matrix<float, 4>, SIZE> &vecmat4f,
const bool transpose =
false);
458 void setUniformMat4FloatArray(
const std::string &variableName,
const unsigned int mat4fCount,
const float *f,
const bool transpose =
false);
460 template <
unsigned int SIZE>
461 void setUniformIntArray(
const std::string &variableName,
const Vector<int, SIZE> &veci);
462 void setUniformIntArray(
const std::string &variableName,
const unsigned int iCount,
const int *i);
464 template <
unsigned int SIZE>
465 void setUniformVec2IntArray(
const std::string &variableName,
const Array<Vector<int, 2>, SIZE> &vecvec2i);
466 void setUniformVec2IntArray(
const std::string &variableName,
const unsigned int vec2iCount,
const int *i);
468 template <
unsigned int SIZE>
469 void setUniformVec3IntArray(
const std::string &variableName,
const Array<Vector<int, 3>, SIZE> &vecvec3i);
470 void setUniformVec3IntArray(
const std::string &variableName,
const unsigned int vec3iCount,
const int *i);
472 template <
unsigned int SIZE>
473 void setUniformVec4IntArray(
const std::string &variableName,
const Array<Vector<int, 4>, SIZE> &vecvec4i);
474 void setUniformVec4IntArray(
const std::string &variableName,
const unsigned int vec4iCount,
const int *i);
476 template <
unsigned int SIZE>
477 void setUniformBoolArray(
const std::string &variableName,
const Array<bool, SIZE> &vecb);
478 void setUniformBoolArray(
const std::string &variableName,
const unsigned int bCount,
const bool *b);
480 template <
unsigned int SIZE>
481 void setUniformVec2BoolArray(
const std::string &variableName,
const Array<Array<bool, 2>, SIZE> &vecvec2b);
482 void setUniformVec2BoolArray(
const std::string &variableName,
const unsigned int vec2bCount,
const bool *b);
484 template <
unsigned int SIZE>
485 void setUniformVec3BoolArray(
const std::string &variableName,
const Array<Array<bool, 3>, SIZE> &vecvec3b);
486 void setUniformVec3BoolArray(
const std::string &variableName,
const unsigned int vec3bCount,
const bool *b);
488 template <
unsigned int SIZE>
489 void setUniformVec4BoolArray(
const std::string &variableName,
const Array<Array<bool, 4>, SIZE> &vecvec4b);
490 void setUniformVec4BoolArray(
const std::string &variableName,
const unsigned int vec4bCount,
const bool *b);
492 void getUniformFloatVariableValue(
const std::string &variableName,
float *value);
493 void getUniformIntVariableValue(
const std::string &variableName,
int *value);
494 void getUniformBoolVariableValue(
const std::string &variableName,
bool *value);
495 void getUniformVec2BoolVariableValue(
const std::string &variableName,
bool *value);
496 void getUniformVec3BoolVariableValue(
const std::string &variableName,
bool *value);
497 void getUniformVec4BoolVariableValue(
const std::string &variableName,
bool *value);
502 void setMaxGeometryShaderOutputVertices(
const int maxOutputVertices);
506 GLint getUniformVariableLocation(
const std::string &variableName);
507 GLint getAttributeVariableLocation(
const std::string &variableName);
509 std::string programName;
510 GLuint programObjectId;
512 std::string programLinkLog;
515 std::vector<GlShader *> attachedShaders;
516 int maxGeometryShaderOutputVertices;
518 static GlShaderProgram *currentActiveShaderProgram;
526 #endif // GL_SHADER_PROGRAM