23 #ifndef __TUCANOSHADER__ 24 #define __TUCANOSHADER__ 30 #include <Eigen/Dense> 89 GLuint computeShader = 0;
92 GLuint vertexShader = 0;
95 GLuint tessellationControlShader = 0;
98 GLuint tessellationEvaluationShader = 0;
101 GLuint geometryShader = 0;
104 GLuint fragmentShader = 0;
107 GLuint shaderProgram = 0;
113 std::shared_ptr < GLuint > programID_sptr = 0;
114 std::shared_ptr < GLuint > vertexID_sptr = 0;
115 std::shared_ptr < GLuint > fragID_sptr = 0;
116 std::shared_ptr < GLuint > geomID_sptr = 0;
117 std::shared_ptr < GLuint > tessEvalID_sptr = 0;
118 std::shared_ptr < GLuint > tessContID_sptr = 0;
119 std::shared_ptr < GLuint > computeID_sptr = 0;
158 shaderProgram = glCreateProgram();
159 programID_sptr = std::shared_ptr < GLuint > (
160 new GLuint (shaderProgram),
175 if (!(fragmentShaderPath.empty() && fragment_code.empty()) && fragID_sptr == 0)
177 fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
178 fragID_sptr = std::shared_ptr < GLuint > (
179 new GLuint (fragmentShader),
187 if (!(vertexShaderPath.empty() && vertex_code.empty()) && vertexID_sptr == 0)
189 vertexShader = glCreateShader(GL_VERTEX_SHADER);
190 vertexID_sptr = std::shared_ptr < GLuint > (
191 new GLuint (vertexShader),
199 if (!(geometryShaderPath.empty() && geometry_code.empty()) && geomID_sptr == 0)
201 geometryShader = glCreateShader(GL_GEOMETRY_SHADER);
202 geomID_sptr = std::shared_ptr < GLuint > (
203 new GLuint (geometryShader),
212 if (!(tessellationControlShaderPath.empty() && tessellation_control_code.empty()) && tessContID_sptr == 0)
214 tessellationControlShader = glCreateShader(GL_TESS_CONTROL_SHADER);
215 tessContID_sptr = std::shared_ptr < GLuint > (
216 new GLuint (tessellationControlShader),
224 if (!(tessellationEvaluationShaderPath.empty() && tessellation_evaluation_code.empty()) && tessEvalID_sptr == 0)
226 tessellationEvaluationShader = glCreateShader(GL_TESS_EVALUATION_SHADER);
227 tessEvalID_sptr = std::shared_ptr < GLuint > (
228 new GLuint (tessellationEvaluationShader),
237 if (!(computeShaderPath.empty() && compute_shader_code.empty()) && computeID_sptr == 0)
239 computeShader = glCreateShader(GL_COMPUTE_SHADER);
240 computeID_sptr = std::shared_ptr < GLuint > (
241 new GLuint (computeShader),
267 Shader (
string name,
string vertex_shader_path,
string fragment_shader_path,
string geometry_shader_path =
"",
string tessellation_evaluation_shader_path =
"",
string tessellation_control_shader_path =
"")
270 vertexShaderPath = vertex_shader_path;
271 tessellationControlShaderPath = tessellation_control_shader_path;
272 tessellationEvaluationShaderPath = tessellation_evaluation_shader_path;
273 geometryShaderPath = geometry_shader_path;
274 fragmentShaderPath = fragment_shader_path;
288 load (name, shader_dir);
352 return *programID_sptr;
374 return *vertexID_sptr;
396 return *tessContID_sptr;
408 return *tessEvalID_sptr;
420 return *computeID_sptr;
436 void load (
string name,
string shader_dir =
"")
443 string vs_name = shader_dir + name +
".vert";
444 ifstream vertex_file(vs_name.c_str());
445 if (vertex_file.good())
447 vertexShaderPath = vs_name;
452 string tesc_name = shader_dir + name +
".tesc";
453 ifstream tesc_file(tesc_name.c_str());
454 if (tesc_file.good())
456 tessellationControlShaderPath = tesc_name;
461 string tese_name = shader_dir + name +
".tese";
462 ifstream tese_file(tese_name.c_str());
463 if (tese_file.good())
465 tessellationEvaluationShaderPath = tese_name;
470 string gs_name = shader_dir + name +
".geom";
471 ifstream geom_file(gs_name.c_str());
472 if (geom_file.good())
474 geometryShaderPath = gs_name;
479 string fs_name = shader_dir + name +
".frag";
480 ifstream fragment_file(fs_name.c_str());
481 if (fragment_file.good())
483 fragmentShaderPath = fs_name;
488 string cs_name = shader_dir + name +
".comp";
489 ifstream comp_file(cs_name.c_str());
490 if (comp_file.good())
492 computeShaderPath = cs_name;
499 std::cerr <<
"Warning: no shader " << name.c_str() <<
" file found in directory : " << shader_dir.c_str() << std::endl;
511 glLinkProgram(*programID_sptr);
513 GLint result = GL_FALSE;
514 glGetProgramiv(*programID_sptr, GL_LINK_STATUS, &result);
515 if (result != GL_TRUE)
517 std::cerr <<
"Error linking program : " << shaderName << std::endl;
518 GLchar errorLog[1024] = {0};
519 glGetProgramInfoLog(*programID_sptr, 1024, NULL, errorLog);
520 fprintf(stdout,
"%s", &errorLog[0]);
521 std::cerr << std::endl;
526 std::cout <<
" Successfully linked : " << shaderName << std::endl << std::endl;
541 void initializeTF (
int size,
const char** varlist, GLenum buffer_mode = GL_INTERLEAVED_ATTRIBS)
544 if(!vertexShaderPath.empty())
548 if (!tessellationControlShaderPath.empty())
550 readTessellationControlCode();
553 if (!tessellationEvaluationShaderPath.empty())
555 readTessellationEvaluationCode();
558 if(!geometryShaderPath.empty())
563 if(!fragmentShaderPath.empty())
567 if(!computeShaderPath.empty())
569 readComputeShaderCode();
572 glTransformFeedbackVaryings(*programID_sptr, size, varlist, buffer_mode);
589 void initializeFromStrings (
string in_vertex_code,
string in_fragment_code,
string in_geometry_code =
"",
string in_tessellation_evaluation_code =
"",
string in_tessellation_control_code =
"")
591 vertex_code = in_vertex_code;
592 fragment_code = in_fragment_code;
593 geometry_code = in_geometry_code;
594 tessellation_evaluation_code = in_tessellation_evaluation_code;
595 tessellation_control_code = in_tessellation_control_code;
599 if (vertex_code.empty())
601 std::cerr <<
"warning: " << shaderName.c_str() <<
" : empty vertex string code!" << std::endl;
605 setVertexShader(vertex_code);
607 if (!tessellationControlShaderPath.empty())
609 setTessellationControlShader(tessellation_control_code);
612 if (!tessellationEvaluationShaderPath.empty())
614 setTessellationEvaluationShader(tessellation_evaluation_code);
617 if (!geometry_code.empty())
619 setGeometryShader(geometry_code);
622 if (fragment_code.empty())
624 std::cerr <<
"warning: " << shaderName.c_str() <<
" : empty fragment string code!" << std::endl;
628 setFragmentShader(fragment_code);
644 if(!vertexShaderPath.empty())
648 if (!tessellationControlShaderPath.empty())
650 readTessellationControlCode();
653 if (!tessellationEvaluationShaderPath.empty())
655 readTessellationEvaluationCode();
658 if(!geometryShaderPath.empty()) {
662 if(!fragmentShaderPath.empty())
666 if(!computeShaderPath.empty())
668 readComputeShaderCode();
684 GLint result = GL_FALSE;
687 char const * vertexSourcePointer = vertexShaderCode.c_str();
688 glShaderSource(*vertexID_sptr, 1, &vertexSourcePointer , NULL);
689 glCompileShader(*vertexID_sptr);
692 glGetShaderiv(*vertexID_sptr, GL_COMPILE_STATUS, &result);
693 if (result != GL_TRUE)
696 std::cerr <<
"Erro compiling vertex shader: " << vertexShaderPath << std::endl;
697 glGetShaderiv(*vertexID_sptr, GL_INFO_LOG_LENGTH, &infoLogLength);
698 char * vertexShaderErrorMessage =
new char[infoLogLength];
699 glGetShaderInfoLog(*vertexID_sptr, infoLogLength, NULL, &vertexShaderErrorMessage[0]);
700 fprintf(stdout,
"\n%s", &vertexShaderErrorMessage[0]);
701 delete [] vertexShaderErrorMessage;
706 if (vertexShaderPath.empty())
708 std::cout <<
"Compiled vertex shader from string without errors : " << shaderName.c_str() << std::endl;
712 std::cout <<
"Compiled vertex shader without errors : " << vertexShaderPath << std::endl;
717 glAttachShader(*programID_sptr, *vertexID_sptr);
731 string vertexShaderCode;
733 ifstream vertexShaderStream(vertexShaderPath.c_str(), std::ios::in);
735 if(vertexShaderStream.is_open())
738 while(getline(vertexShaderStream, line))
740 vertexShaderCode +=
"\n" + line;
742 vertexShaderStream.close();
746 std::cout <<
"warning: no vertex shader file found : " << vertexShaderPath << std::endl;
749 setVertexShader(vertexShaderCode);
750 vertex_code = vertexShaderCode;
759 GLint result = GL_FALSE;
762 char const * tessellationControlSourcePointer = tessellationControlCode.c_str();
763 glShaderSource(*tessContID_sptr, 1, &tessellationControlSourcePointer , NULL);
764 glCompileShader(*tessContID_sptr);
767 glGetShaderiv(*tessContID_sptr, GL_COMPILE_STATUS, &result);
768 if (result != GL_TRUE)
771 std::cerr <<
"Erro compiling tessellation evaluation shader: " << tessellationControlShaderPath << std::endl;
772 glGetShaderiv(*tessContID_sptr, GL_INFO_LOG_LENGTH, &infoLogLength);
773 char * tessellationControlShaderErrorMessage =
new char[infoLogLength];
774 glGetShaderInfoLog(*tessContID_sptr, infoLogLength, NULL, &tessellationControlShaderErrorMessage[0]);
775 fprintf(stdout,
"\n%s", &tessellationControlShaderErrorMessage[0]);
776 delete [] tessellationControlShaderErrorMessage;
781 if (tessellationControlShaderPath.empty())
783 std::cout <<
"Compiled tessellation control shader from string without errors : " << shaderName.c_str() << std::endl;
787 std::cout <<
"Compiled tessellation control shader without errors : " << tessellationControlShaderPath << std::endl;
792 glAttachShader(*programID_sptr, *tessContID_sptr);
805 string tessellationControlShaderCode;
807 ifstream tessellationControlShaderStream(tessellationControlShaderPath.c_str(), std::ios::in);
808 if(tessellationControlShaderStream.is_open())
811 while(getline(tessellationControlShaderStream, line))
813 tessellationControlShaderCode +=
"\n" + line;
815 tessellationControlShaderStream.close();
819 std::cout <<
"warning: no tessellation control shader file found : " << tessellationControlShaderPath << std::endl;
822 setTessellationControlShader(tessellationControlShaderCode);
823 tessellation_control_code = tessellationControlShaderCode;
832 GLint result = GL_FALSE;
835 char const * tessellationEvaluationSourcePointer = tessellationEvaluationCode.c_str();
836 glShaderSource(*tessEvalID_sptr, 1, &tessellationEvaluationSourcePointer , NULL);
837 glCompileShader(*tessEvalID_sptr);
840 glGetShaderiv(*tessEvalID_sptr, GL_COMPILE_STATUS, &result);
841 if (result != GL_TRUE)
844 std::cerr <<
"Erro compiling tessellation evaluation shader: " << tessellationEvaluationShaderPath << std::endl;
845 glGetShaderiv(*tessEvalID_sptr, GL_INFO_LOG_LENGTH, &infoLogLength);
846 char * tessellationEvaluationShaderErrorMessage =
new char[infoLogLength];
847 glGetShaderInfoLog(*tessEvalID_sptr, infoLogLength, NULL, &tessellationEvaluationShaderErrorMessage[0]);
848 fprintf(stdout,
"\n%s", &tessellationEvaluationShaderErrorMessage[0]);
849 delete [] tessellationEvaluationShaderErrorMessage;
854 if (tessellationEvaluationShaderPath.empty())
856 std::cout <<
"Compiled tessellation evaluation shader from string without errors : " << shaderName.c_str() << std::endl;
860 std::cout <<
"Compiled tessellation evaluation shader without errors : " << tessellationEvaluationShaderPath << std::endl;
865 glAttachShader(*programID_sptr, *tessEvalID_sptr);
878 string tessellationEvaluationShaderCode;
880 ifstream tessellationEvaluationShaderStream(tessellationEvaluationShaderPath.c_str(), std::ios::in);
882 if(tessellationEvaluationShaderStream.is_open())
885 while(getline(tessellationEvaluationShaderStream, line))
887 tessellationEvaluationShaderCode +=
"\n" + line;
889 tessellationEvaluationShaderStream.close();
893 std::cout <<
"warning: no tessellation evaluation shader file found : " << tessellationEvaluationShaderPath << std::endl;
896 setTessellationEvaluationShader(tessellationEvaluationShaderCode);
897 tessellation_evaluation_code = tessellationEvaluationShaderCode;
906 GLint result = GL_FALSE;
909 char const * geometrySourcePointer = geometryShaderCode.c_str();
910 glShaderSource(*geomID_sptr, 1, &geometrySourcePointer , NULL);
911 glCompileShader(geometryShader);
914 glGetShaderiv(*geomID_sptr, GL_COMPILE_STATUS, &result);
915 if (result != GL_TRUE)
918 std::cerr <<
"Erro compiling geometry shader: " << geometryShaderPath << std::endl;
919 glGetShaderiv(*geomID_sptr, GL_INFO_LOG_LENGTH, &infoLogLength);
920 char * geometryShaderErrorMessage =
new char[infoLogLength];
921 glGetShaderInfoLog(*geomID_sptr, infoLogLength, NULL, &geometryShaderErrorMessage[0]);
922 fprintf(stdout,
"\n%s", &geometryShaderErrorMessage[0]);
923 delete [] geometryShaderErrorMessage;
928 if (geometryShaderPath.empty())
930 std::cout <<
"Compiled geometry shader from string without errors : " << shaderName.c_str() << std::endl;
934 std::cout <<
"Compiled geometry shader without errors : " << geometryShaderPath << std::endl;
939 glAttachShader(*programID_sptr, *geomID_sptr);
953 string geometryShaderCode;
955 ifstream geometryShaderStream(geometryShaderPath.c_str(), std::ios::in);
957 if(geometryShaderStream.is_open())
960 while(getline(geometryShaderStream, line))
962 geometryShaderCode +=
"\n" + line;
964 geometryShaderStream.close();
968 std::cerr <<
"warning: no geom shader found : " << geometryShaderPath << std::endl;
971 setGeometryShader(geometryShaderCode);
972 geometry_code = geometryShaderCode;
981 GLint result = GL_FALSE;
984 char const * fragmentSourcePointer = fragmentShaderCode.c_str();
985 glShaderSource(*fragID_sptr, 1, &fragmentSourcePointer , NULL);
986 glCompileShader(fragmentShader);
989 glGetShaderiv(*fragID_sptr, GL_COMPILE_STATUS, &result);
990 if (result != GL_TRUE)
992 std::cerr <<
"Erro compiling fragment shader: " << fragmentShaderPath << std::endl;
993 glGetShaderiv(*fragID_sptr, GL_INFO_LOG_LENGTH, &infoLogLength);
994 char * fragmentShaderErrorMessage =
new char[infoLogLength];
995 glGetShaderInfoLog(*fragID_sptr, infoLogLength, NULL, &fragmentShaderErrorMessage[0]);
996 fprintf(stdout,
"\n%s", &fragmentShaderErrorMessage[0]);
997 delete [] fragmentShaderErrorMessage;
1002 if (fragmentShaderPath.empty())
1004 std::cout <<
"Compiled fragment shader from string without errors : " << shaderName.c_str() << std::endl;
1008 std::cout <<
"Compiled fragment shader without errors : " << fragmentShaderPath << std::endl;
1013 glAttachShader(*programID_sptr, *fragID_sptr);
1027 string fragmentShaderCode;
1028 ifstream fragmentShaderStream(fragmentShaderPath.c_str(), std::ios::in);
1029 if(fragmentShaderStream.is_open())
1032 while(getline(fragmentShaderStream, line))
1034 fragmentShaderCode +=
"\n" + line;
1036 fragmentShaderStream.close();
1040 std::cerr <<
"warning: no fragment shader found : " << fragmentShaderPath << std::endl;
1043 setFragmentShader(fragmentShaderCode);
1044 fragment_code = fragmentShaderCode;
1054 GLint result = GL_FALSE;
1057 char const * computeSourcePointer = computeShaderCode.c_str();
1058 glShaderSource(*computeID_sptr, 1, &computeSourcePointer , NULL);
1059 glCompileShader(*computeID_sptr);
1062 glGetShaderiv(*computeID_sptr, GL_COMPILE_STATUS, &result);
1063 if (result != GL_TRUE)
1065 std::cerr <<
"Erro compiling compute shader: " << computeShaderPath << std::endl;
1066 glGetShaderiv(*computeID_sptr, GL_INFO_LOG_LENGTH, &infoLogLength);
1067 char * computeShaderErrorMessage =
new char[infoLogLength];
1068 glGetShaderInfoLog(*computeID_sptr, infoLogLength, NULL, &computeShaderErrorMessage[0]);
1069 fprintf(stdout,
"\n%s", &computeShaderErrorMessage[0]);
1070 delete [] computeShaderErrorMessage;
1075 if (computeShaderPath.empty())
1077 std::cout <<
"Compiled compute shader from string without errors : " << shaderName.c_str() << std::endl;
1081 std::cout <<
"Compiled compute shader without errors : " << computeShaderPath << std::endl;
1086 glAttachShader(*programID_sptr, *computeID_sptr);
1098 string computeShaderCode;
1099 ifstream computeShaderStream(computeShaderPath.c_str(), std::ios::in);
1100 if(computeShaderStream.is_open())
1103 while(getline(computeShaderStream, line))
1105 computeShaderCode +=
"\n" + line;
1107 computeShaderStream.close();
1111 std::cerr <<
"warning: no compute shader found : " << computeShaderPath << std::endl;
1114 setComputeShader(computeShaderCode);
1115 compute_shader_code = computeShaderCode;
1130 std::cout <<
"reloading shaders" << std::endl;
1135 glDetachShader(*programID_sptr, *vertexID_sptr);
1138 if (tessContID_sptr)
1140 glDetachShader(*programID_sptr, *tessContID_sptr);
1141 readTessellationControlCode();
1143 if (tessEvalID_sptr)
1145 glDetachShader(*programID_sptr, *tessEvalID_sptr);
1146 readTessellationEvaluationCode();
1150 glDetachShader(*programID_sptr, *geomID_sptr);
1155 glDetachShader(*programID_sptr, *fragID_sptr);
1160 glDetachShader(*programID_sptr, *computeID_sptr);
1161 readComputeShaderCode();
1178 glUseProgram(*programID_sptr);
1210 glGetProgramiv (*programID_sptr, GL_ACTIVE_ATTRIBUTES, &numattribs);
1211 glGetProgramiv (*programID_sptr, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxlength);
1216 char* name =
new char[maxlength];
1217 for (
int i = 0; i < numattribs; ++i)
1219 glGetActiveAttrib(*programID_sptr, i, maxlength, &length, &size, &type, name);
1220 attribs.push_back(name);
1232 return glGetUniformLocation(*programID_sptr, name);
1242 return glGetAttribLocation(*programID_sptr, name);
1258 void setUniform (GLint location, GLint a, GLint b, GLint c, GLint d)
1260 glUniform4i(location, a, b, c, d);
1272 glUniform3i(location, a, b, c);
1283 glUniform2i(location, a, b);
1293 glUniform1i(location, a);
1304 void setUniform (
const GLchar* name, GLint a, GLint b, GLint c, GLint d)
1306 GLint location = getUniformLocation(name);
1307 setUniform(location, a, b, c, d);
1319 GLint location = getUniformLocation(name);
1320 setUniform(location, a, b, c);
1331 GLint location = getUniformLocation(name);
1332 setUniform(location, a, b);
1342 GLint location = getUniformLocation(name);
1343 setUniform(location, a);
1353 glUniform4i(location, vec[0], vec[1], vec[2], vec[3]);
1363 glUniform3i(location, vec[0], vec[1], vec[2]);
1373 glUniform2i(location, vec[0], vec[1]);
1383 GLint location = getUniformLocation(name);
1384 setUniform(location, vec);
1394 GLint location = getUniformLocation(name);
1395 setUniform(location, vec);
1405 GLint location = getUniformLocation(name);
1406 setUniform(location, vec);
1420 void setUniform (GLint location, GLfloat a, GLfloat b, GLfloat c, GLfloat d)
1422 glUniform4f(location, a, b, c, d);
1432 void setUniform (GLint location, GLfloat a, GLfloat b, GLfloat c)
1434 glUniform3f(location, a, b, c);
1445 glUniform2f(location, a, b);
1455 glUniform1f(location, a);
1466 void setUniform (
const GLchar* name, GLfloat a, GLfloat b, GLfloat c, GLfloat d)
1468 GLint location = getUniformLocation(name);
1469 setUniform(location, a, b, c, d);
1479 void setUniform (
const GLchar* name, GLfloat a, GLfloat b, GLfloat c)
1481 GLint location = getUniformLocation(name);
1482 setUniform(location, a, b, c);
1493 GLint location = getUniformLocation(name);
1494 setUniform(location, a, b);
1504 GLint location = getUniformLocation(name);
1505 setUniform(location, a);
1515 glUniform4f(location, vec[0], vec[1], vec[2], vec[3]);
1525 glUniform3f(location, vec[0], vec[1], vec[2]);
1535 glUniform2f(location, vec[0], vec[1]);
1545 GLint location = getUniformLocation(name);
1546 setUniform(location, vec);
1556 GLint location = getUniformLocation(name);
1557 setUniform(location, vec);
1567 GLint location = getUniformLocation(name);
1568 setUniform(location, vec);
1582 void setUniform (GLint location, GLdouble a, GLdouble b, GLdouble c, GLdouble d)
1584 glUniform4f(location, (GLfloat)a, (GLfloat)b, (GLfloat)c, (GLfloat)d);
1595 void setUniform (GLint location, GLdouble a, GLdouble b, GLdouble c)
1597 glUniform3f(location, (GLfloat)a, (GLfloat)b, (GLfloat)c);
1609 glUniform2f(location, (GLfloat)a, (GLfloat)b);
1619 glUniform1f(location, (GLfloat)a);
1632 void setUniform (
const GLchar* name, GLdouble a, GLdouble b, GLdouble c, GLdouble d)
1634 GLint location = getUniformLocation(name);
1635 setUniform(location, a, b, c, d);
1647 void setUniform (
const GLchar* name, GLdouble a, GLdouble b, GLdouble c)
1649 GLint location = getUniformLocation(name);
1650 setUniform(location, a, b, c);
1663 GLint location = getUniformLocation(name);
1664 setUniform(location, a, b);
1673 GLint location = getUniformLocation(name);
1674 setUniform(location, a);
1685 glUniform4f(location, (GLfloat)vec[0], (GLfloat)vec[1], (GLfloat)vec[2], (GLfloat)vec[3]);
1695 glUniform3f(location, (GLfloat)vec[0], (GLfloat)vec[1], (GLfloat)vec[2]);
1705 glUniform2f(location, (GLfloat)vec[0], (GLfloat)vec[1]);
1715 GLint location = getUniformLocation(name);
1716 setUniform(location, vec);
1726 GLint location = getUniformLocation(name);
1727 setUniform(location, vec);
1737 GLint location = getUniformLocation(name);
1738 setUniform(location, vec);
1753 void setUniform (GLint location,
const GLint* v, GLuint nvalues, GLsizei count = 1)
1757 case 1: glUniform1iv(location, count, v);
break;
1758 case 2: glUniform2iv(location, count, v);
break;
1759 case 3: glUniform3iv(location, count, v);
break;
1760 case 4: glUniform4iv(location, count, v);
break;
1773 void setUniform (GLint location,
const GLfloat* v, GLuint nvalues, GLsizei count = 1)
1777 case 1: glUniform1fv(location, count, v);
break;
1778 case 2: glUniform2fv(location, count, v);
break;
1779 case 3: glUniform3fv(location, count, v);
break;
1780 case 4: glUniform4fv(location, count, v);
break;
1793 void setUniform (
const GLchar* name,
const GLint* v, GLuint nvalues, GLsizei count = 1)
1795 GLint location = getUniformLocation(name);
1796 setUniform(location,v,nvalues,count);
1809 void setUniform (
const GLchar* name,
const GLfloat* v, GLuint nvalues, GLsizei count = 1)
1811 GLint location = getUniformLocation(name);
1812 setUniform(location, v, nvalues, count);
1830 void setUniform (GLint location,
const GLfloat* m, GLuint dim, GLboolean transpose = GL_FALSE, GLsizei count = 1)
1834 case 2: glUniformMatrix2fv(location, count, transpose, m);
break;
1835 case 3: glUniformMatrix3fv(location, count, transpose, m);
break;
1836 case 4: glUniformMatrix4fv(location, count, transpose, m);
break;
1852 void setUniform (
const GLchar* name,
const GLfloat* m, GLuint dim, GLboolean transpose = GL_FALSE, GLsizei count = 1)
1854 GLint location = getUniformLocation(name);
1855 setUniform(location, m, dim, transpose, count);
1865 glUniformMatrix4fv(location, 1, GL_FALSE, matrix.data());
1875 glUniformMatrix3fv(location, 1, GL_FALSE, matrix.data());
1885 glUniformMatrix2fv(location, 1, GL_FALSE, matrix.data());
1893 void setUniform (
const GLchar* name,
const Eigen::Matrix4f &matrix)
1895 GLint location = getUniformLocation(name);
1896 setUniform(location, matrix);
1904 void setUniform (
const GLchar* name,
const Eigen::Matrix3f &matrix)
1906 GLint location = getUniformLocation(name);
1907 setUniform(location, matrix);
1915 void setUniform (
const GLchar* name,
const Eigen::Matrix2f &matrix)
1917 GLint location = getUniformLocation(name);
1918 setUniform(location, matrix);
1926 void setUniform (GLint location,
const Eigen::Affine3f &affine_matrix)
1928 glUniformMatrix4fv(location, 1, GL_FALSE, affine_matrix.matrix().data());
1936 void setUniform (GLint location,
const Eigen::Affine2f &affine_matrix)
1938 glUniformMatrix3fv(location, 1, GL_FALSE, affine_matrix.matrix().data());
1946 void setUniform (
const GLchar* name,
const Eigen::Affine3f &affine_matrix)
1948 GLint location = getUniformLocation(name);
1949 setUniform(location, affine_matrix);
1957 void setUniform (
const GLchar* name,
const Eigen::Affine2f &affine_matrix)
1959 GLint location = getUniformLocation(name);
1960 setUniform(location, affine_matrix);
string tessellationEvaluationShaderPath
Stores the path to the tessellation evaluation shader file.
Definition: shader.hpp:59
void setUniform(const GLchar *name, const Eigen::Affine2f &affine_matrix)
Sets a uniform 3x3 float matrix value given its name in shader and eigen 2x2 affine matrix...
Definition: shader.hpp:1957
GLuint getVertexShader(void)
Returns a handle to the vertex shader.
Definition: shader.hpp:371
Shader()
Empty constructor.
Definition: shader.hpp:296
void setUniform(GLint location, const Eigen::Vector2f &vec)
Sets an uniform float 2D vector (vec2) given a location and the vector with values.
Definition: shader.hpp:1533
GLuint getGeometryShader(void)
Returns a handle to the geometry shader.
Definition: shader.hpp:382
void setFragmentShader(string &fragmentShaderCode)
Loads fragment code into shader program.
Definition: shader.hpp:979
string fragmentShaderPath
Stores the path to the fragment shader file.
Definition: shader.hpp:65
string shaderName
Stores an user mainteined identification for the shader. If the shader is created with the autoloader...
Definition: shader.hpp:50
void setUniform(GLint location, const Eigen::Matrix2f &matrix)
Sets a uniform 2x2 float matrix value given its location and eigen 2x2 matrix.
Definition: shader.hpp:1883
GLuint getFragmentShader(void)
Returns a handle to the fragment shader.
Definition: shader.hpp:360
string compute_shader_code
Compute shader code.
Definition: shader.hpp:86
void setUniform(const GLchar *name, const Eigen::Matrix3f &matrix)
Sets a uniform 3x3 float matrix value given its name in shader and eigen 3x3 matrix.
Definition: shader.hpp:1904
Shader(string name, string shader_dir)
Constructors that searches a given directory for shaders with given name.
Definition: shader.hpp:286
GLuint getTessellationEvaluationShader(void)
Returns a handle to the tessellation evaluation shader.
Definition: shader.hpp:405
GLint getAttributeLocation(const GLchar *name) const
Definition: shader.hpp:1240
void setUniform(const GLchar *name, GLfloat a, GLfloat b, GLfloat c, GLfloat d)
Sets an uniform float 4D vector (vec4) given its name in the shader and the vector values...
Definition: shader.hpp:1466
void setUniform(GLint location, GLdouble a, GLdouble b, GLdouble c, GLdouble d)
Sets an uniform float 4D vector (vec4) given a location and the vector values as Double. The double values are converted to float.
Definition: shader.hpp:1582
string geometryShaderPath
Stores the path to the geometry shader file.
Definition: shader.hpp:62
void setUniform(GLint location, GLint a, GLint b, GLint c)
Sets an uniform integer 3D vector (ivec3) given a location and the vector values. ...
Definition: shader.hpp:1270
Definition: bufferobject.hpp:34
void setUniform(const GLchar *name, const Eigen::Vector4f &vec)
Sets an uniform float 4D vector (vec4) given its name in the shader and the vector with values...
Definition: shader.hpp:1543
void initialize(void)
Calls all the functions related to the shader initialization, i.e., creates, loads the shaders from t...
Definition: shader.hpp:641
void setShaderName(string name)
Sets the shader name, very useful for debugging.
Definition: shader.hpp:329
void setGeometryShader(string &geometryShaderCode)
Loads geometry code into shader program.
Definition: shader.hpp:904
void setUniform(GLint location, const Eigen::Vector4d vec)
Sets an uniform float 4D vector (vec4) given a location and the double vector that is converted to fl...
Definition: shader.hpp:1683
void readVertexCode(void)
Reads the external file containing the vertex shader and loads it into the shader program...
Definition: shader.hpp:728
void createShaders(void)
Create the necessary shaders.
Definition: shader.hpp:172
void setUniform(GLint location, const Eigen::Vector4f &vec)
Sets an uniform float 4D vector (vec4) given a location and the vector with values.
Definition: shader.hpp:1513
void setUniform(GLint location, GLint a)
Sets an uniform integer given a location and the integer value.
Definition: shader.hpp:1291
void setUniform(GLint location, GLdouble a, GLdouble b, GLdouble c)
Sets an uniform float 3D vector (vec3) given a location and the vector values as Double. The double values are converted to float.
Definition: shader.hpp:1595
string getShaderName(void)
Returns a string with the shader name.
Definition: shader.hpp:340
void setUniform(const GLchar *name, GLint a, GLint b, GLint c, GLint d)
Sets an uniform integer 4D vector (ivec4) given its name in the shader and the vector values...
Definition: shader.hpp:1304
A Shader object represents one GLSL program.
Definition: shader.hpp:45
string tessellationControlShaderPath
Stores the path to the tessellation control shader file.
Definition: shader.hpp:56
void setUniform(GLint location, const Eigen::Matrix3f &matrix)
Sets a uniform 3x3 float matrix value given its location and eigen 3x3 matrix.
Definition: shader.hpp:1873
void setUniform(GLint location, const Eigen::Vector3i &vec)
Sets an uniform integer 3D vector (ivec3) given a location and the vector with values.
Definition: shader.hpp:1361
void setUniform(GLint location, GLfloat a, GLfloat b, GLfloat c, GLfloat d)
Sets an uniform float 4D vector (vec4) given a location and the vector values.
Definition: shader.hpp:1420
void setUniform(GLint location, const Eigen::Vector2d vec)
Sets an uniform float 2D vector (vec2) given a location and the double vector that is converted to fl...
Definition: shader.hpp:1703
void setUniform(const GLchar *name, GLint a, GLint b)
Sets an uniform integer 2D vector (ivec2) given its name in the shader and the vector values...
Definition: shader.hpp:1329
void setUniform(const GLchar *name, const Eigen::Matrix4f &matrix)
Sets a uniform 4x4 float matrix value given its name in shader and eigen 4x4 matrix.
Definition: shader.hpp:1893
void getActiveAttributes(vector< string > &attribs)
Detaches and deletes the shaders and the shader program.
Definition: shader.hpp:1205
void setUniform(const GLchar *name, const Eigen::Vector3f &vec)
Sets an uniform float 3D vector (vec3) given its name in the shader and the vector with values...
Definition: shader.hpp:1554
void setUniform(const GLchar *name, const Eigen::Vector2f &vec)
Sets an uniform float 2D vector (vec2) given its name in the shader and the vector with values...
Definition: shader.hpp:1565
void setUniform(GLint location, GLdouble a, GLdouble b)
Sets an uniform float 2D vector (vec2) given a location and the vector values as Double. The double values are converted to float.
Definition: shader.hpp:1607
void errorCheckFunc(std::string file, int line, std::string message="")
GL error check method.
Definition: misc.hpp:53
void initializeFromStrings(string in_vertex_code, string in_fragment_code, string in_geometry_code="", string in_tessellation_evaluation_code="", string in_tessellation_control_code="")
Initializes shader directly from string, no files.
Definition: shader.hpp:589
void setUniform(const GLchar *name, const Eigen::Vector3i &vec)
Sets an uniform integer 3D vector (ivec3) given its name in the shader and the vector with values...
Definition: shader.hpp:1392
void setUniform(GLint location, GLfloat a)
Sets an uniform float given a location and the float value.
Definition: shader.hpp:1453
void setUniform(const GLchar *name, GLdouble a, GLdouble b)
Sets an uniform float 2D vector (vec2) given its name in the shader and the vector values as Double...
Definition: shader.hpp:1661
void setUniform(GLint location, GLfloat a, GLfloat b, GLfloat c)
Sets an uniform float 3D vector (vec3) given a location and the vector values.
Definition: shader.hpp:1432
void initializeTF(int size, const char **varlist, GLenum buffer_mode=GL_INTERLEAVED_ATTRIBS)
Initializes shader and prepares it to use Transform Feedback.
Definition: shader.hpp:541
void setUniform(const GLchar *name, GLint a, GLint b, GLint c)
Sets an uniform integer 3D vector (ivec3) given its name in the shader and the vector values...
Definition: shader.hpp:1317
void setVertexShader(string &vertexShaderCode)
Loads vertex code into shader program.
Definition: shader.hpp:682
void setUniform(const GLchar *name, const Eigen::Vector2d vec)
Sets an uniform float 2D vector (vec2) given its name in the shader and the double vector that is con...
Definition: shader.hpp:1735
void setUniform(GLint location, const GLfloat *v, GLuint nvalues, GLsizei count=1)
Sets a float uniform vector value given its location and an array with the values.
Definition: shader.hpp:1773
void setUniform(const GLchar *name, GLdouble a)
Sets an uniform float given its name in the shader and a double value that is converted to float...
Definition: shader.hpp:1671
Shader(string name, string vertex_shader_path, string fragment_shader_path, string geometry_shader_path="", string tessellation_evaluation_shader_path="", string tessellation_control_shader_path="")
Constructor that receives the path for each shader separately.
Definition: shader.hpp:267
void setUniform(GLint location, const Eigen::Affine3f &affine_matrix)
Sets a uniform 4x4 float matrix value given its location and eigen 3x3 affine matrix.
Definition: shader.hpp:1926
void reloadShaders(void)
Reloads all shaders by reading the files again.
Definition: shader.hpp:1126
void setUniform(GLint location, GLdouble a)
Sets an uniform float given a location and a double value that is converted to float.
Definition: shader.hpp:1617
void readComputeShaderCode(void)
Reads the external file containing the compute shader code.
Definition: shader.hpp:1096
void setUniform(const GLchar *name, const Eigen::Vector4d vec)
Sets an uniform float 4D vector (vec4) given its name in the shader and the double vector that is con...
Definition: shader.hpp:1713
void readFragmentCode(void)
Reads the external file containing the fragment shader and loads it into the shader program...
Definition: shader.hpp:1024
GLuint getTessellationControlShader(void)
Returns a handle to the tessellation control shader.
Definition: shader.hpp:393
GLuint getComputeShader(void)
Definition: shader.hpp:417
void setComputeShader(string &computeShaderCode)
Loads compute code into shader program.
Definition: shader.hpp:1052
GLuint getShaderProgram(void)
Returns the program identification handle.
Definition: shader.hpp:349
void readTessellationEvaluationCode(void)
Reads the external file containing the tessellation evaluation shader and loads it into the shader pr...
Definition: shader.hpp:875
void setUniform(GLint location, GLint a, GLint b)
Sets an uniform integer 2D vector (ivec2) given a location and the vector values. ...
Definition: shader.hpp:1281
string vertexShaderPath
Stores the path to the vertex shader file.
Definition: shader.hpp:53
string vertex_code
Vertex shader code.
Definition: shader.hpp:71
void unbind(void)
Disables the shader program.
Definition: shader.hpp:1184
void setUniform(const GLchar *name, const GLfloat *m, GLuint dim, GLboolean transpose=GL_FALSE, GLsizei count=1)
Sets a uniform float matrix value given its name in shader code.
Definition: shader.hpp:1852
void createProgramID(void)
Copy Contructor Copies the shader codes and recompiles to generate new program.
Definition: shader.hpp:155
void setUniform(GLint location, const Eigen::Vector3f &vec)
Sets an uniform float 3D vector (vec3) given a location and the vector with values.
Definition: shader.hpp:1523
string geometry_code
Geometry shader code.
Definition: shader.hpp:77
void setUniform(const GLchar *name, const GLfloat *v, GLuint nvalues, GLsizei count=1)
Sets a float uniform vector value given its name in shader and an array with the values.
Definition: shader.hpp:1809
void setUniform(const GLchar *name, GLfloat a)
Sets an uniform float given its name in the shader and the float value.
Definition: shader.hpp:1502
string fragment_code
Fragment shader code.
Definition: shader.hpp:74
void readTessellationControlCode(void)
Reads the external file containing the tessellation control shader and loads it into the shader progr...
Definition: shader.hpp:802
void setUniform(const GLchar *name, const Eigen::Vector2i &vec)
Sets an uniform integer 2D vector (ivec2) given its name in the shader and the vector with values...
Definition: shader.hpp:1403
string computeShaderPath
Stores the paths to the compute shaders files.
Definition: shader.hpp:68
void setUniform(const GLchar *name, const Eigen::Affine3f &affine_matrix)
Sets a uniform 4x4 float matrix value given its name in shader and eigen 3x3 affine matrix...
Definition: shader.hpp:1946
void setUniform(const GLchar *name, GLfloat a, GLfloat b)
Sets an uniform float 2D vector (vec4) given its name in the shader and the vector values...
Definition: shader.hpp:1491
void setUniform(const GLchar *name, GLfloat a, GLfloat b, GLfloat c)
Sets an uniform float 3D vector (vec3) given its name in the shader and the vector values...
Definition: shader.hpp:1479
void setUniform(const GLchar *name, const Eigen::Matrix2f &matrix)
Sets a uniform 2x2 float matrix value given its name in shader and eigen 2x2 matrix.
Definition: shader.hpp:1915
void setUniform(const GLchar *name, const Eigen::Vector3d vec)
Sets an uniform float 3D vector (vec3) given its name in the shader and the double vector that is con...
Definition: shader.hpp:1724
void setTessellationEvaluationShader(string &tessellationEvaluationCode)
Loads tessellation evaluation code into shader program.
Definition: shader.hpp:830
void setUniform(const GLchar *name, const Eigen::Vector4i &vec)
Sets an uniform integer 4D vector (ivec4) given its name in the shader and the vector with values...
Definition: shader.hpp:1381
void load(string name, string shader_dir="")
Loads a shader given a directory and a name. Searches for all shader extensions in directory...
Definition: shader.hpp:436
void bind(void)
Enables the shader program for usage.
Definition: shader.hpp:1176
void setUniform(GLint location, const GLint *v, GLuint nvalues, GLsizei count=1)
Sets a integer uniform vector value given its location and an array with the values.
Definition: shader.hpp:1753
void setTessellationControlShader(string &tessellationControlCode)
Loads tessellation control code into shader program.
Definition: shader.hpp:757
string tessellation_evaluation_code
Tesselation evaluation code.
Definition: shader.hpp:80
void setUniform(GLint location, const Eigen::Affine2f &affine_matrix)
Sets a uniform 3x3 float matrix value given its location and eigen 2x2 affine matrix.
Definition: shader.hpp:1936
void setUniform(GLint location, const Eigen::Vector3d vec)
Sets an uniform float 3D vector (vec3) given a location and the double vector that is converted to fl...
Definition: shader.hpp:1693
void setUniform(GLint location, const GLfloat *m, GLuint dim, GLboolean transpose=GL_FALSE, GLsizei count=1)
Sets a uniform float matrix value given its location.
Definition: shader.hpp:1830
void linkProgram(void)
Link shader program and check for link errors.
Definition: shader.hpp:508
void setUniform(GLint location, const Eigen::Matrix4f &matrix)
Sets a uniform 4x4 float matrix value given its location and eigen 4x4 matrix.
Definition: shader.hpp:1863
void setUniform(GLint location, GLfloat a, GLfloat b)
Sets an uniform float 2D vector (vec2) given a location and the vector values.
Definition: shader.hpp:1443
void setUniform(const GLchar *name, GLdouble a, GLdouble b, GLdouble c)
Sets an uniform float 3D vector (vec3) given its name in the shader and the vector values as Double...
Definition: shader.hpp:1647
void setUniform(const GLchar *name, GLint a)
Sets an uniform integer given its name in the shader and the integer value.
Definition: shader.hpp:1340
GLint getUniformLocation(const GLchar *name) const
Definition: shader.hpp:1230
string tessellation_control_code
Tesselation control code.
Definition: shader.hpp:83
void setUniform(GLint location, const Eigen::Vector4i &vec)
Sets an uniform integer 4D vector (ivec4) given a location and the vector with values.
Definition: shader.hpp:1351
void setUniform(GLint location, const Eigen::Vector2i &vec)
Sets an uniform integer 2D vector (ivec2) given a location and the vector with values.
Definition: shader.hpp:1371
void setUniform(const GLchar *name, GLdouble a, GLdouble b, GLdouble c, GLdouble d)
Sets an uniform float 4D vector (vec4) given its name in the shader and the vector values as Double...
Definition: shader.hpp:1632
void readGeometryCode(void)
Reads the external file containing the geometry shader and loads it into the shader program...
Definition: shader.hpp:950
void setUniform(const GLchar *name, const GLint *v, GLuint nvalues, GLsizei count=1)
Sets a integer uniform vector value given its name in shader and an array with the values...
Definition: shader.hpp:1793
void setUniform(GLint location, GLint a, GLint b, GLint c, GLint d)
Sets an uniform integer 4D vector (ivec4) given a location and the vector values. ...
Definition: shader.hpp:1258