From 6a135773515b020ea3f163a11d06150ae5c0e69f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 27 Feb 2008 14:09:02 +0000 Subject: [PATCH] Allow Renderables in a Scene to specify ordering --- source/renderable.h | 1 + source/scene.cpp | 10 +++++++++- source/scene.h | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/renderable.h b/source/renderable.h index 00b8b901..aeee1666 100644 --- a/source/renderable.h +++ b/source/renderable.h @@ -17,6 +17,7 @@ namespace GL { class Renderable { public: + virtual int get_order() const { return 0; } virtual bool has_pass(const Tag &tag) const =0; virtual void render(const Tag &tag=Tag()) const =0; diff --git a/source/scene.cpp b/source/scene.cpp index 20399daf..607166d5 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -24,10 +24,18 @@ void Scene::remove(const Renderable &r) void Scene::render(const Tag &tag) const { - for(set::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) + for(set::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) if((*i)->has_pass(tag)) (*i)->render(tag); } + +bool Scene::Compare::operator()(const Renderable *a, const Renderable *b) const +{ + if(a->get_order()!=b->get_order()) + return a->get_order()get_order(); + return a renderables; + struct Compare + { + bool operator()(const Renderable *, const Renderable *) const; + }; + + std::set renderables; public: void add(const Renderable &); -- 2.45.2