VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgFileCache.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
18 
19 #include <vrvCore/DtFileCache.h>
20 
22 #include <vrvUtil/signalslib.h>
23 
24 #include <osgDB/ReaderWriter>
25 
26 #define _WINSOCKAPI_
27 #include <boost/signals2.hpp>
28 
29 #include <tbb/atomic.h>
30 #include <tbb/spin_rw_mutex.h>
31 
32 namespace osg
33 {
34  class Drawable;
35  class GraphicsContext;
36  class Node;
37  class Texture;
38  class Object;
39 }
40 
41 namespace makVrv
42 {
43  class DtMeifConverter;
44  class DtMetaFileManager;
45  class DtOsgShaderManager;
46  class DtOsgShaderFilesCache;
47  class DtEffectControllerFactory;
48  class DtReadFileCallback;
49  class DtModelDefinition;
50 
56  {
57  public:
58 
61  friend class DtOsgFileCacheCreator;
62 
64  virtual ~DtOsgFileCache();
65 
68  virtual void initSingletonDependencies();
69 
71  virtual void releaseResources()
72  {
73  releaseResources(0);
74  }
75 
77  virtual void releaseResources(osg::State* state);
78 
80  virtual void setFromRecord( const makArchives::DtCacheSettingsRecord& rec );
81 
85  static void optimizeNodeGeometry(osg::Node* node);
86 
90  osg::Node* readNodeFile( const std::string& inputFilename,
91  const LoadFileOptions& loadFileOptions);
92 
95  inline osg::ref_ptr<osg::Node> findNodeFile( const std::string& inputFilename )
96  {
97  return ts_findNodeFile(inputFilename);
98  }
99 
103  osg::Image* readImageFile( const std::string& inputFilename,
104  const LoadFileOptions& loadFileOptions);
105 
108  virtual osg::Texture* getTextureInstance(const std::string& filePath,
109  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
110  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
111  const LoadFileOptions& loadFileOptions);
112 
116  virtual void ts_getTextureInstance(const std::string& filePath,
117  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
118  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
119  const LoadFileOptions& loadFileOptions, osg::ref_ptr<osg::Texture>& texture);
120 
122  virtual void runMergeDuplicateTextureVisitor(osg::Node& node);
123 
125  virtual void encodeOptionsString(const LoadFileOptions& loadFileOptions,
126  osgDB::ReaderWriter::Options& options) const;
127 
129  virtual void decodeOptions(const osgDB::ReaderWriter::Options& options,
130  LoadFileOptions& loadFileOptions) const;
131 
133  DtMetaFileManager* metaFileManager();
134 
138  void cleanDataFilePathList(FilePathList& fileList);
139 
144  boost::signals2::signal<void (osg::Node*, const std::string& origFileName,
145  const std::string& actualFileName)> signal_nodeFileLoaded;
146 
151  boost::signals2::signal<void (osg::Image*, const std::string& origFileName,
152  const std::string& actualFileName)> signal_imageFileLoaded;
153 
158  boost::signals2::signal<void(osg::Object*, const std::string& origFileName,
159  const std::string& actualFileName)> signal_objectFileLoaded;
160 
164  boost::signals2::signal<void (const std::string& filename,
165  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
167 
171  boost::signals2::signal<void (const std::string& filename,
172  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
174 
178  boost::signals2::signal<void(const std::string& filename,
179  osgDB::ReaderWriter::ReadResult&, const osgDB::ReaderWriter::Options*)>
181 
183  virtual const DtOsgShaderFilesCache& shaderFilesCache(void) const;
184 
188  virtual const std::string& loadShaderSource(const std::string& shaderFile) const;
189 
192  virtual std::string ts_getTextureFilePathAndSetNameIfNotSet(const osg::Texture* baseTexture) const;
193 
195  virtual void ts_setEffectTextureName(osg::ref_ptr<osg::Texture>& effectTexture, const std::string& validFile) const;
196 
198  virtual void ts_setEffectTextureFilterAndHardwareMipMapGen(osg::Texture* effectTexture, osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, bool hardwareMipMapGen) const;
199 
201  virtual void ts_compareAndSwapIgnoreHint(osg::Texture* effectTexture, bool oldVal, bool newVal) const;
202 
207  virtual bool ts_checkAndSetIgnoreHint(osg::Object* obj, bool val, const char* hint) const;
208 
211  virtual bool ts_ignore(osg::Object* obj, const char* hint) const;
212 
214  virtual const DtEffectControllerShaderCache& effectControllerShaderCache(void) const;
215 
217  virtual void setNumActivePagerThreads(int active);
218 
220  virtual int numActivePagerThreads();
221 
223  virtual int numImageProcessingTasks() const;
224 
226  virtual void setNumDiguyWorkerThreads(int num);
227 
230  virtual void incrementNumSleepingPagerThreads();
231 
233  virtual void decrementNumSleepingPagerThreads();
234 
236  virtual DtOsgShaderManager& shaderManager(void);
237 
239  virtual const DtOsgShaderManager& shaderManager(void) const;
240 
242  virtual void ts_flushInstancingCache(bool multipass,
243  bool flushNodes, bool flushTextures, bool flushImages);
244 
245  protected:
246 
247  friend class DtReadFileCallback;
248 
250  virtual osg::ref_ptr<osg::Node> ts_readNodeFile( const std::string& inputFilename,
251  const LoadFileOptions& loadFileOptions, const osg::UserDataContainer *optionsUserData);
252 
254  virtual osg::ref_ptr<osg::Node> ts_readCdbNodeFile(const std::string& inputFilename,
255  const LoadFileOptions& loadFileOptions, const osg::UserDataContainer *optionsUserData);
256 
258  virtual osg::ref_ptr<osg::Node> ts_findNodeFile( const std::string& inputFilename );
259 
261  virtual osg::ref_ptr<osg::Image> ts_readImageFile( const std::string& inputFilename,
262  const LoadFileOptions& loadFileOptions,
263  const osg::UserDataContainer* optionsUserData =0L);
264 
266  virtual osg::ref_ptr<osg::Image> ts_readCdbImageFile(const std::string& inputFilename,
267  const LoadFileOptions& loadFileOptions,
268  const osg::UserDataContainer* optionsUserData = 0L);
269 
271  virtual osg::ref_ptr<osg::Object> ts_readObject(
272  const std::string& filename, const osgDB::ReaderWriter::Options* options);
273 
275  void ts_encryptImage( const std::string& inputFileName,
276  const std::string& outputFilename, const osgDB::ReaderWriter::Options* options, bool printToConsole);
277 
279  bool ts_resolveRelativeFilename( const LoadFileOptions& loadFileOptions,
280  std::string& absoluteInputFilename );
281 
283  virtual void ts_clearInstancingCache();
284 
285 
287  virtual void applyEffectTexture(osg::Node* node, const std::string& extension,
288  bool isCdb, osgDB::ReaderWriter::Options* option);
289 
291  DtOsgFileCache(DtDe& de);
292 
295  virtual bool save(const std::string& origFilename,
296  const std::string& cachedFilename, bool optimize);
297 
299  bool saveToAcceleratedFile( const std::string& origFileName,
300  osg::Node* nodeRef, const std::string& cachedFilename,
301  bool writeExternalReferences);
302 
304  virtual void addMetaFlightOptions(std::string& optionsString);
305 
307  virtual bool needsShaderGeneration(const std::string& extension, const LoadFileOptions& options) const;
308 
310  virtual void updateGlobalOptions();
311 
313  virtual void slot_onDdsFlipChanged(bool flip);
314 
316  virtual void slot_instancingChanged(bool enabled);
317 
318  // check if an attrData object is in the cache (only for FLT and CDB)
319  virtual bool getAttrFromLocalCache(const std::string& filename, osg::Object** attrData);
320 
322  virtual void writeCacheFile(osg::ref_ptr<osg::Node> node, const std::string& acceleratedFileLocation, DtCVMarkerSeries& series);
323 
325  virtual void shadersGeneration(osg::ref_ptr<osg::Node> node, const std::string& fileToLoad);
326 
329  virtual void squishImage(const std::string& fileToLoad, const std::string& acceleratedFilename, DtCVMarkerSeries& objectCreation,
330  osg::ref_ptr<osg::Image> image, bool writeAcceleratedFile, bool isCDB);
331 
336  virtual void saveImageFilename(const std::string& absoluteInputFilename, osg::Image* image);
337 
339  virtual osg::ref_ptr<osg::Image> isImageAlreadyInCache(const std::string& cacheKey, const std::string& inputExtension, const LoadFileOptions& loadFileOptions);
340 
341  protected:
342 
343  typedef boost::unordered_map<std::string,std::string> RelativePathCache;
344 
348  typedef std::map< std::string, osg::ref_ptr<osg::Object> > AttrCacheMap;
350 
352  unsigned int myMaxFlushNodeCount;
353  unsigned int myMaxFlushImageCount;
354 
355  tbb::spin_rw_mutex myRelativePathMutex;
359 
363 
364  // effect controller shader cache
366 
368 
369  // determines threading behavior
371  tbb::atomic<int> myNumSleepingPagerThreads;
372  tbb::atomic<int> myNumDiguyWorkerThreads;
373  };
374 
378  {
379 
380  public:
381 
383  virtual DtFileCache* create(DtDe& de);
384 
385  };
386 }
387 
388 // Include the inl to solve a circular dependency problem for gcc
389 #include <vrvOsg/DtOsgReferencedCollection.inl>
390 
Diagonal crossing liens.
Definition: DtTacticalGraphicUtilities.h:93
tbb::spin_rw_mutex myRelativePathMutex
Definition: DtOsgFileCache.h:355
RelativePathCache myRelativePathCache
Definition: DtOsgFileCache.h:356
Contains makVrv::DtTextureCollection class.
virtual void releaseResources()
Release all rendering resources.
Definition: DtOsgFileCache.h:71
std::map< std::string, osg::ref_ptr< osg::Object > > AttrCacheMap
Definition: DtOsgFileCache.h:348
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Class responsible for converting images into MAK encrypted image files.
Definition: DtMeifConverter.h:25
AttrCacheMap myAttrCacheMap
Definition: DtOsgFileCache.h:349
DtOsgReferencedCollection< osg::Node > myNodeCollection
Definition: DtOsgFileCache.h:345
Creates a series/span line in the CV tool.
Definition: DtConcurrencyViewerMacros.h:27
The abstract creator for the abstract DtFileCache class.
Definition: DtFileCache.h:272
boost::signals2::signal< void(osg::Object *, const std::string &origFileName, const std::string &actualFileName)> signal_objectFileLoaded
Signal emitted whenever an object file is loaded from disk.
Definition: DtOsgFileCache.h:159
tbb::atomic< int > myNumDiguyWorkerThreads
Definition: DtOsgFileCache.h:372
brief DtEffectControllerShaderCache is a cache for shaders used by effect texture controller ...
Definition: DtEffectControllerShaderCache.h:26
unsigned int myMaxFlushImageCount
Definition: DtOsgFileCache.h:353
osg::ref_ptr< osg::Node > findNodeFile(const std::string &inputFilename)
Find a node file.
Definition: DtOsgFileCache.h:95
Definition: DtOsgShaderFilesCache.h:22
The DtOsgFileCache creator.
Definition: DtOsgFileCache.h:377
boost::signals2::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readObjectCallback
Signaled emitted when osg calls readObject.
Definition: DtOsgFileCache.h:180
Handles the set up and processing of .meta files.
Definition: DtMetaFileManager.h:36
int myNumActivePagerThreads
Definition: DtOsgFileCache.h:370
Contains makVrv::DtFileCache class.
The OSG implementation of makVrv::DtOsgFileCache.
Definition: DtOsgFileCache.h:55
DtOsgReferencedCollection< osg::Image > myImageCollection
Definition: DtOsgFileCache.h:347
boost::unordered_map< std::string, std::string > RelativePathCache
Definition: DtOsgFileCache.h:343
Contains the DtEffectControllerShaderCache class declaration.
DtOsgShaderManager & myShaderManager
Definition: DtOsgFileCache.h:360
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2 &size, const ImVec2 &uv0=ImVec2(0, 0), const ImVec2 &uv1=ImVec2(1, 1), const ImVec4 &tint_col=ImVec4(1, 1, 1, 1), const ImVec4 &border_col=ImVec4(0, 0, 0, 0))
DtOsgShaderFilesCache & myShaderFilesCache
Definition: DtOsgFileCache.h:361
boost::signals2::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readImageCallback
Signaled emitted when osg calls readImageFile.
Definition: DtOsgFileCache.h:173
DtEffectControllerShaderCache myEffectControllerShaderCache
Definition: DtOsgFileCache.h:365
DtMetaFileManager * myMetaFileManager
Definition: DtOsgFileCache.h:358
Definition: DtFileCache.h:60
tbb::atomic< int > myNumSleepingPagerThreads
Definition: DtOsgFileCache.h:371
boost::signals2::signal< void(osg::Image *, const std::string &origFileName, const std::string &actualFileName)> signal_imageFileLoaded
Signal emitted whenever an image file is loaded from disk.
Definition: DtOsgFileCache.h:152
osg::ref_ptr< DtReadFileCallback > myReadFileCallback
Definition: DtOsgFileCache.h:367
DtOsgShaderManager injects custom shaders into the scenes, and keeps their uniform parameters set to ...
Definition: DtOsgShaderManager.h:55
Record for the settings associated with the VRV caching.
Definition: DtCacheSettingsRecord.h:20
Definition: DtReadFileCallback.h:21
DtEffectControllerFactory & myEffectControllerFactory
Definition: DtOsgFileCache.h:362
The scene object creators are registered with the scene object factory for accessing DtSceneObjectCre...
Definition: DtEffectControllerFactory.h:31
DtMeifConverter * myImageCompressor
Definition: DtOsgFileCache.h:357
Contains DLL export macros.
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
Contains makVrv::DtOsgReferencedCollection class.
unsigned int myMaxFlushTextureCount
Definition: DtOsgFileCache.h:351
Contains the DtCVMarkerSeries and DtCVMarkerSeries class declarations responsible for wrapping up to ...
unsigned int myMaxFlushNodeCount
Definition: DtOsgFileCache.h:352
Handles the caching of files.
Definition: DtFileCache.h:52
DtOsgReferencedCollection< DtTextureCollection > myTextureCollection
Definition: DtOsgFileCache.h:346
boost::signals2::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readNodeCallback
Signaled emitted when osg calls readNodeFile.
Definition: DtOsgFileCache.h:166
Contains the DtEffectControllerContainer class.
boost::signals2::signal< void(osg::Node *, const std::string &origFileName, const std::string &actualFileName)> signal_nodeFileLoaded
Signal emitted whenever a Node file is loaded from disk.
Definition: DtOsgFileCache.h:145

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)