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) 2013 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 
94  virtual void encodeOptionsString(const LoadFileOptions& loadFileOptions,
95  osgDB::ReaderWriter::Options& options) const;
96 
98  virtual void decodeOptions(const osgDB::ReaderWriter::Options& options,
99  LoadFileOptions& loadFileOptions) const;
100 
102  DtMetaFileManager* metaFileManager();
103 
108  boost::signals2::signal<void (osg::Node*, const std::string& origFileName,
109  const std::string& actualFileName)> signal_nodeFileLoaded;
110 
115  boost::signals2::signal<void (osg::Image*, const std::string& origFileName,
116  const std::string& actualFileName)> signal_imageFileLoaded;
117 
121  boost::signals2::signal<void (const std::string& filename,
122  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
124 
128  boost::signals2::signal<void (const std::string& filename,
129  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
131 
132  class TextureCollection : public osg::Referenced
133  {
134  public:
135  union KeyType
136  {
137  unsigned short key;
138  struct
139  {
140  unsigned int min : 4;
141  unsigned int max : 4;
142  unsigned int wrap_s : 4;
143  unsigned int wrap_t : 4;
144  };
145  };
146 
147  // \Returns trush if the entire texture collection should be flushed.
148  bool flush()
149  {
150  TextureList replacementList;
151 
152  TextureList::iterator i = myTextures.begin();
153  TextureList::iterator e = myTextures.end();
154  for(;i != e;++i)
155  {
156  if(i->second->referenceCount() > 1)
157  {
158  replacementList.push_back(*i);
159  }
160  }
161  if(replacementList.size() != myTextures.size())
162  {
163  myTextures.swap(replacementList);
164  }
165  return myTextures.size() == 0;
166  }
167 
168  void releaseGLObjects()
169  {
170  TextureList::iterator i = myTextures.begin();
171  TextureList::iterator e = myTextures.end();
172  for(;i != e;++i)
173  {
174  i->second->releaseGLObjects();
175  }
176  }
177 
178  bool findTexture(unsigned int minFilter, unsigned int magFilter,
179  unsigned int wrapS, unsigned wrapT, osg::ref_ptr<osg::Texture>& texture)
180  {
181  KeyType k;
182  k.min = ((minFilter ^ 0x2600) & 0x3) + ((minFilter ^ 0x2600) >> 7);
183  k.max = ((magFilter ^ 0x2600) & 0x3) + ((magFilter ^ 0x2600) >> 7);
184  k.wrap_s = (wrapS & 0x0F) | ((wrapS & 0x10) >> 3);
185  k.wrap_t = (wrapT & 0x0F) | ((wrapT & 0x10) >> 3);
186 
187  TextureList::iterator i = myTextures.begin();
188  TextureList::iterator e = myTextures.end();
189  for(;i != e;++i)
190  {
191  if(i->first.key == k.key)
192  {
193  texture = i->second;
194  return true;
195  }
196  }
197  return false;
198  }
199 
200  void addTexture(osg::Texture* texture)
201  {
202  KeyTexturePair pair;
203 
204  pair.first.min = ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) & 0x3) +
205  ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) >> 7);
206 
207  pair.first.max = ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) & 0x3) +
208  ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) >> 7);
209 
210  pair.first.wrap_s = (texture->getWrap(osg::Texture::WRAP_S) & 0x0F) |
211  ((texture->getWrap(osg::Texture::WRAP_S) & 0x10) >> 3);
212 
213  pair.first.wrap_t = (texture->getWrap(osg::Texture::WRAP_T) & 0x0F) |
214  ((texture->getWrap(osg::Texture::WRAP_T) & 0x10) >> 3);
215  pair.second = texture;
216  myTextures.push_back(pair);
217  }
218 
219  typedef std::pair<KeyType,osg::ref_ptr<osg::Texture> > KeyTexturePair;
220  typedef std::vector<KeyTexturePair> TextureList;
222  };
223 
224  protected:
225 
226  friend class DtReadFileCallback;
227 
229  virtual osg::ref_ptr<osg::Node> ts_readNodeFile( const std::string& inputFilename,
230  const LoadFileOptions& loadFileOptions);
231 
233  virtual osg::ref_ptr<osg::Node> ts_findNodeFile( const std::string& inputFilename );
234 
236  virtual osg::ref_ptr<osg::Image> ts_readImageFile( const std::string& inputFilename,
237  const LoadFileOptions& loadFileOptions);
238 
240  void ts_encryptImage( const std::string& inputFileName,
241  const std::string& outputFilename, bool printToConsole);
242 
244  bool ts_resolveRelativeFilename( const LoadFileOptions& loadFileOptions,
245  std::string& absoluteInputFilename );
246 
248  virtual void ts_clearInstancingCache();
249 
251  virtual void ts_flushInstancingCache( bool multipass,
252  bool flushNodes, bool flushTextures, bool flushImages);
253 
255  DtOsgFileCache(DtDe& de);
256 
260  std::string ts_buildAcceleratedFilename( const std::string& filePathIn,
261  const std::string& cachedDir,
262  const std::string& cachedExtension) const;
263 
266  virtual bool save(const std::string& origFilename,
267  const std::string& cachedFilename, bool optimize);
268 
270  bool shouldSaveFile( const std::string& filename);
271 
273  bool saveToAcceleratedFile( const std::string& origFileName,
274  osg::Node* nodeRef, const std::string& cachedFilename,
275  bool writeExternalReferences);
276 
278  virtual void addMetaFlightOptions(std::string& optionsString);
279 
281  virtual bool needsShaderGeneration(const std::string& filename, const LoadFileOptions& options) const;
282 
284  virtual void updateGlobalOptions();
285 
287  virtual void slot_onDdsFlipChanged(bool flip);
288 
290  virtual void slot_instancingChanged(bool enabled);
291 
292 
293  protected:
294 
295  typedef boost::unordered_map<std::string,std::string> RelativePathCache;
296 
300 
302  unsigned int myMaxFlushNodeCount;
303  unsigned int myMaxFlushImageCount;
304 
305  boost::mutex myRelativePathMutex;
309 
311  };
312 
316  {
317 
318  public:
319 
321  virtual DtFileCache* create(DtDe& de);
322 
323  };
324 }
325 
326 // Include the inl to solve a circular dependency problem for gcc
327 #include <vrvOsg/DtOsgReferencedCollection.inl>
328 

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)