]> git.tdb.fi Git - libs/gl.git/commitdiff
Adjust OccludedScene to be more compatible with OpenGL ES
authorMikko Rasa <tdb@tdb.fi>
Sun, 10 Jan 2016 16:45:06 +0000 (18:45 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 10 Jan 2016 16:45:06 +0000 (18:45 +0200)
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 [new file with mode: 0644]
source/occludedscene.cpp

diff --git a/extensions/arb_occlusion_query2.glext b/extensions/arb_occlusion_query2.glext
new file mode 100644 (file)
index 0000000..74c4d6b
--- /dev/null
@@ -0,0 +1 @@
+extension ARB_occlusion_query2
index 8d05f7c18161d8af7833fd1f62cae4f9effc21ad..3d540a72ac8739e6b780ff7e7cc19845104741fc 100644 (file)
@@ -1,38 +1,25 @@
 #include <algorithm>
 #include <msp/gl/extensions/arb_occlusion_query.h>
+#include <msp/gl/extensions/arb_occlusion_query2.h>
 #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);
                }
 }