21 #ifndef GL_SHADER_PROGRAM 22 #define GL_SHADER_PROGRAM 24 #include <tulip/OpenGlIncludes.h> 29 #include <tulip/tulipconf.h> 30 #include <tulip/Matrix.h> 31 #include <tulip/Color.h> 35 enum ShaderType { Vertex, Fragment, Geometry };
65 class TLP_GL_SCOPE GlShader {
67 friend class GlShaderProgram;
77 GlShader(ShaderType shaderType);
91 GlShader(GLenum inputPrimitiveType, GLenum outputPrimitiveType);
101 GLuint getShaderId()
const {
102 return shaderObjectId;
108 ShaderType getShaderType()
const {
116 GLenum getInputPrimitiveType()
const {
117 return inputPrimitiveType;
124 GLenum getOutputPrimitiveType()
const {
125 return outputPrimitiveType;
139 void setInputPrimitiveType(
const GLenum inputPrimitiveType) {
140 this->inputPrimitiveType = inputPrimitiveType;
153 void setOutputPrimitiveType(
const GLenum outputPrimitiveType) {
154 this->outputPrimitiveType = outputPrimitiveType;
162 void compileFromSourceCode(
const char *shaderSrc);
169 void compileFromSourceCode(
const std::string &shaderSrc);
176 void compileFromSourceFile(
const std::string &shaderSrcFilename);
181 bool isCompiled()
const {
182 return shaderCompiled;
188 std::string getCompilationLog()
const {
189 return compilationLog;
193 void setAnonymousCreation(
const bool anonymousCreation) {
194 this->anonymousCreation = anonymousCreation;
196 bool anonymouslyCreated()
const {
197 return anonymousCreation;
200 void compileShaderObject(
const char *shaderSrc);
202 ShaderType shaderType;
203 GLuint shaderObjectId;
204 GLenum inputPrimitiveType, outputPrimitiveType;
206 std::string compilationLog;
207 bool anonymousCreation;
224 class TLP_GL_SCOPE GlShaderProgram {
232 GlShaderProgram(
const std::string &name =
"");
243 static bool shaderProgramsSupported();
248 static bool geometryShaderSupported();
253 static GlShaderProgram *getCurrentActiveShader();
258 std::string getName()
const {
265 GLuint getShaderProgramId()
const {
266 return programObjectId;
274 void addShader(GlShader *shader);
282 void removeShader(GlShader *shader);
287 void removeAllShaders();
299 void addShaderFromSourceCode(
const ShaderType shaderType,
const char *shaderSrc);
311 void addShaderFromSourceCode(
const ShaderType shaderType,
const std::string &shaderSrc);
323 void addShaderFromSourceFile(
const ShaderType shaderType,
const std::string &shaderSrcFilename);
339 void addGeometryShaderFromSourceCode(
const char *geometryShaderSrc, GLenum inputPrimitiveType,
340 GLenum outputPrimitiveType);
356 void addGeometryShaderFromSourceCode(
const std::string &geometryShaderSrc,
357 GLenum inputPrimitiveType, GLenum outputPrimitiveType);
374 void addGeometryShaderFromSourceFile(
const std::string &geometryShaderSrcFilename,
375 GLenum inputPrimitiveType, GLenum outputPrimitiveType);
385 bool isLinked()
const {
386 return programLinked;
406 void setUniformFloat(
const std::string &variateName,
const float f);
407 void setUniformVec2Float(
const std::string &variableName,
const Vector<float, 2> &vec2f);
408 void setUniformVec2Float(
const std::string &variableName,
const float f1,
const float f2);
409 void setUniformVec3Float(
const std::string &variableName,
const Vector<float, 3> &vec3f);
410 void setUniformVec3Float(
const std::string &variableName,
const float f1,
const float f2,
412 void setUniformVec4Float(
const std::string &variableName,
const Vector<float, 4> &vec4f);
413 void setUniformVec4Float(
const std::string &variableName,
const float f1,
const float f2,
414 const float f3,
const float f4);
415 void setUniformMat2Float(
const std::string &variableName,
const Matrix<float, 2> &mat2f,
416 const bool transpose =
false);
417 void setUniformMat2Float(
const std::string &variableName,
const float *f,
418 const bool transpose =
false);
419 void setUniformMat3Float(
const std::string &variableName,
const Matrix<float, 3> &mat3f,
420 const bool transpose =
false);
421 void setUniformMat3Float(
const std::string &variableName,
const float *f,
422 const bool transpose =
false);
423 void setUniformMat4Float(
const std::string &variableName,
const Matrix<float, 4> &mat4f,
424 const bool transpose =
false);
425 void setUniformMat4Float(
const std::string &variableName,
const float *f,
426 const bool transpose =
false);
428 void setUniformInt(
const std::string &variableName,
const int f);
429 void setUniformVec2Int(
const std::string &variableName,
const Vector<int, 2> &vec2i);
430 void setUniformVec2Int(
const std::string &variableName,
const int i1,
const int i2);
431 void setUniformVec3Int(
const std::string &variableName,
const Vector<int, 3> &vec3i);
432 void setUniformVec3Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3);
433 void setUniformVec4Int(
const std::string &variableName,
const Vector<int, 4> &vec4i);
434 void setUniformVec4Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3,
437 void setUniformBool(
const std::string &variableName,
const bool b);
438 void setUniformVec2Bool(
const std::string &variableName,
const Array<bool, 2> &vec2b);
439 void setUniformVec2Bool(
const std::string &variableName,
const bool b1,
const bool b2);
440 void setUniformVec3Bool(
const std::string &variableName,
const Array<bool, 3> &vec3b);
441 void setUniformVec3Bool(
const std::string &variableName,
const bool b1,
const bool b2,
443 void setUniformVec4Bool(
const std::string &variableName,
const Array<bool, 4> &vec4b);
444 void setUniformVec4Bool(
const std::string &variableName,
const bool i1,
const bool i2,
445 const bool i3,
const bool i4);
447 void setAttributeFloat(
const std::string &variableName,
const float f);
448 void setAttributeVec2Float(
const std::string &variableName,
const Vector<float, 2> &vec2f);
449 void setAttributeVec2Float(
const std::string &variableName,
const float f1,
const float f2);
450 void setAttributeVec3Float(
const std::string &variableName,
const Vector<float, 3> &vec3f);
451 void setAttributeVec3Float(
const std::string &variableName,
const float f1,
const float f2,
453 void setAttributeVec4Float(
const std::string &variableName,
const Vector<float, 4> &vec4f);
454 void setAttributeVec4Float(
const std::string &variableName,
const float f1,
const float f2,
455 const float f3,
const float f4);
457 void setAttributeInt(
const std::string &variableName,
const int f);
458 void setAttributeVec2Int(
const std::string &variableName,
const Vector<int, 2> &vec2i);
459 void setAttributeVec2Int(
const std::string &variableName,
const int i1,
const int i2);
460 void setAttributeVec3Int(
const std::string &variableName,
const Vector<int, 3> &vec3i);
461 void setAttributeVec3Int(
const std::string &variableName,
const int i1,
const int i2,
463 void setAttributeVec4Int(
const std::string &variableName,
const Vector<int, 4> &vec4i);
464 void setAttributeVec4Int(
const std::string &variableName,
const int i1,
const int i2,
465 const int i3,
const int i4);
467 void setAttributeBool(
const std::string &variableName,
const bool b);
468 void setAttributeVec2Bool(
const std::string &variableName,
const Array<bool, 2> &vec2b);
469 void setAttributeVec2Bool(
const std::string &variableName,
const bool b1,
const bool b2);
470 void setAttributeVec3Bool(
const std::string &variableName,
const Array<bool, 3> &vec3b);
471 void setAttributeVec3Bool(
const std::string &variableName,
const bool b1,
const bool b2,
473 void setAttributeVec4Bool(
const std::string &variableName,
const Array<bool, 4> &vec4b);
474 void setAttributeVec4Bool(
const std::string &variableName,
const bool b1,
const bool b2,
475 const bool b3,
const bool b4);
477 void setUniformTextureSampler(
const std::string &samplerVariateName,
const int samplerId);
478 void setUniformColor(
const std::string &variableName,
const Color &color);
479 void setAttributeColor(
const std::string &variableName,
const Color &color);
481 template <
unsigned int SIZE>
482 void setUniformFloatArray(
const std::string &variableName,
const Vector<float, SIZE> &vecf);
483 void setUniformFloatArray(
const std::string &variableName,
const unsigned int fCount,
486 template <
unsigned int SIZE>
487 void setUniformVec2FloatArray(
const std::string &variableName,
488 const Array<Vector<float, 2>, SIZE> &vecvec2f);
489 void setUniformVec2FloatArray(
const std::string &variableName,
const unsigned int vec2fCount,
492 template <
unsigned int SIZE>
493 void setUniformVec3FloatArray(
const std::string &variableName,
494 const Array<Vector<float, 3>, SIZE> &vecvec3f);
495 void setUniformVec3FloatArray(
const std::string &variableName,
const unsigned int vec3fCount,
498 template <
unsigned int SIZE>
499 void setUniformVec4FloatArray(
const std::string &variableName,
500 const Array<Vector<float, 4>, SIZE> &vecvec4f);
501 void setUniformVec4FloatArray(
const std::string &variableName,
const unsigned int vec4fCount,
504 template <
unsigned int SIZE>
505 void setUniformMat2FloatArray(
const std::string &variableName,
506 const Vector<Matrix<float, 2>, SIZE> &vecmat2f,
507 const bool transpose =
false);
508 void setUniformMat2FloatArray(
const std::string &variableName,
const unsigned int mat2fCount,
509 const float *f,
const bool transpose =
false);
511 template <
unsigned int SIZE>
512 void setUniformMat3FloatArray(
const std::string &variableName,
513 const Vector<Matrix<float, 3>, SIZE> &vecmat3f,
514 const bool transpose =
false);
515 void setUniformMat3FloatArray(
const std::string &variableName,
const unsigned int mat3fCount,
516 const float *f,
const bool transpose =
false);
518 template <
unsigned int SIZE>
519 void setUniformMat4FloatArray(
const std::string &variableName,
520 const Vector<Matrix<float, 4>, SIZE> &vecmat4f,
521 const bool transpose =
false);
522 void setUniformMat4FloatArray(
const std::string &variableName,
const unsigned int mat4fCount,
523 const float *f,
const bool transpose =
false);
525 template <
unsigned int SIZE>
526 void setUniformIntArray(
const std::string &variableName,
const Vector<int, SIZE> &veci);
527 void setUniformIntArray(
const std::string &variableName,
const unsigned int iCount,
const int *i);
529 template <
unsigned int SIZE>
530 void setUniformVec2IntArray(
const std::string &variableName,
531 const Array<Vector<int, 2>, SIZE> &vecvec2i);
532 void setUniformVec2IntArray(
const std::string &variableName,
const unsigned int vec2iCount,
535 template <
unsigned int SIZE>
536 void setUniformVec3IntArray(
const std::string &variableName,
537 const Array<Vector<int, 3>, SIZE> &vecvec3i);
538 void setUniformVec3IntArray(
const std::string &variableName,
const unsigned int vec3iCount,
541 template <
unsigned int SIZE>
542 void setUniformVec4IntArray(
const std::string &variableName,
543 const Array<Vector<int, 4>, SIZE> &vecvec4i);
544 void setUniformVec4IntArray(
const std::string &variableName,
const unsigned int vec4iCount,
547 template <
unsigned int SIZE>
548 void setUniformBoolArray(
const std::string &variableName,
const Array<bool, SIZE> &vecb);
549 void setUniformBoolArray(
const std::string &variableName,
const unsigned int bCount,
552 template <
unsigned int SIZE>
553 void setUniformVec2BoolArray(
const std::string &variableName,
554 const Array<Array<bool, 2>, SIZE> &vecvec2b);
555 void setUniformVec2BoolArray(
const std::string &variableName,
const unsigned int vec2bCount,
558 template <
unsigned int SIZE>
559 void setUniformVec3BoolArray(
const std::string &variableName,
560 const Array<Array<bool, 3>, SIZE> &vecvec3b);
561 void setUniformVec3BoolArray(
const std::string &variableName,
const unsigned int vec3bCount,
564 template <
unsigned int SIZE>
565 void setUniformVec4BoolArray(
const std::string &variableName,
566 const Array<Array<bool, 4>, SIZE> &vecvec4b);
567 void setUniformVec4BoolArray(
const std::string &variableName,
const unsigned int vec4bCount,
570 void getUniformFloatVariableValue(
const std::string &variableName,
float *value);
571 void getUniformIntVariableValue(
const std::string &variableName,
int *value);
572 void getUniformBoolVariableValue(
const std::string &variableName,
bool *value);
573 void getUniformVec2BoolVariableValue(
const std::string &variableName,
bool *value);
574 void getUniformVec3BoolVariableValue(
const std::string &variableName,
bool *value);
575 void getUniformVec4BoolVariableValue(
const std::string &variableName,
bool *value);
581 void setMaxGeometryShaderOutputVertices(
const int maxOutputVertices);
584 GLint getUniformVariableLocation(
const std::string &variableName);
585 GLint getAttributeVariableLocation(
const std::string &variableName);
587 std::string programName;
588 GLuint programObjectId;
590 std::string programLinkLog;
593 std::vector<GlShader *> attachedShaders;
594 int maxGeometryShaderOutputVertices;
596 static GlShaderProgram *currentActiveShaderProgram;
600 #endif // GL_SHADER_PROGRAM