]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/zsortedscene.h
Use a per-camera cache in ZSortedScene
[libs/gl.git] / source / render / zsortedscene.h
index 6806547235962793fc976d7613d28e49ed516708..be23ac271979be39fda50a9a248847ff195b2bfb 100644 (file)
@@ -10,20 +10,23 @@ namespace GL {
 
 enum SortOrder
 {
-       FRONT_TO_BACK,
-       BACK_TO_FRONT
+       FRONT_TO_BACK = 0,
+       BACK_TO_FRONT = 1
 };
 
 enum DepthReference
 {
-       CLOSEST,
-       CENTER,
-       FURTHEST
+       CLOSEST = 0,
+       CENTER = 1,
+       FURTHEST = 2
 };
 
 /**
-Sorts renderables by their distance from the camera before rendering.  Requires
-renderables to have a matrix.
+A scene which sorts renderables by their distance from the camera before
+rendering.
+
+Renderables must have valid model matrices to be sorted.  Those without a
+matrix are sorted as closest to the camera.
 */
 class ZSortedScene: public Scene
 {
@@ -42,10 +45,10 @@ private:
                bool operator<(const SortedRenderable &o) const { return depth<o.depth; }
        };
 
-       std::set<Renderable *> renderables;
+       std::vector<Renderable *> content;
        SortOrder order = BACK_TO_FRONT;
        DepthReference reference = FURTHEST;
-       mutable std::vector<SortedRenderable> sorted_cache;
+       mutable std::map<const Camera *, std::vector<SortedRenderable> > sorted_cache;
 
 public:
        virtual void add(Renderable &);
@@ -57,10 +60,6 @@ public:
        /// Sets the reference point for sorting.  Default is furthest from camera.
        void set_reference(DepthReference);
 
-private:
-       void populate_cache() const;
-
-public:
        virtual void setup_frame(Renderer &);
        virtual void finish_frame();