VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtOsgFileCache.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2016 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 #include <vrvOsg/vrvOsg.h>
13 #include <vrvCore/DtFileCache.h>
14 #include <vrvUtil/signalslib.h>
15 #include <osgDB/ReaderWriter>
16 
17 #include <osgDB/ReaderWriter>
18 #define _WINSOCKAPI_
19 #include <boost/signals2.hpp>
20 
21 namespace osg
22 {
23  class Drawable;
24  class GraphicsContext;
25  class Node;
26  class Texture;
27 }
28 
29 namespace makVrv
30 {
31  class DtMeifConverter;
32  class DtMetaFileManager;
33  class DtOsgShaderManager;
34 
40  {
41  public:
42 
45  friend class DtOsgFileCacheCreator;
46 
48  virtual ~DtOsgFileCache();
49 
51  virtual void releaseResources()
52  {
53  releaseResources(0);
54  }
55 
57  virtual void releaseResources(osg::State* state);
58 
60  virtual void setFromRecord( const makArchives::DtCacheSettingsRecord& rec );
61 
65  static void optimizeNodeGeometry(osg::Node* node);
66 
70  osg::Node* readNodeFile( const std::string& inputFilename,
71  const LoadFileOptions& loadFileOptions);
72 
75  inline osg::ref_ptr<osg::Node> findNodeFile( const std::string& inputFilename )
76  {
77  return ts_findNodeFile(inputFilename);
78  }
79 
83  osg::Image* readImageFile( const std::string& inputFilename,
84  const LoadFileOptions& loadFileOptions);
85 
88  virtual osg::Texture* getTextureInstance(const std::string& filePath,
89  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
90  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
91  const LoadFileOptions& loadFileOptions);
92 
96  virtual void ts_getTextureInstance(const std::string& filePath,
97  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
98  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
99  const LoadFileOptions& loadFileOptions, osg::ref_ptr<osg::Texture>& texture);
100 
102  virtual void encodeOptionsString(const LoadFileOptions& loadFileOptions,
103  osgDB::ReaderWriter::Options& options) const;
104 
106  virtual void decodeOptions(const osgDB::ReaderWriter::Options& options,
107  LoadFileOptions& loadFileOptions) const;
108 
110  DtMetaFileManager* metaFileManager();
111 
116  boost::signals2::signal<void (osg::Node*, const std::string& origFileName,
117  const std::string& actualFileName)> signal_nodeFileLoaded;
118 
123  boost::signals2::signal<void (osg::Image*, const std::string& origFileName,
124  const std::string& actualFileName)> signal_imageFileLoaded;
125 
129  boost::signals2::signal<void (const std::string& filename,
130  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
132 
136  boost::signals2::signal<void (const std::string& filename,
137  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
139 
140  class TextureCollection : public osg::Referenced
141  {
142  public:
143  union KeyType
144  {
145  unsigned short key;
146  struct
147  {
148  unsigned int min : 4;
149  unsigned int max : 4;
150  unsigned int wrap_s : 4;
151  unsigned int wrap_t : 4;
152  };
153  };
154 
155  // \Returns trush if the entire texture collection should be flushed.
156  bool flush()
157  {
158  TextureList replacementList;
159 
160  TextureList::iterator i = myTextures.begin();
161  TextureList::iterator e = myTextures.end();
162  for(;i != e;++i)
163  {
164  if(i->second->referenceCount() > 1)
165  {
166  replacementList.push_back(*i);
167  }
168  }
169  if(replacementList.size() != myTextures.size())
170  {
171  myTextures.swap(replacementList);
172  }
173  return myTextures.size() == 0;
174  }
175 
176  void releaseGLObjects()
177  {
178  TextureList::iterator i = myTextures.begin();
179  TextureList::iterator e = myTextures.end();
180  for(;i != e;++i)
181  {
182  i->second->releaseGLObjects();
183  }
184  }
185 
186  bool findTexture(unsigned int minFilter, unsigned int magFilter,
187  unsigned int wrapS, unsigned wrapT, osg::ref_ptr<osg::Texture>& texture)
188  {
189  KeyType k;
190  k.min = ((minFilter ^ 0x2600) & 0x3) + ((minFilter ^ 0x2600) >> 7);
191  k.max = ((magFilter ^ 0x2600) & 0x3) + ((magFilter ^ 0x2600) >> 7);
192  k.wrap_s = (wrapS & 0x0F) | ((wrapS & 0x10) >> 3);
193  k.wrap_t = (wrapT & 0x0F) | ((wrapT & 0x10) >> 3);
194 
195  TextureList::iterator i = myTextures.begin();
196  TextureList::iterator e = myTextures.end();
197  for(;i != e;++i)
198  {
199  if(i->first.key == k.key)
200  {
201  texture = i->second;
202  return true;
203  }
204  }
205  return false;
206  }
207 
208  void addTexture(osg::Texture* texture)
209  {
210  KeyTexturePair pair;
211 
212  pair.first.min = ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) & 0x3) +
213  ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) >> 7);
214 
215  pair.first.max = ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) & 0x3) +
216  ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) >> 7);
217 
218  pair.first.wrap_s = (texture->getWrap(osg::Texture::WRAP_S) & 0x0F) |
219  ((texture->getWrap(osg::Texture::WRAP_S) & 0x10) >> 3);
220 
221  pair.first.wrap_t = (texture->getWrap(osg::Texture::WRAP_T) & 0x0F) |
222  ((texture->getWrap(osg::Texture::WRAP_T) & 0x10) >> 3);
223  pair.second = texture;
224  myTextures.push_back(pair);
225  }
226 
227  typedef std::pair<KeyType,osg::ref_ptr<osg::Texture> > KeyTexturePair;
228  typedef std::vector<KeyTexturePair> TextureList;
230  };
231 
232  protected:
233 
234  friend class DtReadFileCallback;
235 
237  virtual osg::ref_ptr<osg::Node> ts_readNodeFile( const std::string& inputFilename,
238  const LoadFileOptions& loadFileOptions, const osg::UserDataContainer *optionsUserData);
239 
241  virtual osg::ref_ptr<osg::Node> ts_findNodeFile( const std::string& inputFilename );
242 
244  virtual osg::ref_ptr<osg::Image> ts_readImageFile( const std::string& inputFilename,
245  const LoadFileOptions& loadFileOptions);
246 
248  void ts_encryptImage( const std::string& inputFileName,
249  const std::string& outputFilename, bool printToConsole);
250 
252  bool ts_resolveRelativeFilename( const LoadFileOptions& loadFileOptions,
253  std::string& absoluteInputFilename );
254 
256  virtual void ts_clearInstancingCache();
257 
259  virtual void ts_flushInstancingCache( bool multipass,
260  bool flushNodes, bool flushTextures, bool flushImages);
261 
263  DtOsgFileCache(DtDe& de);
264 
268  std::string ts_buildAcceleratedFilename( const std::string& filePathIn,
269  const std::string& cachedDir,
270  const std::string& cachedExtension) const;
271 
274  virtual bool save(const std::string& origFilename,
275  const std::string& cachedFilename, bool optimize);
276 
278  bool shouldSaveFile( const std::string& filename);
279 
281  bool saveToAcceleratedFile( const std::string& origFileName,
282  osg::Node* nodeRef, const std::string& cachedFilename,
283  bool writeExternalReferences);
284 
286  virtual void addMetaFlightOptions(std::string& optionsString);
287 
289  virtual bool needsShaderGeneration(const std::string& filename, const LoadFileOptions& options) const;
290 
292  virtual void updateGlobalOptions();
293 
295  virtual void slot_onDdsFlipChanged(bool flip);
296 
298  virtual void slot_instancingChanged(bool enabled);
299 
300 
301  protected:
302 
303  typedef boost::unordered_map<std::string,std::string> RelativePathCache;
304 
308 
310  unsigned int myMaxFlushNodeCount;
311  unsigned int myMaxFlushImageCount;
312 
313  boost::mutex myRelativePathMutex;
317 
319  };
320 
324  {
325 
326  public:
327 
329  virtual DtFileCache* create(DtDe& de);
330 
331  };
332 }
333 
334 // Include the inl to solve a circular dependency problem for gcc
335 #include <vrvOsg/DtOsgReferencedCollection.inl>
336 

Document ID: Generated on Mon Jul 4 01:00:18 EDT 2016 from SVN revision 166489
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)