]> git.tdb.fi Git - libs/gl.git/blobdiff - source/zsortedscene.h
Keep track of which components have been set in Transform
[libs/gl.git] / source / zsortedscene.h
index f9f6f7eed40bd9cfa527540c5417c6fbce3ae75e..cb21061bae301db5f7851c54130112d29e04c011 100644 (file)
@@ -1,7 +1,9 @@
 #ifndef MSP_GL_ZSORTEDSCENE_H_
 #define MSP_GL_ZSORTEDSCENE_H_
 
-#include "simplescene.h"
+#include <set>
+#include <vector>
+#include "scene.h"
 
 namespace Msp {
 namespace GL {
@@ -23,32 +25,48 @@ enum DepthReference
 Sorts renderables by their distance from the camera before rendering.  Requires
 renderables to have a matrix.
 */
-class ZSortedScene: public SimpleScene
+class ZSortedScene: public Scene
 {
 private:
-       struct DepthRenderable
+       struct SortedRenderable
        {
+               Renderable *renderable;
+               bool in_frustum;
                float depth;
-               const Renderable *renderable;
 
-               DepthRenderable(float, const Renderable *);
+               SortedRenderable(Renderable *);
 
-               bool operator<(const DepthRenderable &o) const { return depth<o.depth; }
+               bool operator<(const SortedRenderable &o) const { return depth<o.depth; }
        };
 
+       typedef std::set<Renderable *> RenderableSet;
+       typedef std::vector<SortedRenderable> SortedArray;
+
+       RenderableSet renderables;
        SortOrder order;
        DepthReference reference;
+       mutable SortedArray sorted_cache;
 
 public:
        ZSortedScene();
 
+       virtual void add(Renderable &);
+       virtual void remove(Renderable &);
+
        /// Sets the sort order.  Default is back to front.
        void set_order(SortOrder);
 
        /// Sets the reference point for sorting.  Default is furthest from camera.
        void set_reference(DepthReference);
 
-       virtual void render(Renderer &, const Tag &) const;
+private:
+       void populate_cache() const;
+
+public:
+       virtual void setup_frame(Renderer &);
+       virtual void finish_frame();
+
+       virtual void render(Renderer &, const Tag & = Tag()) const;
 };
 
 } // namespace GL