]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/Effect.hxx
Merge branch 'zan/stencil'
[simgear.git] / simgear / scene / material / Effect.hxx
index c3436c432f6eb2453b377206f17556ed4cf143e8..1f33b9e86d61209f7a0b1f6cb5c4a08b7aa64446 100644 (file)
@@ -19,6 +19,9 @@
 
 #include <vector>
 #include <string>
+#include <boost/tr1/unordered_map.hpp>
+
+#include <boost/functional/hash.hpp>
 
 #include <osg/Object>
 #include <osgDB/ReaderWriter>
@@ -104,11 +107,50 @@ public:
     {
         void doUpdate(osg::Node* node, osg::NodeVisitor* nv);
     };
-    
 protected:
     std::vector<SGSharedPtr<Updater> > _extraData;
     ~Effect();
+    // Support for a cache of effects that inherit from this one, so
+    // Effect objects with the same parameters and techniques can be
+    // shared.
+    struct Key
+    {
+        Key() {}
+        Key(SGPropertyNode* unmerged_, const osgDB::FilePathList& paths_)
+            : unmerged(unmerged_), paths(paths_)
+        {
+        }
+        Key& operator=(const Key& rhs)
+        {
+            unmerged = rhs.unmerged;
+            paths = rhs.paths;
+            return *this;
+        }
+        SGPropertyNode_ptr unmerged;
+        osgDB::FilePathList paths;
+        struct EqualTo
+        {
+            bool operator()(const Key& lhs, const Key& rhs) const;
+        };
+    };
+    typedef std::tr1::unordered_map<Key, osg::ref_ptr<Effect>,
+                                    boost::hash<Key>, Key::EqualTo> Cache;
+    Cache* getCache()
+    {
+        if (!_cache)
+            _cache = new Cache;
+        return _cache;
+    }
+    Cache* _cache;
+    friend size_t hash_value(const Key& key);
+    friend Effect* makeEffect(SGPropertyNode* prop, bool realizeTechniques,
+                              const osgDB::ReaderWriter::Options* options);
+    bool _isRealized;
 };
+// Automatic support for boost hash function
+size_t hash_value(const Effect::Key&);
+
+
 Effect* makeEffect(const std::string& name,
                    bool realizeTechniques,
                    const osgDB::ReaderWriter::Options* options = 0);