From: Mikko Rasa Date: Fri, 1 Oct 2021 16:43:35 +0000 (+0300) Subject: Use QueryPool in OccludedScene X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=93448d16e72e38afbaecbccf6fdedd46d6a82a73;p=libs%2Fgl.git Use QueryPool in OccludedScene --- diff --git a/source/render/occludedscene.cpp b/source/render/occludedscene.cpp index 23d79df2..975510e5 100644 --- a/source/render/occludedscene.cpp +++ b/source/render/occludedscene.cpp @@ -1,6 +1,4 @@ #include -#include -#include #include "camera.h" #include "occludedscene.h" #include "renderer.h" @@ -15,20 +13,12 @@ namespace GL { OccludedScene::OccludedScene(): bounding_mesh(Resources::get_global().get("_occluder.mesh")), bounding_shader(Resources::get_global().get("_occluder.glsl.shader")), + no_depth_write(LEQUAL, false), occluder_min_size(0.25f), + queries(OCCLUSION_QUERY, 0), cache_dirty(false) { - static Require req(ARB_occlusion_query); - static Require req2(ARB_occlusion_query2); -} - -OccludedScene::~OccludedScene() -{ - vector queries; - queries.reserve(occluded_cache.size()); - for(OccludedRenderable &o: occluded_cache) - queries.push_back(o.query); - glDeleteQueries(queries.size(), &queries[0]); + no_color_write.write_mask = WRITE_NONE; } void OccludedScene::add(Renderable &r) @@ -48,15 +38,10 @@ void OccludedScene::populate_cache() const if(!cache_dirty) return; + if(queries.get_size() new_queries(occluded_cache.size()-old_size); - glGenQueries(new_queries.size(), &new_queries[0]); - for(unsigned i=0; iin_frustum); ++i) if(!i->occluder) { - glBeginQuery(GL_ANY_SAMPLES_PASSED, i->query); + QueryPool::Activate activate_query(renderer, queries, i-occluded_cache.begin()); 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_ANY_SAMPLES_PASSED); } - - glColorMask(true, true, true, true); - glDepthMask(true); } // Render anything that has a chance of being visible for(auto i=occluded_cache.begin(); (i!=occluded_cache.end() && i->in_frustum); ++i) - if(!i->occluder) - { - unsigned any_passed = 0; - glGetQueryObjectuiv(i->query, GL_QUERY_RESULT, &any_passed); - if(any_passed) - renderer.render(*i->renderable, tag); - } + if(!i->occluder && queries.get_result(i-occluded_cache.begin())) + renderer.render(*i->renderable, tag); } @@ -178,8 +155,7 @@ OccludedScene::OccludedRenderable::OccludedRenderable(): renderable(0), bounding_sphere(0), in_frustum(false), - occluder(false), - query(0) + occluder(false) { } } // namespace GL diff --git a/source/render/occludedscene.h b/source/render/occludedscene.h index 056acb2e..f11c707e 100644 --- a/source/render/occludedscene.h +++ b/source/render/occludedscene.h @@ -3,8 +3,11 @@ #include #include +#include "blend.h" +#include "depthtest.h" #include "mesh.h" #include "program.h" +#include "query.h" #include "scene.h" namespace Msp { @@ -26,21 +29,22 @@ private: const Geometry::BoundingSphere *bounding_sphere; bool in_frustum; bool occluder; - unsigned query; OccludedRenderable(); }; const Mesh &bounding_mesh; const Program &bounding_shader; + Blend no_color_write; + DepthTest no_depth_write; std::set renderables; float occluder_min_size; + mutable QueryPool queries; mutable std::vector occluded_cache; mutable bool cache_dirty; public: OccludedScene(); - ~OccludedScene(); virtual void add(Renderable &); virtual void remove(Renderable &);