From 782344299d402dfc7e4eb038bba876d7455f50f5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 10 Jan 2016 18:45:06 +0200 Subject: [PATCH] Adjust OccludedScene to be more compatible with OpenGL ES GL_SAMPLES_PASSED is not available in OpenGL ES so use occlusion_query2 for GL_ANY_SAMPLES_PASSED. In theory it's possible for an implementation to support occlusion_query but not the 2 variant; I'll deal with that case if I ever come across such a combination of hardware and drivers. --- extensions/arb_occlusion_query2.glext | 1 + source/occludedscene.cpp | 31 ++++++++------------------- 2 files changed, 10 insertions(+), 22 deletions(-) create mode 100644 extensions/arb_occlusion_query2.glext diff --git a/extensions/arb_occlusion_query2.glext b/extensions/arb_occlusion_query2.glext new file mode 100644 index 00000000..74c4d6b5 --- /dev/null +++ b/extensions/arb_occlusion_query2.glext @@ -0,0 +1 @@ +extension ARB_occlusion_query2 diff --git a/source/occludedscene.cpp b/source/occludedscene.cpp index 8d05f7c1..3d540a72 100644 --- a/source/occludedscene.cpp +++ b/source/occludedscene.cpp @@ -1,38 +1,25 @@ #include #include +#include #include "camera.h" #include "occludedscene.h" +#include "programbuilder.h" #include "renderer.h" #include "sphere.h" using namespace std; -namespace { - -const char vshader[] = - "void main()\n" - "{\n" - " gl_Position = gl_ProjectionMatrix*gl_ModelViewMatrix*gl_Vertex;\n" - "}"; - -const char fshader[] = - "void main()\n" - "{\n" - " gl_FragColor = vec4(1.0);\n" - "}"; - -} - namespace Msp { namespace GL { OccludedScene::OccludedScene(): bounding_mesh((VERTEX3, NORMAL3)), - bounding_shader(vshader, fshader), + bounding_shader(ProgramBuilder::StandardFeatures()), occluder_min_size(0.25f), cache_dirty(false) { static Require req(ARB_occlusion_query); + static Require req2(ARB_occlusion_query2); /* Use a slightly larger radius to ensure that all parts of the renderable fit inside the icosahedron */ @@ -149,13 +136,13 @@ void OccludedScene::render(Renderer &renderer, const Tag &tag) const for(OccludedArray::const_iterator i=occluded_cache.begin(); (i!=occluded_cache.end() && i->in_frustum); ++i) if(!i->occluder) { - glBeginQuery(GL_SAMPLES_PASSED, i->query); + glBeginQuery(GL_ANY_SAMPLES_PASSED, i->query); Renderer::Push push2(renderer); renderer.transform(Matrix(*i->renderable->get_matrix()) .translate(i->bounding_sphere->get_center()) .scale(i->bounding_sphere->get_radius())); bounding_mesh.draw(renderer); - glEndQuery(GL_SAMPLES_PASSED); + glEndQuery(GL_ANY_SAMPLES_PASSED); } glColorMask(true, true, true, true); @@ -166,9 +153,9 @@ void OccludedScene::render(Renderer &renderer, const Tag &tag) const for(OccludedArray::const_iterator i=occluded_cache.begin(); (i!=occluded_cache.end() && i->in_frustum); ++i) if(!i->occluder) { - int samples_passed; - glGetQueryObjectiv(i->query, GL_QUERY_RESULT, &samples_passed); - if(samples_passed>0) + unsigned any_passed = 0; + glGetQueryObjectuiv(i->query, GL_QUERY_RESULT, &any_passed); + if(any_passed) renderer.render(*i->renderable, tag); } } -- 2.43.0