X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Fzsortedscene.cpp;h=25255dc693569a9d34b2adfc7b64f709089af63e;hb=282a10854eda602d874e200c8301cf57d6501e81;hp=7b64fb2b478387b448eac09acd32e9e418af31f2;hpb=e9a898f315b5d1396f196d785913a283c30940f2;p=libs%2Fgl.git diff --git a/source/render/zsortedscene.cpp b/source/render/zsortedscene.cpp index 7b64fb2b..25255dc6 100644 --- a/source/render/zsortedscene.cpp +++ b/source/render/zsortedscene.cpp @@ -1,3 +1,4 @@ +#include #include "camera.h" #include "renderer.h" #include "zsortedscene.h" @@ -7,21 +8,25 @@ using namespace std; namespace Msp { namespace GL { -ZSortedScene::ZSortedScene(): - order(BACK_TO_FRONT), - reference(FURTHEST) -{ } - void ZSortedScene::add(Renderable &r) { - if(renderables.insert(&r).second && !sorted_cache.empty()) - sorted_cache.push_back(&r); + auto i = lower_bound(content, &r); + if(i==content.end() || *i!=&r) + { + content.insert(i, &r); + if(!sorted_cache.empty()) + sorted_cache.push_back(&r); + } } void ZSortedScene::remove(Renderable &r) { - renderables.erase(&r); - sorted_cache.clear(); + auto i = lower_bound(content, &r); + if(i!=content.end() && *i==&r) + { + content.erase(i); + sorted_cache.clear(); + } } void ZSortedScene::set_order(SortOrder o) @@ -36,10 +41,10 @@ void ZSortedScene::set_reference(DepthReference r) void ZSortedScene::populate_cache() const { - if(sorted_cache.empty() && !renderables.empty()) + if(sorted_cache.empty() && !content.empty()) { - sorted_cache.reserve(renderables.size()); - sorted_cache.insert(sorted_cache.end(), renderables.begin(), renderables.end()); + sorted_cache.reserve(content.size()); + sorted_cache.insert(sorted_cache.end(), content.begin(), content.end()); } } @@ -58,7 +63,7 @@ void ZSortedScene::finish_frame() void ZSortedScene::render(Renderer &renderer, Tag tag) const { - if(renderables.empty()) + if(content.empty()) return; populate_cache(); @@ -67,7 +72,7 @@ void ZSortedScene::render(Renderer &renderer, Tag tag) const if(!camera) { for(const SortedRenderable &r: sorted_cache) - renderer.render(*r.renderable, tag); + r.renderable->render(renderer, tag); return; } @@ -118,7 +123,7 @@ void ZSortedScene::render(Renderer &renderer, Tag tag) const } for(auto i=sorted_cache.begin(); (i!=sorted_cache.end() && i->in_frustum); ++i) - renderer.render(*i->renderable, tag); + i->renderable->render(renderer, tag); }