44 #include "ClassicDepthPeeling.hh" 46 #include <ObjectTypes/Light/LightNode.hh> 48 #include <ACG/GL/GLError.hh> 55 DepthPeelingPlugin::DepthPeelingPlugin() :
61 for (
unsigned int i = 0; i < 16; ++i)
62 lightTypes_[i] = LIGHTTYPE_POINT;
64 for (
unsigned int i = 0; i < PEEL_NUM_COMBINATIONS; ++i)
67 for (
unsigned int i = 0; i < PEEL_NUM_COMBINATIONS*3; ++i)
70 for (
unsigned int i = 0; i < 8; ++i)
73 for (
unsigned int i = 0; i < 4; ++i)
74 blendDualPeelProg_[i] = 0;
76 for (
unsigned int i = 0; i < 16; ++i)
82 DepthPeelingPlugin::~DepthPeelingPlugin() {
87 DepthPeelingPlugin::ViewerResources::ViewerResources()
89 rtWidth_ = rtHeight_ = 0;
91 glWidth_ = glHeight_ = 0;
93 memset(blendDualPeelTexID_, 0, 7*4);
95 blendDualPeelFbo_ = 0;
98 void DepthPeelingPlugin::initializePlugin()
100 memset(blendShaders_, 0,
sizeof(blendShaders_));
101 memset(peelShaders_, 0,
sizeof(peelShaders_));
103 memset(blendDualPeelProg_, 0,
sizeof(blendDualPeelProg_));
104 memset(peelProgs_, 0,
sizeof(peelProgs_));
114 void DepthPeelingPlugin::exit()
121 QString DepthPeelingPlugin::rendererName() {
122 return QString(
"Classical Depth Peeling Renderer");
144 glVertex2f(x0, y0-h);
145 glVertex2f(x0+w, y0-h);
146 glVertex2f(x0+w, y0);
175 if (lightID != GL_INVALID_ENUM)
177 int id = lightID - GL_LIGHT0;
182 lightTypes_[
numLights_] = LIGHTTYPE_DIRECTIONAL;
183 else if (light.spotCutoff() > 179.5f)
207 traverseLightNodes(*cIt);
212 traverseLightNodes(*cIt);
223 GLSL::StringList* _strFragmentShaderOut,
224 GLSL::StringList* _strGeometryShaderOut,
231 if (_flatShaded) _phong =
false;
232 if (_vertexColor) _phong =
false;
234 std::string strColor =
"color";
235 std::string strNormal =
"normal";
236 std::string strFragPos =
"vPosVS";
239 strFragPos =
"VPosVS";
242 _flatShaded = _vertexColor = _textured = _phong =
false;
244 std::string strCode =
"";
246 for (
unsigned int i = 0; i <
numLights_ && (!_wireFrame); ++i)
251 std::string strLight =
"gl_LightSource[";
252 std::string strMaterial =
"gl_FrontLightProduct[";
255 sprintf(szTmp,
"%u]", glLightIDs_[i]);
258 strMaterial += szTmp;
262 if (lightTypes_[i] == LIGHTTYPE_DIRECTIONAL)
263 strCode +=
"vec3 vLightVS = " + strLight +
".position.xyz;\n";
265 strCode +=
"vec3 vLightVS = " + strLight +
".position.xyz - " + strFragPos +
".xyz;\n";
267 strCode +=
"vec3 vLightDir = normalize(vLightVS);\n";
270 strCode +=
"vec4 colLight = " + strMaterial +
".ambient;\n";
273 strCode +=
"float ldotn = dot(vLightDir, " + strNormal +
");\n";
274 strCode +=
"ldotn = clamp(ldotn, 0.0, 1.0);\n";
275 strCode +=
"colLight += ldotn * ";
276 if (_textured && _phong)
277 strCode +=
"diffColor * ";
282 strCode +=
"vColor[2];\n";
284 strCode +=
"gl_Color;\n";
287 strCode += strMaterial +
".diffuse;\n";
290 strCode +=
"colLight += floor(ldotn + 0.9) * pow(ldotn, gl_FrontMaterial.shininess) * " + strMaterial +
".specular;\n";
293 if (lightTypes_[i] == LIGHTTYPE_DIRECTIONAL)
294 strCode += strColor +
".rgb += colLight.rgb;\n";
298 strCode +=
"float fLenSq = dot(vLightVS, vLightVS);\n";
299 strCode +=
"float atten = " + strLight +
".constantAttenuation + " +
300 strLight +
".linearAttenuation * sqrt(fLenSq) + " +
301 strLight +
".quadraticAttenuation * fLenSq;\n";
303 if (lightTypes_[i] == LIGHTTYPE_POINT)
304 strCode += strColor +
".rgb += colLight.rgb / atten;\n";
308 strCode +=
"float spot = -dot(vLightDir, " + strLight +
".spotDirection);\n";
309 strCode +=
"spot *= step(" + strLight +
".spotCosCutoff, spot);\n";
310 strCode +=
"spot *= pow(spot, " + strLight +
".spotExponent);\n";
312 strCode += strColor +
".rgb += " +
"(spot / atten) * colLight.rgb;\n";
319 const char* szVertexShader[] = {
"varying vec2 vTexCoord;",
320 "varying vec3 vNormal; // normal: view space",
321 "varying vec4 vPosVS; // position in view space",
322 "varying vec4 vColor; // used in gouraud / flat shading only",
326 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;",
328 " vNormal = gl_NormalMatrix * gl_Normal; // gl_NormalMatrix : upper left 3x3 of WorldViewIT",
329 " vPosVS = (gl_ModelViewMatrix * gl_Vertex);",
330 " vTexCoord = gl_MultiTexCoord0.xy;",
335 const char* szGeometryShaderStart[] = {
337 "#extension GL_ARB_geometry_shader4 : enable",
339 "varying vec2 vTexCoord[3];",
340 "varying vec4 vPosVS[3];",
341 "varying vec3 vNormal[3];",
342 "varying vec4 vColor[3];",
344 "varying vec2 VTexCoord;",
345 "varying vec3 VNormal;",
346 "varying vec4 VPosVS;",
347 "varying vec4 VColor;",
352 " // recompute triangle normal",
354 " vec3 normal = cross(gl_PositionIn[1].xyz - gl_PositionIn[0].xyz, gl_PositionIn[2].xyz - gl_PositionIn[0].xyz);",
355 " normal = normalize(normal);",
356 " normal = gl_NormalMatrix * normal;",
359 " VPosVS = (gl_PositionIn[0] + gl_PositionIn[1] + gl_PositionIn[2]) / 3.0;",
360 " VPosVS = gl_ModelViewMatrix * VPosVS; // triangle center in view space needed for point and spot lights",
361 " vec4 color = vec4(gl_FrontMaterial.emission.rgb, gl_FrontMaterial.diffuse.a);",
364 const char* szGeometryShaderEnd[] = {
366 " for(int i = 0; i < 3; i++)",
368 " gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[i];",
369 " VTexCoord = vTexCoord[i];",
370 " VNormal = normal;",
371 " VPosVS = vPosVS[i];",
380 const char* szFragmentShaderStart[] = {
"varying vec2 vTexCoord;",
381 "varying vec3 vNormal; ",
382 "varying vec4 vPosVS;",
383 "varying vec4 vColor;",
385 "uniform sampler2D DiffuseTex;",
386 "uniform sampler2DRect DepthBlenderTex;",
387 "uniform sampler2DRect FrontBlenderTex;",
389 "#define MAX_DEPTH 1.0",
394 " // window-space depth interpolated linearly in screen space",
395 " float fragDepth = gl_FragCoord.z;",
397 " vec2 depthBlender = texture2DRect(DepthBlenderTex, gl_FragCoord.xy).xy;",
398 " vec4 forwardTemp = texture2DRect(FrontBlenderTex, gl_FragCoord.xy);",
400 " // Depths and 1.0-alphaMult always increase",
401 " // so we can use pass-through by default with MAX blending",
402 " gl_FragData[0].xy = depthBlender;",
404 " // Front colors always increase (DST += SRC*ALPHA_MULT)",
405 " // so we can use pass-through by default with MAX blending",
406 " gl_FragData[1] = forwardTemp;",
408 " // Because over blending makes color increase or decrease,",
409 " // we cannot pass-through by default.",
410 " // Each pass, only one fragment writes a color greater than 0",
411 " gl_FragData[2] = vec4(0.0);",
413 " float nearestDepth = -depthBlender.x;",
414 " float farthestDepth = depthBlender.y;",
415 " float alphaMultiplier = 1.0 - forwardTemp.w;",
417 " if (fragDepth < nearestDepth || fragDepth > farthestDepth) {",
418 " // Skip this depth in the peeling algorithm",
419 " gl_FragData[0].xy = vec2(-MAX_DEPTH);",
423 " if (fragDepth > nearestDepth && fragDepth < farthestDepth) {",
424 " // This fragment needs to be peeled again",
425 " gl_FragData[0].xy = vec2(-fragDepth, fragDepth);",
429 " // If we made it here, this fragment is on the peeled layer from last pass",
430 " // therefore, we need to shade it, and make sure it is not peeled any farther",
433 const char* szFragmentShaderEnd[] = {
"",
434 " gl_FragData[0].xy = vec2(-MAX_DEPTH);",
436 " if (fragDepth == nearestDepth) {",
437 " gl_FragData[1].xyz += color.rgb * color.a * alphaMultiplier;",
438 " gl_FragData[1].w = 1.0 - alphaMultiplier * (1.0 - color.a);",
440 " gl_FragData[2] += color;",
447 for (
unsigned int i = 0; i <
sizeof(szVertexShader) /
sizeof(
char*); ++i)
449 std::string str = szVertexShader[i];
452 if (!strncmp(
"varying vec4 vColor", str.c_str(), strlen(
"varying vec4 vColor")))
460 _strVertexShaderOut->push_back(str);
464 if (!_phong && !_flatShaded && !_wireFrame)
467 _strVertexShaderOut->push_back(
"\nvec4 color = vec4(gl_FrontMaterial.emission.rgb, gl_FrontMaterial.diffuse.a);");
468 _strVertexShaderOut->push_back(
"\nvec3 normal = vNormal;\n");
470 std::string::size_type curPos = 0;
471 std::string::size_type newLinePos = strCode.find_first_of(
'\n');
472 while (newLinePos != std::string::npos)
474 _strVertexShaderOut->push_back(strCode.substr(curPos, newLinePos - curPos + 1));
475 curPos = newLinePos + 1;
476 newLinePos = strCode.find_first_of(
'\n', curPos);
478 _strVertexShaderOut->push_back(
"\nvColor = color;\n");
483 _strVertexShaderOut->push_back(
"vColor = gl_Color;\n");
484 _strVertexShaderOut->push_back(
"gl_Position = gl_Vertex;\n");
487 _strVertexShaderOut->push_back(
"\n}");
490 for (
unsigned int i = 0; i <
sizeof(szFragmentShaderStart) /
sizeof(
char*); ++i)
492 std::string str = szFragmentShaderStart[i];
495 if (!strncmp(
"varying vec4 vColor", str.c_str(), strlen(
"varying vec4 vColor")))
504 if (!strncmp(
"varying vec2 vTexCoord", str.c_str(), strlen(
"varying vec2 vTexCoord")))
505 str =
"varying vec2 VTexCoord;";
506 if (!strncmp(
"varying vec3 vNormal", str.c_str(), strlen(
"varying vec3 vNormal")))
507 str =
"varying vec3 VNormal;";
508 if (!strncmp(
"varying vec4 vPosVS", str.c_str(), strlen(
"varying vec4 vPosVS")))
509 str =
"varying vec4 VPosVS;";
510 if (!strncmp(
"varying vec4 vColor", str.c_str(), strlen(
"varying vec4 vColor")))
511 str =
"varying vec4 VColor;";
514 _strFragmentShaderOut->push_back(str);
521 _strFragmentShaderOut->push_back(
" vec3 normal = normalize(vNormal);\n");
523 _strFragmentShaderOut->push_back(
" vec4 color = vec4(gl_FrontMaterial.emission.rgb, gl_FrontMaterial.diffuse.a);\n");
525 _strFragmentShaderOut->push_back(
" vec4 diffColor = texture2D(DiffuseTex, vTexCoord); color.a *= diffColor.a;\n");
529 _strFragmentShaderOut->push_back(
" vec4 color = vec4(gl_FrontMaterial.emission.rgb, gl_FrontMaterial.diffuse.a);\n");
530 _strFragmentShaderOut->push_back(
" vec4 vColor = VColor;\n");
532 _strFragmentShaderOut->push_back(
" vec4 diffColor = texture2D(DiffuseTex, VTexCoord); color.a *= diffColor.a;\n");
538 _strFragmentShaderOut->push_back(
" color = diffColor * vColor;\n");
540 _strFragmentShaderOut->push_back(
" color = vColor;\n");
545 std::string::size_type curPos = 0;
546 std::string::size_type newLinePos = strCode.find_first_of(
'\n');
547 while (newLinePos != std::string::npos)
549 _strFragmentShaderOut->push_back(strCode.substr(curPos, newLinePos - curPos + 1));
550 curPos = newLinePos + 1;
551 newLinePos = strCode.find_first_of(
'\n', curPos);
556 _strFragmentShaderOut->push_back(
" vec4 color = vColor;\n");
558 for (
unsigned int i = 0; i <
sizeof(szFragmentShaderEnd) /
sizeof(
char*); ++i)
560 std::string str = szFragmentShaderEnd[i];
562 _strFragmentShaderOut->push_back(str);
569 for (
unsigned int i = 0; i <
sizeof(szGeometryShaderStart) /
sizeof(
char*); ++i)
571 std::string str = szGeometryShaderStart[i];
573 _strGeometryShaderOut->push_back(str);
577 std::string::size_type curPos = 0;
578 std::string::size_type newLinePos = strCode.find_first_of(
'\n');
579 while (newLinePos != std::string::npos)
581 _strGeometryShaderOut->push_back(strCode.substr(curPos, newLinePos - curPos + 1));
582 curPos = newLinePos + 1;
583 newLinePos = strCode.find_first_of(
'\n', curPos);
586 for (
unsigned int i = 0; i <
sizeof(szGeometryShaderEnd) /
sizeof(
char*); ++i)
588 std::string str = szGeometryShaderEnd[i];
590 _strGeometryShaderOut->push_back(str);
596 #ifdef DEPTHPEELING_SHADER_EXPORT 597 FILE* pShaderOut = fopen(
"peel_vertex.glsl",
"wt");
598 for (GLSL::StringList::iterator it = _strVertexShaderOut->begin(); it != _strVertexShaderOut->end(); ++it)
599 fprintf(pShaderOut, it->c_str());
603 pShaderOut = fopen(
"peel_frag.glsl",
"wt");
604 for (GLSL::StringList::iterator it = _strFragmentShaderOut->begin(); it != _strFragmentShaderOut->end(); ++it)
605 fprintf(pShaderOut, it->c_str());
610 pShaderOut = fopen(
"peel_geom.glsl",
"wt");
611 for (GLSL::StringList::iterator it = _strGeometryShaderOut->begin(); it != _strGeometryShaderOut->end(); ++it)
612 fprintf(pShaderOut, it->c_str());
620 template <
class Action>
633 dm = _globalDrawMode;
648 dmShaded &= ~
ACG::SceneGraph::DrawModes::WIREFRAME;
649 dmShaded &= ~
ACG::SceneGraph::DrawModes::HIDDENLINE;
655 ret &= traverseDrawApplyAction(_node, _action, _globalDrawMode, _pass, _peelPass);
663 unsigned int shaderIndex = getPeelShaderIndex(dm);
666 GLenum prev_depth = glStateTmp_->depthFunc();
667 if (dm & ACG::SceneGraph::DrawModes::HIDDENLINE)
675 GLSL::Program* peelProg = peelProgs_[PEEL_SHADER_HIDDENLINE];
679 peelProg->
setUniform(
"ObjectColor", glStateTmp_->clear_color());
684 ret &= _action(_node);
694 ACG::GLState::lockDepthFunc();
697 shaderIndex = PEEL_SHADER_WIREFRAME;
705 if (shaderIndex & PEEL_SHADER_FLAT)
715 ret &= _action(_node);
721 if (dm & ACG::SceneGraph::DrawModes::HIDDENLINE)
723 ACG::GLState::unlockDepthFunc();
734 template <
class Action>
750 if_has_enter(_action, _node);
757 process_children &= traverseDrawApplyAction(_node, _action, _globalDrawMode, _pass, _peelPass);
759 if (process_children) {
766 traverseDraw(*cIt, _action, _globalDrawMode, _pass, _peelPass);
771 traverseDraw(*cIt, _action, _globalDrawMode, _pass, _peelPass);
780 traverseDrawApplyAction(_node, _action, _globalDrawMode, _pass, _peelPass);
784 if_has_leave(_action, _node);
802 for(
unsigned int pass = BaseNode::PASS_1; pass <= (BaseNode::PASS_1 + max_passes); ++pass) {
805 traverseDraw (_sceneGraphRoot, action, _drawMode, pass, _peelPass);
826 bool rebuildShaders =
false;
833 unsigned int prevIDs[8];
837 memcpy(prevIDs, glLightIDs_,
sizeof(
unsigned int) * numLights_);
840 traverseLightNodes(sceneGraphRoot);
843 if (numLights_ == prevNum)
846 if (memcmp(prevLights, lightTypes_,
sizeof(
LightType) * numLights_) ||
847 memcmp(prevIDs, glLightIDs_,
sizeof(
unsigned int) * numLights_))
848 rebuildShaders =
true;
850 else rebuildShaders =
true;
855 for (
unsigned int i = 0; i <
sizeof(peelShaders_) /
sizeof(peelShaders_[0]); ++i)
857 delete peelShaders_[i]; peelShaders_[i] = 0;
860 for (
unsigned int i = 0; i <
sizeof(peelProgs_) /
sizeof(peelProgs_[0]); ++i)
862 delete peelProgs_[i]; peelProgs_[i] = 0;
865 for (
unsigned int i = 0; i < PEEL_NUM_COMBINATIONS; ++i)
867 GLuint texturedDrawMode = 0, flatDrawMode = 0, phongDrawMode = 0, vertexColorDrawMode = 0, gouraudDrawMode = 0;
869 texturedDrawMode = i & PEEL_SHADER_TEXTURED;
870 flatDrawMode = i & PEEL_SHADER_FLAT;
871 phongDrawMode = i & PEEL_SHADER_PHONG;
872 vertexColorDrawMode = i & PEEL_SHADER_VERTEXCOLORS;
873 gouraudDrawMode = i & PEEL_SHADER_GOURAUD;
875 if (i != PEEL_SHADER_WIREFRAME)
878 if (flatDrawMode && phongDrawMode)
continue;
879 if (flatDrawMode && gouraudDrawMode)
continue;
880 if (phongDrawMode && gouraudDrawMode)
continue;
882 if (phongDrawMode + flatDrawMode + gouraudDrawMode == 0)
continue;
895 GLSL::StringList strVertexShader, strFragmentShader, strGeometryShader;
896 generatePeelingShaders(&strVertexShader, &strFragmentShader, &strGeometryShader, texturedDrawMode != 0, flatDrawMode != 0, phongDrawMode != 0, vertexColorDrawMode != 0, i == PEEL_SHADER_WIREFRAME);
904 peelShaders_[i*3 + 0] = pVertexSh;
905 peelProgs_[i]->attach(pVertexSh);
912 peelShaders_[i*3 + 1] = pGeomSh;
913 peelProgs_[i]->attach(pGeomSh);
919 peelShaders_[i*3 + 2] = pFragSh;
920 peelProgs_[i]->attach(pFragSh);
922 peelProgs_[i]->link();
926 #ifdef DEPTHPEELING_SHADER_EXPORT 927 char szFileName[256];
928 sprintf(szFileName,
"peel_vertex_%02u.glsl", i);
929 FILE* pShaderOut = fopen(szFileName,
"wt");
930 for (GLSL::StringList::iterator it = strVertexShader.begin(); it != strVertexShader.end(); ++it)
931 fprintf(pShaderOut, it->c_str());
935 sprintf(szFileName,
"peel_frag%02u.glsl", i);
936 pShaderOut = fopen(szFileName,
"wt");
937 for (GLSL::StringList::iterator it = strFragmentShader.begin(); it != strFragmentShader.end(); ++it)
938 fprintf(pShaderOut, it->c_str());
943 sprintf(szFileName,
"peel_geom%02u.glsl", i);
944 pShaderOut = fopen(szFileName,
"wt");
945 for (GLSL::StringList::iterator it = strGeometryShader.begin(); it != strGeometryShader.end(); ++it)
946 fprintf(pShaderOut, it->c_str());
958 const char* szVertexShader[] = {
961 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;",
964 const char* szFragmentShader[] = {
965 "uniform vec4 ObjectColor;",
966 "uniform sampler2DRect DepthBlenderTex;",
967 "uniform sampler2DRect FrontBlenderTex;",
969 "#define MAX_DEPTH 1.0",
974 " // window-space depth interpolated linearly in screen space",
975 " float fragDepth = gl_FragCoord.z;",
977 " vec2 depthBlender = texture2DRect(DepthBlenderTex, gl_FragCoord.xy).xy;",
978 " vec4 forwardTemp = texture2DRect(FrontBlenderTex, gl_FragCoord.xy);",
980 " // Depths and 1.0-alphaMult always increase",
981 " // so we can use pass-through by default with MAX blending",
982 " gl_FragData[0].xy = depthBlender;",
984 " // Front colors always increase (DST += SRC*ALPHA_MULT)",
985 " // so we can use pass-through by default with MAX blending",
986 " gl_FragData[1] = forwardTemp;",
988 " // Because over blending makes color increase or decrease,",
989 " // we cannot pass-through by default.",
990 " // Each pass, only one fragment writes a color greater than 0",
991 " gl_FragData[2] = vec4(0.0);",
993 " float nearestDepth = -depthBlender.x;",
994 " float farthestDepth = depthBlender.y;",
995 " float alphaMultiplier = 1.0 - forwardTemp.w;",
997 " if (fragDepth < nearestDepth || fragDepth > farthestDepth) {",
998 " // Skip this depth in the peeling algorithm",
999 " gl_FragData[0].xy = vec2(-MAX_DEPTH);",
1003 " if (fragDepth > nearestDepth && fragDepth < farthestDepth) {",
1004 " // This fragment needs to be peeled again",
1005 " gl_FragData[0].xy = vec2(-fragDepth, fragDepth);",
1009 " // If we made it here, this fragment is on the peeled layer from last pass",
1010 " // therefore, we need to shade it, and make sure it is not peeled any farther",
1011 " vec4 color = ObjectColor;",
1012 " gl_FragData[0].xy = vec2(-MAX_DEPTH);",
1014 " if (fragDepth == nearestDepth) {",
1015 " gl_FragData[1].xyz += color.rgb * color.a * alphaMultiplier;",
1016 " gl_FragData[1].w = 1.0 - alphaMultiplier * (1.0 - color.a);",
1018 " gl_FragData[2] += color;",
1022 GLSL::StringList strVertexShader, strFragmentShader;
1023 for (
unsigned int i = 0; i <
sizeof(szVertexShader) /
sizeof(
char*); ++i)
1025 std::string str = szVertexShader[i];
1027 strVertexShader.push_back(str);
1030 for (
unsigned int i = 0; i <
sizeof(szFragmentShader) /
sizeof(
char*); ++i)
1032 std::string str = szFragmentShader[i];
1034 strFragmentShader.push_back(str);
1042 peelShaders_[PEEL_SHADER_HIDDENLINE*3 + 0] = pVertexSh;
1043 peelHiddenLine->
attach(pVertexSh);
1048 peelShaders_[PEEL_SHADER_HIDDENLINE*3 + 2] = pFragSh;
1049 peelHiddenLine->
attach(pFragSh);
1051 peelHiddenLine->
link();
1061 return PEEL_SHADER_WIREFRAME;
1072 if (phong && flat) flat =
false;
1073 if (flat && gouraud) gouraud =
false;
1074 if (gouraud && phong) phong =
false;
1077 if ((!phong) && (!gouraud) && (!flat)) gouraud =
true;
1079 unsigned int idx = 0;
1081 if (flat) idx |= PEEL_SHADER_FLAT;
1082 if (gouraud) idx |= PEEL_SHADER_GOURAUD;
1083 if (phong) idx |= PEEL_SHADER_PHONG;
1084 if (vertexColor) idx |= PEEL_SHADER_VERTEXCOLORS;
1085 if (textured) idx |= PEEL_SHADER_TEXTURED;
1090 QString DepthPeelingPlugin::checkOpenGL() {
1092 return QString(
"Classic depth peeling Rendering-plugin is not compatible with core contexts.");
1094 return QString(
"Insufficient OpenGL Version! OpenGL 2.0 or higher required");
1097 QString missing =
"";
1100 missing +=
"Missing Extension GL_ARB_geometry_shader4\n";
1103 missing +=
"Missing Extension GL_ARB_vertex_program\n";
static void lockProgram()
lock the program
void setSource(const StringList &source)
Upload the source of the shader.
void getLightSource(LightSource *_light) const
Get the light source parameters.
void use()
Enables the program object for using.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Namespace providing different geometric functions concerning angles.
bool compile(bool verbose=true)
Compile the shader object.
static void unlockDepthRange()
unlock depth range
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
void generatePeelingShaders(GLSL::StringList *_strVertexShaderOut, GLSL::StringList *_strFragmentShaderOut, GLSL::StringList *_strGeometryShaderOut, bool _textured, bool _flatShaded, bool _phong, bool _vertexColor, bool _wireFrame)
peel shader generator based on lights and texture mode
Draw node in second pass.
static void unlockProgram()
unlock the program
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
Hide this node and its children.
LightType
light type enumeration
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
bool multipassNodeActive(const unsigned int _i) const
Get Node status to traverse in a specific pass.
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
StatusMode status() const
Get node's status.
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
void setGeometryInputType(GLint _type)
Set Type of Geometry.
void setGeometryVertexCount(GLint _numVerticesOut)
Sets the maximum vertex output of the geometry shader.
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
void attach(PtrConstShader _shader)
Attaches a shader object to the program object.
ChildIter childrenBegin()
Returns: begin-iterator of children.
unsigned int traverseMode() const
Return how the node should be traversed.
static void lockDepthRange()
lock depth range
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
void reset_render_pass()
reset render pass counter
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Structure to hold options for one LightSource.
DrawMode SOLID_TEXTURED
draw textured faces
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
bool openGLVersion(const int _major, const int _minor, bool _verbose)
void drawQuadProj(float _x0=-1.0f, float _y0=1.0f, float _w=2.0f, float _h=2.0f)
draw a quad in projection space (only positions)
int numLights_
Number of Lights.
void next_render_pass()
increment render pass counter
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Execute action on node first and then on its children.
ChildIter childrenEnd()
Returns: end-iterator of children.
DrawMode WIREFRAME
draw wireframe
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Draw this node, but hide children.
bool checkExtensionSupported(const std::string &_extension)
bool directional() const
Check if the light source is a directional light source.
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
void updatePeelingShaderSet()
regenerates peeling shaders based on light nodes in scenegraph
void drawScenePass(ACG::GLState *_glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, BaseNode *_sceneGraphRoot)
draw the current scene
bool multipassStatusActive(const unsigned int _i) const
Get multipass status to traverse in a specific pass.
Execute action the children first and then on this node.
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
Hide this node, but draw children.
unsigned int max_render_passes() const
get maximum number of render passes
DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED
draw smooth shaded and colored faces (requires vertex normals and face colors)
void link()
Links the shader objects to the program.
void traverseLightNodes(BaseNode *_node)
find all light nodes in the scene
void setGeometryOutputType(GLint _type)
Set output type of geometry.
unsigned int getPeelShaderIndex(ACG::SceneGraph::DrawModes::DrawMode _drawMode)
converts a drawmode to the correct shading program index