VR-Forces 4.5 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) 2017 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  class DtOsgShaderFilesCache;
35  class DtEffectControllerFactory;
36 
42  {
43  public:
44 
47  friend class DtOsgFileCacheCreator;
48 
50  virtual ~DtOsgFileCache();
51 
53  virtual void releaseResources()
54  {
55  releaseResources(0);
56  }
57 
59  virtual void releaseResources(osg::State* state);
60 
62  virtual void setFromRecord( const makArchives::DtCacheSettingsRecord& rec );
63 
67  static void optimizeNodeGeometry(osg::Node* node);
68 
72  osg::Node* readNodeFile( const std::string& inputFilename,
73  const LoadFileOptions& loadFileOptions);
74 
77  inline osg::ref_ptr<osg::Node> findNodeFile( const std::string& inputFilename )
78  {
79  return ts_findNodeFile(inputFilename);
80  }
81 
85  osg::Image* readImageFile( const std::string& inputFilename,
86  const LoadFileOptions& loadFileOptions);
87 
90  virtual osg::Texture* getTextureInstance(const std::string& filePath,
91  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
92  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
93  const LoadFileOptions& loadFileOptions);
94 
98  virtual void ts_getTextureInstance(const std::string& filePath,
99  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
100  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
101  const LoadFileOptions& loadFileOptions, osg::ref_ptr<osg::Texture>& texture);
102 
104  virtual void encodeOptionsString(const LoadFileOptions& loadFileOptions,
105  osgDB::ReaderWriter::Options& options) const;
106 
108  virtual void decodeOptions(const osgDB::ReaderWriter::Options& options,
109  LoadFileOptions& loadFileOptions) const;
110 
112  DtMetaFileManager* metaFileManager();
113 
118  boost::signals2::signal<void (osg::Node*, const std::string& origFileName,
119  const std::string& actualFileName)> signal_nodeFileLoaded;
120 
125  boost::signals2::signal<void (osg::Image*, const std::string& origFileName,
126  const std::string& actualFileName)> signal_imageFileLoaded;
127 
131  boost::signals2::signal<void (const std::string& filename,
132  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
134 
138  boost::signals2::signal<void (const std::string& filename,
139  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
141 
142  class TextureCollection : public osg::Referenced
143  {
144  public:
145  union KeyType
146  {
147  unsigned short key;
148  struct
149  {
150  unsigned int min : 4;
151  unsigned int max : 4;
152  unsigned int wrap_s : 4;
153  unsigned int wrap_t : 4;
154  };
155  };
156 
157  // \Returns trush if the entire texture collection should be flushed.
158  bool flush()
159  {
160  TextureList replacementList;
161 
162  TextureList::iterator i = myTextures.begin();
163  TextureList::iterator e = myTextures.end();
164  for(;i != e;++i)
165  {
166  if(i->second->referenceCount() > 1)
167  {
168  replacementList.push_back(*i);
169  }
170  }
171  if(replacementList.size() != myTextures.size())
172  {
173  myTextures.swap(replacementList);
174  }
175  return myTextures.size() == 0;
176  }
177 
178  void releaseGLObjects()
179  {
180  TextureList::iterator i = myTextures.begin();
181  TextureList::iterator e = myTextures.end();
182  for(;i != e;++i)
183  {
184  i->second->releaseGLObjects();
185  }
186  }
187 
188  bool findTexture(unsigned int minFilter, unsigned int magFilter,
189  unsigned int wrapS, unsigned wrapT, osg::ref_ptr<osg::Texture>& texture)
190  {
191  KeyType k;
192  k.min = ((minFilter ^ 0x2600) & 0x3) + ((minFilter ^ 0x2600) >> 7);
193  k.max = ((magFilter ^ 0x2600) & 0x3) + ((magFilter ^ 0x2600) >> 7);
194  k.wrap_s = (wrapS & 0x0F) | ((wrapS & 0x10) >> 3);
195  k.wrap_t = (wrapT & 0x0F) | ((wrapT & 0x10) >> 3);
196 
197  TextureList::iterator i = myTextures.begin();
198  TextureList::iterator e = myTextures.end();
199  for(;i != e;++i)
200  {
201  if(i->first.key == k.key)
202  {
203  texture = i->second;
204  return true;
205  }
206  }
207  return false;
208  }
209 
210  void addTexture(osg::Texture* texture)
211  {
212  KeyTexturePair pair;
213 
214  pair.first.min = ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) & 0x3) +
215  ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) >> 7);
216 
217  pair.first.max = ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) & 0x3) +
218  ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) >> 7);
219 
220  pair.first.wrap_s = (texture->getWrap(osg::Texture::WRAP_S) & 0x0F) |
221  ((texture->getWrap(osg::Texture::WRAP_S) & 0x10) >> 3);
222 
223  pair.first.wrap_t = (texture->getWrap(osg::Texture::WRAP_T) & 0x0F) |
224  ((texture->getWrap(osg::Texture::WRAP_T) & 0x10) >> 3);
225  pair.second = texture;
226  myTextures.push_back(pair);
227  }
228 
229  typedef std::pair<KeyType,osg::ref_ptr<osg::Texture> > KeyTexturePair;
230  typedef std::vector<KeyTexturePair> TextureList;
232  };
233 
234 
235  const DtOsgShaderManager& shaderManager(void) const
236  {
237  return myShaderManager;
238  }
239 
240  DtOsgShaderManager& shaderManager(void)
241  {
242  return myShaderManager;
243  }
244 
245  const DtOsgShaderFilesCache& shaderFilesCache(void) const
246  {
247  return myShaderFilesCache;
248  }
249 
250  DtEffectControllerFactory& effectControllerFactory(void) const
251  {
252  return myEffectControllerFactory;
253  }
254 
255  protected:
256 
257  friend class DtReadFileCallback;
258 
260  virtual osg::ref_ptr<osg::Node> ts_readNodeFile( const std::string& inputFilename,
261  const LoadFileOptions& loadFileOptions, const osg::UserDataContainer *optionsUserData);
262 
264  virtual osg::ref_ptr<osg::Node> ts_findNodeFile( const std::string& inputFilename );
265 
267  virtual osg::ref_ptr<osg::Image> ts_readImageFile( const std::string& inputFilename,
268  const LoadFileOptions& loadFileOptions,
269  const osg::UserDataContainer* optionsUserData =0L);
270 
272  void ts_encryptImage( const std::string& inputFileName,
273  const std::string& outputFilename, const osgDB::ReaderWriter::Options* options, bool printToConsole);
274 
276  bool ts_resolveRelativeFilename( const LoadFileOptions& loadFileOptions,
277  std::string& absoluteInputFilename );
278 
280  virtual void ts_clearInstancingCache();
281 
283  virtual void ts_flushInstancingCache( bool multipass,
284  bool flushNodes, bool flushTextures, bool flushImages);
285 
287  DtOsgFileCache(DtDe& de);
288 
292  std::string ts_buildAcceleratedFilename( const std::string& filePathIn,
293  const std::string& cachedDir,
294  const std::string& cachedExtension) const;
295 
298  virtual bool save(const std::string& origFilename,
299  const std::string& cachedFilename, bool optimize);
300 
302  bool shouldSaveFile( const std::string& filename);
303 
305  bool saveToAcceleratedFile( const std::string& origFileName,
306  osg::Node* nodeRef, const std::string& cachedFilename,
307  bool writeExternalReferences);
308 
310  virtual void addMetaFlightOptions(std::string& optionsString);
311 
313  virtual bool needsShaderGeneration(const std::string& filename, const LoadFileOptions& options) const;
314 
316  virtual void updateGlobalOptions();
317 
319  virtual void slot_onDdsFlipChanged(bool flip);
320 
322  virtual void slot_instancingChanged(bool enabled);
323 
324  protected:
325 
326  typedef boost::unordered_map<std::string,std::string> RelativePathCache;
327 
331 
333  unsigned int myMaxFlushNodeCount;
334  unsigned int myMaxFlushImageCount;
335 
336  boost::mutex myRelativePathMutex;
340 
344 
345  //mutex for protecting against setUserValue threading issues.
346  boost::mutex myImageUserValueMutex;
347  };
348 
352  {
353 
354  public:
355 
357  virtual DtFileCache* create(DtDe& de);
358 
359  };
360 }
361 
362 // Include the inl to solve a circular dependency problem for gcc
363 #include <vrvOsg/DtOsgReferencedCollection.inl>
364 

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)