diff --git a/DepthPeeling.cc b/DepthPeeling.cc index 52b1776e9b3caa8622198eace1786e8c0090482b..835740db05ce6226a3fc705877812c90d22d0cc3 100644 --- a/DepthPeeling.cc +++ b/DepthPeeling.cc @@ -132,9 +132,19 @@ public: { _code->push_back("float fragDepth = gl_FragCoord.z;"); +#ifdef __APPLE__ + if(ACG::openGLVersion(3,3)) + { + //on Apple systems with OpenGL 3.3 or higher, ht eGLSL version 330 is used no matter what we write + _code->push_back("vec2 depthLayer = texture(g_DepthLayer, sg_vScreenPos).xy;"); + _code->push_back("vec4 forwardTemp = texture(g_FrontLayer, sg_vScreenPos);"); + } + else +#endif + { _code->push_back("vec2 depthLayer = texture2D(g_DepthLayer, sg_vScreenPos).xy;"); _code->push_back("vec4 forwardTemp = texture2D(g_FrontLayer, sg_vScreenPos);"); - + } _code->push_back("outDepth = vec4(depthLayer, 0, 0);"); _code->push_back("outFragment = forwardTemp;"); _code->push_back("outBackColor = vec4(0,0,0,0);"); @@ -215,23 +225,14 @@ DepthPeeling::~DepthPeeling() QString DepthPeeling::checkOpenGL() { + //if(!ACG::compatibilityProfile()) + // return QString("DepthPeeling render-plugin is nto yet compatible with core profile contexts."); if (!ACG::openGLVersion(3, 2)) - return QString("Insufficient OpenGL Version! OpenGL 3.2 or higher required"); + return QString("Insufficient OpenGL Version! OpenGL 3.2 or higher required"); - QString missing(""); + //no other extensions are necessary, as OpenGL version 3.2 includes them all in the spec - if (!ACG::checkExtensionSupported("GL_ARB_vertex_buffer_object")) - missing += "GL_ARB_vertex_buffer_object extension missing\n"; - -#ifndef __APPLE__ - if (!ACG::checkExtensionSupported("GL_ARB_vertex_program")) - missing += "GL_ARB_vertex_program extension missing\n"; -#endif - - if (!ACG::checkExtensionSupported("GL_ARB_occlusion_query")) - missing += "GL_ARB_occlusion_query extension missing\n"; - - return missing; + return QString(""); } @@ -614,7 +615,8 @@ void DepthPeeling::renderDualPeeling(ACG::GLState* _glState, Viewer::ViewerPrope glEnable(GL_BLEND); glBlendEquation(GL_MAX_EXT); // get min/max depth - glDisable(GL_ALPHA_TEST); + if(_glState->compatibilityProfile()) + glDisable(GL_ALPHA_TEST); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); @@ -918,14 +920,19 @@ void DepthPeeling::ViewerResources::resize(bool _dualPeeling, unsigned int _widt // depth textures: store layer depth as float // front color textures: store (r,g,b,a) colors as R8G8B8A8 // color blending and accumulation texture: (r,g,b,a) color as R8G8B8A8 + GLint wrapmode; + if(ACG::openGLVersion(3,2)) + wrapmode = GL_CLAMP_TO_EDGE; + else + wrapmode = GL_CLAMP; - singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT0, width_, height_, GL_R32F, GL_RGB, GL_CLAMP, GL_NEAREST, GL_NEAREST); - singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT1, width_, height_, GL_RGBA, GL_RGBA, GL_CLAMP, GL_NEAREST, GL_NEAREST); + singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT0, width_, height_, GL_R32F, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST); + singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT1, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST); - singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT2, width_, height_, GL_R32F, GL_RGB, GL_CLAMP, GL_NEAREST, GL_NEAREST); - singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT3, width_, height_, GL_RGBA, GL_RGBA, GL_CLAMP, GL_NEAREST, GL_NEAREST); + singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT2, width_, height_, GL_R32F, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST); + singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT3, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST); - singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT4, width_, height_, GL_RGBA, GL_RGBA, GL_CLAMP, GL_NEAREST, GL_NEAREST); + singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT4, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST); singleFbo_->attachTexture2DDepth(width_, height_); @@ -961,16 +968,22 @@ void DepthPeeling::ViewerResources::resize(bool _dualPeeling, unsigned int _widt // depth textures: store (min,max) depth as float2 // front+back color textures: store (r,g,b,a) colors as R8G8B8A8 // color blending and accumulation texture: (r,g,b) color as R8G8B8X8 - - dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT0, width_, height_, GL_RG32F, GL_RGB, GL_CLAMP, GL_NEAREST, GL_NEAREST); - dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT1, width_, height_, GL_RGBA, GL_RGBA, GL_CLAMP, GL_NEAREST, GL_NEAREST); - dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT2, width_, height_, GL_RGBA, GL_RGBA, GL_CLAMP, GL_NEAREST, GL_NEAREST); + GLint wrapmode; + if(ACG::openGLVersion(3,2)) + { + wrapmode = GL_CLAMP_TO_EDGE; + } + else + wrapmode = GL_CLAMP; + dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT0, width_, height_, GL_RG32F, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST); + dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT1, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST); + dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT2, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST); - dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT3, width_, height_, GL_RG32F, GL_RGB, GL_CLAMP, GL_NEAREST, GL_NEAREST); - dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT4, width_, height_, GL_RGBA, GL_RGBA, GL_CLAMP, GL_NEAREST, GL_NEAREST); - dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT5, width_, height_, GL_RGBA, GL_RGBA, GL_CLAMP, GL_NEAREST, GL_NEAREST); + dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT3, width_, height_, GL_RG32F, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST); + dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT4, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST); + dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT5, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST); - dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT6, width_, height_, GL_RGB, GL_RGB, GL_CLAMP, GL_NEAREST, GL_NEAREST); + dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT6, width_, height_, GL_RGB, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST); dualDepthTex_[0] = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT0); dualDepthTex_[1] = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT3); @@ -1010,11 +1023,24 @@ void DepthPeeling::initDepthPeeling() ShaderProgGenerator::registerModifier(&PeelLayerModifier::instance); // load intermediate blending and final shader +#ifdef __APPLE__ + if(ACG::openGLVersion(3,3)) + { + if (!peelBlend_) + peelBlend_ = GLSL::loadProgram("DepthPeeling/screenquad_330.glsl", "DepthPeeling/blend_330.glsl"); + + if (!peelFinal_) + peelFinal_ = GLSL::loadProgram("DepthPeeling/screenquad_330.glsl", "DepthPeeling/final_330.glsl"); + } + else +#endif + { if (!peelBlend_) peelBlend_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/blend.glsl"); if (!peelFinal_) peelFinal_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/final.glsl"); + } // occ query id if (!peelQueryID_) @@ -1034,11 +1060,22 @@ void DepthPeeling::initDualDepthPeeling() ShaderProgGenerator::registerModifier(&PeelDualLayerModifier::instance); // load intermediate blending and final shader - if (!peelBlendDual_) - peelBlendDual_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/blend_dual.glsl"); - - if (!peelFinalDual_) - peelFinalDual_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/final_dual.glsl"); +#ifdef __APPLE__ //this is fugly, pimpl pattern would be much appreciated + if(ACG::openGLVersion(3,3)) + { + if(!peelBlendDual_) + peelBlendDual_ = GLSL::loadProgram("DepthPeeling/screenquad_330.glsl", "DepthPeeling/blend_dual_330.glsl"); + if (!peelFinalDual_) + peelFinalDual_ = GLSL::loadProgram("DepthPeeling/screenquad_330.glsl", "DepthPeeling/final_dual_330.glsl"); + } + else +#endif + { + if(!peelBlendDual_) + peelBlendDual_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/blend_dual.glsl"); + if (!peelFinalDual_) + peelFinalDual_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/final_dual.glsl"); + } // occ query id if (!peelQueryID_) diff --git a/Shaders/DepthPeeling/blend_330.glsl b/Shaders/DepthPeeling/blend_330.glsl new file mode 100644 index 0000000000000000000000000000000000000000..dfdeeb7ed0858b1db5bd5912870465d2ec00b1cf --- /dev/null +++ b/Shaders/DepthPeeling/blend_330.glsl @@ -0,0 +1,12 @@ +#version 330 + +uniform sampler2D BlendTex; + + +in vec2 vTexCoord; +out vec4 oColor; + +void main() +{ + oColor = texture(BlendTex, vTexCoord); +} \ No newline at end of file diff --git a/Shaders/DepthPeeling/blend_dual_330.glsl b/Shaders/DepthPeeling/blend_dual_330.glsl new file mode 100644 index 0000000000000000000000000000000000000000..ebf37366e9050aee867d139531bd760befdd565c --- /dev/null +++ b/Shaders/DepthPeeling/blend_dual_330.glsl @@ -0,0 +1,14 @@ +#version 330 + +uniform sampler2D BlendTex; + + +in vec2 vTexCoord; +out vec4 oColor; + +void main() +{ + oColor = texture(BlendTex, vTexCoord); + // for occlusion query + if (oColor.a == 0) discard; +} \ No newline at end of file diff --git a/Shaders/DepthPeeling/final_330.glsl b/Shaders/DepthPeeling/final_330.glsl new file mode 100644 index 0000000000000000000000000000000000000000..7f1ff888cbf6c25718b62daf0ed18d5d0135332f --- /dev/null +++ b/Shaders/DepthPeeling/final_330.glsl @@ -0,0 +1,13 @@ +#version 330 + +uniform sampler2D SceneTex; +uniform vec3 BkgColor; + +in vec2 vTexCoord; +out vec4 oColor; + +void main() +{ + vec4 c = texture(SceneTex, vTexCoord); + oColor = vec4(c.rgb + BkgColor * c.a, 1.0); +} \ No newline at end of file diff --git a/Shaders/DepthPeeling/final_dual_330.glsl b/Shaders/DepthPeeling/final_dual_330.glsl new file mode 100644 index 0000000000000000000000000000000000000000..e9eb32693d93da66f9e479e9fc3536facb04a44c --- /dev/null +++ b/Shaders/DepthPeeling/final_dual_330.glsl @@ -0,0 +1,16 @@ +#version 330 + +uniform sampler2D FrontSceneTex; +uniform sampler2D BackSceneTex; + +in vec2 vTexCoord; +out vec4 oColor; + +void main() +{ + vec4 cf = texture(FrontSceneTex, vTexCoord); + vec4 cb = texture(BackSceneTex, vTexCoord); + + // combine front and back color + oColor = vec4(cf.rgb + cb.rbg * (1.0 - cf.a), 1.0); +} \ No newline at end of file diff --git a/Shaders/DepthPeeling/screenquad_330.glsl b/Shaders/DepthPeeling/screenquad_330.glsl new file mode 100644 index 0000000000000000000000000000000000000000..aec17d21175b3277d1f977701ee81e7d3e2886b0 --- /dev/null +++ b/Shaders/DepthPeeling/screenquad_330.glsl @@ -0,0 +1,10 @@ +#version 330 + +in vec4 inPosition; +out vec2 vTexCoord; + +void main() +{ + gl_Position = inPosition; + vTexCoord = inPosition.xy * 0.5 + vec2(0.5, 0.5); +} \ No newline at end of file