VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgReferencedCollection.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2021 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <osg/ref_ptr>
13 #include <osg/Texture>
14 #include <boost/unordered_set.hpp>
15 #include <boost/unordered_map.hpp>
16 #include <boost/thread.hpp>
17 #include <string>
18 
19 namespace osg
20 {
21  class State;
22 }
23 
24 namespace makVrv
25 {
29  template <typename OsgObject>
31  {
32  public:
33 
34  typedef boost::unordered_map<std::string,osg::ref_ptr<OsgObject> >
36  typedef std::vector<std::pair<std::string,OsgObject*> > ReferenceList;
37 
39  DtOsgReferencedCollection(unsigned int initialCapacity);
40 
44  inline void lock() { myMutex.lock(); }
45 
49 
52  inline InstanceMap& getUnsafeMap() { return myInstanceMap; }
53 
55  unsigned int unsafeListSize() const;
56 
58  inline void unlock() { myMutex.unlock(); }
59 
66  bool findOrBlockWhilePending(const std::string& name, osg::ref_ptr<OsgObject>& object );
67 
69  osg::ref_ptr<OsgObject> find(const std::string& filename);
70 
73  void insert(const std::string& name,const osg::ref_ptr<OsgObject>& obj);
74 
76  void releaseGLObjects(osg::State* state);
77 
79  void clear();
80 
81 
85  bool findOrAddTexture(const std::string& filename,
86  osg::Texture::FilterMode minFilter,osg::Texture::FilterMode magFilter,
87  osg::Texture::WrapMode s, osg::Texture::WrapMode t, osg::ref_ptr<osg::Texture>& texture,
88  bool unloadImageDataFlag, bool compressTexturesFlag, const std::string& alternateFilename = "");
89 
92  bool findTexture(const std::string& filename,
93  osg::Texture::FilterMode minFilter,osg::Texture::FilterMode magFilter,
94  osg::Texture::WrapMode s, osg::Texture::WrapMode t, bool compressedTexturesFlag, osg::ref_ptr<osg::Texture>& texture);
95 
98  void addTexture(const std::string& filename,
99  osg::ref_ptr<osg::Texture> texture, bool unloadImageDataFlag, bool compressTexturesFlag, std::string alternateFilename = "");
100 
101 
104  unsigned int flush();
105 
108  unsigned int partialFlush(unsigned int maxToCheck,unsigned int maxToFlush);
109 
112  unsigned int flushTextures();
113 
116  unsigned int partialFlushTextures(unsigned int maxToCheck,unsigned int maxToFlush);
117 
118 
119  protected:
120 
122  {
123  const std::string& myStr;
124  FindReference(const std::string& str) : myStr(str){}
125  bool operator()(const std::pair<std::string,OsgObject*>& ref)
126  {
127  return ref.first == myStr;
128  }
129  };
130 
131  typedef boost::unordered_set<std::string> PendingSet;
132  boost::mutex myMutex;
133  //use this condition variable to wait for the instance that is pending to be loaded
134  boost::condition_variable myPendingInstanceDone;
139  unsigned int myPartialFlushIndex;
140  };
141 
142 }
143 
bool findOrBlockWhilePending(const std::string &name, osg::ref_ptr< OsgObject > &object)
Find an object with a given name or save the name as pending. This function will block if the object ...
ReferenceList myRefInstanceList
Definition: DtOsgReferencedCollection.h:136
const std::string & myStr
Definition: DtOsgReferencedCollection.h:123
boost::unordered_set< std::string > PendingSet
Definition: DtOsgReferencedCollection.h:131
Definition: featureContext.h:37
osg::ref_ptr< OsgObject > find(const std::string &filename)
Look for an object and return a value (null or not).
boost::mutex myMutex
Definition: DtOsgReferencedCollection.h:132
bool findTexture(const std::string &filename, osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, osg::Texture::WrapMode s, osg::Texture::WrapMode t, bool compressedTexturesFlag, osg::ref_ptr< osg::Texture > &texture)
Find a texture with the given image name.
unsigned int flush()
Do a partial flush of items.
bool findOrAddTexture(const std::string &filename, osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, osg::Texture::WrapMode s, osg::Texture::WrapMode t, osg::ref_ptr< osg::Texture > &texture, bool unloadImageDataFlag, bool compressTexturesFlag, const std::string &alternateFilename="")
Find a texture with the given image name. If it is not found the texture input is added to the cache ...
std::vector< std::pair< std::string, OsgObject * > > ReferenceList
Definition: DtOsgReferencedCollection.h:36
DtOsgReferencedCollection(unsigned int initialCapacity)
Constructor.
void lock()
Lock the collection.
Definition: DtOsgReferencedCollection.h:44
A thread safe collection, used by the mult-threaded cache, of OSG referenced objects.
Definition: DtOsgReferencedCollection.h:30
unsigned int myPartialFlushIndex
Definition: DtOsgReferencedCollection.h:139
void releaseGLObjects(osg::State *state)
Release GL objects on all objects in the cache.
PendingSet myPendingInstances
Definition: DtOsgReferencedCollection.h:137
PendingSet myFailedInstances
Definition: DtOsgReferencedCollection.h:138
Definition: DtOsgReferencedCollection.h:121
void unlock()
Unlock the collection.
Definition: DtOsgReferencedCollection.h:58
void addTexture(const std::string &filename, osg::ref_ptr< osg::Texture > texture, bool unloadImageDataFlag, bool compressTexturesFlag, std::string alternateFilename="")
add a texture for the given image name. also processes the texture to put on a callback for handling ...
unsigned int flushTextures()
Do a flush of all textures.
InstanceMap myInstanceMap
Definition: DtOsgReferencedCollection.h:135
FindReference(const std::string &str)
Definition: DtOsgReferencedCollection.h:124
boost::unordered_map< std::string, osg::ref_ptr< OsgObject > > InstanceMap
Definition: DtOsgReferencedCollection.h:35
InstanceMap & getUnsafeMap()
Get the unsafe map, to make this safe you MUST lock the collection first.
Definition: DtOsgReferencedCollection.h:52
unsigned int unsafeListSize() const
returns size of collection
boost::condition_variable myPendingInstanceDone
Definition: DtOsgReferencedCollection.h:134
void clear()
Clears all of the instances.
bool operator()(const std::pair< std::string, OsgObject * > &ref)
Definition: DtOsgReferencedCollection.h:125
unsigned int partialFlushTextures(unsigned int maxToCheck, unsigned int maxToFlush)
Do a partial flush of items.
void insert(const std::string &name, const osg::ref_ptr< OsgObject > &obj)
Insert an instance into the cache Needs to be called if an object is pending (pass 0 to remove from p...
unsigned int partialFlush(unsigned int maxToCheck, unsigned int maxToFlush)
Do a partial flush of items.
ReferenceList & getUnsafeList()
Get the unsafe list, to make this safe you MUST lock the collection first.
Definition: DtOsgReferencedCollection.h:48

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)