22 #ifndef GL_SHADER_PROGRAM
23 #define GL_SHADER_PROGRAM
29 #if defined(__APPLE__)
30 #include <OpenGL/gl.h>
38 #include <tulip/tulipconf.h>
39 #include <tulip/Matrix.h>
40 #include <tulip/Color.h>
44 enum ShaderType {Vertex, Fragment, Geometry};
66 class TLP_GL_SCOPE GlShader {
68 friend class GlShaderProgram;
79 GlShader(ShaderType shaderType);
92 GlShader(GLenum inputPrimitiveType, GLenum outputPrimitiveType);
102 GLuint getShaderId()
const {
103 return shaderObjectId;
109 ShaderType getShaderType()
const {
117 GLenum getInputPrimitiveType()
const {
118 return inputPrimitiveType;
124 GLenum getOutputPrimitiveType()
const {
125 return outputPrimitiveType;
136 void setInputPrimitiveType(
const GLenum inputPrimitiveType) {
137 this->inputPrimitiveType = inputPrimitiveType;
148 void setOutputPrimitiveType(
const GLenum outputPrimitiveType) {
149 this->outputPrimitiveType = outputPrimitiveType;
157 void compileFromSourceCode(
const char *shaderSrc);
164 void compileFromSourceCode(
const std::string &shaderSrc);
171 void compileFromSourceFile(
const std::string &shaderSrcFilename);
176 bool isCompiled()
const {
177 return shaderCompiled;
183 std::string getCompilationLog()
const {
184 return compilationLog;
189 void setAnonymousCreation(
const bool anonymousCreation) {
190 this->anonymousCreation = anonymousCreation;
192 bool anonymouslyCreated()
const {
193 return anonymousCreation;
196 void compileShaderObject(
const char *shaderSrc);
198 ShaderType shaderType;
199 GLuint shaderObjectId;
200 GLenum inputPrimitiveType, outputPrimitiveType;
202 std::string compilationLog;
203 bool anonymousCreation;
217 class TLP_GL_SCOPE GlShaderProgram {
226 GlShaderProgram(
const std::string &name =
"");
236 static bool shaderProgramsSupported();
241 static bool geometryShaderSupported();
246 static GlShaderProgram *getCurrentActiveShader();
251 std::string getName()
const {
258 GLuint getShaderProgramId()
const {
259 return programObjectId;
267 void addShader(GlShader *shader);
275 void removeShader(GlShader *shader);
280 void removeAllShaders();
290 void addShaderFromSourceCode(
const ShaderType shaderType,
const char *shaderSrc);
300 void addShaderFromSourceCode(
const ShaderType shaderType,
const std::string &shaderSrc);
310 void addShaderFromSourceFile(
const ShaderType shaderType,
const std::string &shaderSrcFilename);
324 void addGeometryShaderFromSourceCode(
const char *geometryShaderSrc, GLenum inputPrimitiveType, GLenum outputPrimitiveType);
338 void addGeometryShaderFromSourceCode(
const std::string &geometryShaderSrc, GLenum inputPrimitiveType, GLenum outputPrimitiveType);
352 void addGeometryShaderFromSourceFile(
const std::string &geometryShaderSrcFilename, GLenum inputPrimitiveType, GLenum outputPrimitiveType);
362 bool isLinked()
const {
363 return programLinked;
381 void setUniformFloat(
const std::string &variateName,
const float f);
382 void setUniformVec2Float(
const std::string &variableName,
const Vector<float, 2> &vec2f);
383 void setUniformVec2Float(
const std::string &variableName,
const float f1,
const float f2);
384 void setUniformVec3Float(
const std::string &variableName,
const Vector<float, 3> &vec3f);
385 void setUniformVec3Float(
const std::string &variableName,
const float f1,
const float f2,
const float f3);
386 void setUniformVec4Float(
const std::string &variableName,
const Vector<float, 4> &vec4f);
387 void setUniformVec4Float(
const std::string &variableName,
const float f1,
const float f2,
const float f3,
const float f4);
388 void setUniformMat2Float(
const std::string &variableName,
const Matrix<float, 2> &mat2f,
const bool transpose =
false);
389 void setUniformMat2Float(
const std::string &variableName,
const float *f,
const bool transpose =
false);
390 void setUniformMat3Float(
const std::string &variableName,
const Matrix<float, 3> &mat3f,
const bool transpose =
false);
391 void setUniformMat3Float(
const std::string &variableName,
const float *f,
const bool transpose =
false);
392 void setUniformMat4Float(
const std::string &variableName,
const Matrix<float, 4> &mat4f,
const bool transpose =
false);
393 void setUniformMat4Float(
const std::string &variableName,
const float *f,
const bool transpose =
false);
395 void setUniformInt(
const std::string &variableName,
const int f);
396 void setUniformVec2Int(
const std::string &variableName,
const Vector<int, 2> &vec2i);
397 void setUniformVec2Int(
const std::string &variableName,
const int i1,
const int i2);
398 void setUniformVec3Int(
const std::string &variableName,
const Vector<int, 3> &vec3i);
399 void setUniformVec3Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3);
400 void setUniformVec4Int(
const std::string &variableName,
const Vector<int, 4> &vec4i);
401 void setUniformVec4Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3,
const int i4);
403 void setUniformBool(
const std::string &variableName,
const bool b);
404 void setUniformVec2Bool(
const std::string &variableName,
const Array<bool, 2> &vec2b);
405 void setUniformVec2Bool(
const std::string &variableName,
const bool b1,
const bool b2);
406 void setUniformVec3Bool(
const std::string &variableName,
const Array<bool, 3> &vec3b);
407 void setUniformVec3Bool(
const std::string &variableName,
const bool b1,
const bool b2,
const bool b3);
408 void setUniformVec4Bool(
const std::string &variableName,
const Array<bool, 4> &vec4b);
409 void setUniformVec4Bool(
const std::string &variableName,
const bool i1,
const bool i2,
const bool i3,
const bool i4);
411 void setAttributeFloat(
const std::string &variableName,
const float f);
412 void setAttributeVec2Float(
const std::string &variableName,
const Vector<float, 2> &vec2f);
413 void setAttributeVec2Float(
const std::string &variableName,
const float f1,
const float f2);
414 void setAttributeVec3Float(
const std::string &variableName,
const Vector<float, 3> &vec3f);
415 void setAttributeVec3Float(
const std::string &variableName,
const float f1,
const float f2,
const float f3);
416 void setAttributeVec4Float(
const std::string &variableName,
const Vector<float, 4> &vec4f);
417 void setAttributeVec4Float(
const std::string &variableName,
const float f1,
const float f2,
const float f3,
const float f4);
419 void setAttributeInt(
const std::string &variableName,
const int f);
420 void setAttributeVec2Int(
const std::string &variableName,
const Vector<int, 2> &vec2i);
421 void setAttributeVec2Int(
const std::string &variableName,
const int i1,
const int i2);
422 void setAttributeVec3Int(
const std::string &variableName,
const Vector<int, 3> &vec3i);
423 void setAttributeVec3Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3);
424 void setAttributeVec4Int(
const std::string &variableName,
const Vector<int, 4> &vec4i);
425 void setAttributeVec4Int(
const std::string &variableName,
const int i1,
const int i2,
const int i3,
const int i4);
427 void setAttributeBool(
const std::string &variableName,
const bool b);
428 void setAttributeVec2Bool(
const std::string &variableName,
const Array<bool, 2> &vec2b);
429 void setAttributeVec2Bool(
const std::string &variableName,
const bool b1,
const bool b2);
430 void setAttributeVec3Bool(
const std::string &variableName,
const Array<bool, 3> &vec3b);
431 void setAttributeVec3Bool(
const std::string &variableName,
const bool b1,
const bool b2,
const bool b3);
432 void setAttributeVec4Bool(
const std::string &variableName,
const Array<bool, 4> &vec4b);
433 void setAttributeVec4Bool(
const std::string &variableName,
const bool b1,
const bool b2,
const bool b3,
const bool b4);
435 void setUniformTextureSampler(
const std::string &samplerVariateName,
const int samplerId);
436 void setUniformColor(
const std::string &variableName,
const Color &color);
437 void setAttributeColor(
const std::string &variableName,
const Color &color);
439 template <
unsigned int SIZE>
440 void setUniformFloatArray(
const std::string &variableName,
const Vector<float, SIZE> &vecf);
441 void setUniformFloatArray(
const std::string &variableName,
const unsigned int fCount,
const float *f);
443 template <
unsigned int SIZE>
444 void setUniformVec2FloatArray(
const std::string &variableName,
const Array<Vector<float, 2>, SIZE> &vecvec2f);
445 void setUniformVec2FloatArray(
const std::string &variableName,
const unsigned int vec2fCount,
const float *f);
447 template <
unsigned int SIZE>
448 void setUniformVec3FloatArray(
const std::string &variableName,
const Array<Vector<float, 3>, SIZE> &vecvec3f);
449 void setUniformVec3FloatArray(
const std::string &variableName,
const unsigned int vec3fCount,
const float *f);
451 template <
unsigned int SIZE>
452 void setUniformVec4FloatArray(
const std::string &variableName,
const Array<Vector<float, 4>, SIZE> &vecvec4f);
453 void setUniformVec4FloatArray(
const std::string &variableName,
const unsigned int vec4fCount,
const float *f);
455 template <
unsigned int SIZE>
456 void setUniformMat2FloatArray(
const std::string &variableName,
const Vector<Matrix<float, 2>, SIZE> &vecmat2f,
const bool transpose =
false);
457 void setUniformMat2FloatArray(
const std::string &variableName,
const unsigned int mat2fCount,
const float *f,
const bool transpose =
false);
459 template <
unsigned int SIZE>
460 void setUniformMat3FloatArray(
const std::string &variableName,
const Vector<Matrix<float, 3>, SIZE> &vecmat3f,
const bool transpose =
false);
461 void setUniformMat3FloatArray(
const std::string &variableName,
const unsigned int mat3fCount,
const float *f,
const bool transpose =
false);
463 template <
unsigned int SIZE>
464 void setUniformMat4FloatArray(
const std::string &variableName,
const Vector<Matrix<float, 4>, SIZE> &vecmat4f,
const bool transpose =
false);
465 void setUniformMat4FloatArray(
const std::string &variableName,
const unsigned int mat4fCount,
const float *f,
const bool transpose =
false);
467 template <
unsigned int SIZE>
468 void setUniformIntArray(
const std::string &variableName,
const Vector<int, SIZE> &veci);
469 void setUniformIntArray(
const std::string &variableName,
const unsigned int iCount,
const int *i);
471 template <
unsigned int SIZE>
472 void setUniformVec2IntArray(
const std::string &variableName,
const Array<Vector<int, 2>, SIZE> &vecvec2i);
473 void setUniformVec2IntArray(
const std::string &variableName,
const unsigned int vec2iCount,
const int *i);
475 template <
unsigned int SIZE>
476 void setUniformVec3IntArray(
const std::string &variableName,
const Array<Vector<int, 3>, SIZE> &vecvec3i);
477 void setUniformVec3IntArray(
const std::string &variableName,
const unsigned int vec3iCount,
const int *i);
479 template <
unsigned int SIZE>
480 void setUniformVec4IntArray(
const std::string &variableName,
const Array<Vector<int, 4>, SIZE> &vecvec4i);
481 void setUniformVec4IntArray(
const std::string &variableName,
const unsigned int vec4iCount,
const int *i);
483 template <
unsigned int SIZE>
484 void setUniformBoolArray(
const std::string &variableName,
const Array<bool, SIZE> &vecb);
485 void setUniformBoolArray(
const std::string &variableName,
const unsigned int bCount,
const bool *b);
487 template <
unsigned int SIZE>
488 void setUniformVec2BoolArray(
const std::string &variableName,
const Array<Array<bool, 2>, SIZE> &vecvec2b);
489 void setUniformVec2BoolArray(
const std::string &variableName,
const unsigned int vec2bCount,
const bool *b);
491 template <
unsigned int SIZE>
492 void setUniformVec3BoolArray(
const std::string &variableName,
const Array<Array<bool, 3>, SIZE> &vecvec3b);
493 void setUniformVec3BoolArray(
const std::string &variableName,
const unsigned int vec3bCount,
const bool *b);
495 template <
unsigned int SIZE>
496 void setUniformVec4BoolArray(
const std::string &variableName,
const Array<Array<bool, 4>, SIZE> &vecvec4b);
497 void setUniformVec4BoolArray(
const std::string &variableName,
const unsigned int vec4bCount,
const bool *b);
499 void getUniformFloatVariableValue(
const std::string &variableName,
float *value);
500 void getUniformIntVariableValue(
const std::string &variableName,
int *value);
501 void getUniformBoolVariableValue(
const std::string &variableName,
bool *value);
502 void getUniformVec2BoolVariableValue(
const std::string &variableName,
bool *value);
503 void getUniformVec3BoolVariableValue(
const std::string &variableName,
bool *value);
504 void getUniformVec4BoolVariableValue(
const std::string &variableName,
bool *value);
509 void setMaxGeometryShaderOutputVertices(
const int maxOutputVertices);
513 GLint getUniformVariableLocation(
const std::string &variableName);
514 GLint getAttributeVariableLocation(
const std::string &variableName);
516 std::string programName;
517 GLuint programObjectId;
519 std::string programLinkLog;
522 std::vector<GlShader *> attachedShaders;
523 int maxGeometryShaderOutputVertices;
525 static GlShaderProgram *currentActiveShaderProgram;
533 #endif // GL_SHADER_PROGRAM