VR-Forces Developer's Guide
 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) 2023 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 
28 #include <tbb/spin_rw_mutex.h>
29 
30 #include <atomic>
31 #include <unordered_map>
32 
33 namespace osg
34 {
35  class Drawable;
36  class GraphicsContext;
37  class Node;
38  class Texture;
39  class Object;
40 }
41 
42 namespace makVrv
43 {
44  class DtMeifConverter;
45  class DtMetaFileManager;
46  class DtOsgShaderManager;
47  class DtOsgShaderFilesCache;
48  class DtEffectControllerFactory;
49  class DtReadFileCallback;
50  class DtModelDefinition;
51 
57  {
58  public:
59 
62  friend class DtOsgFileCacheCreator;
63 
65  virtual ~DtOsgFileCache();
66 
69  virtual void initSingletonDependencies();
70 
72  virtual void releaseResources()
73  {
74  releaseResources(0);
75  }
76 
78  virtual void releaseResources(osg::State* state);
79 
81  virtual void setFromRecord( const makArchives::DtCacheSettingsRecord& rec );
82 
86  static void optimizeNodeGeometry(osg::Node* node);
87 
91  osg::Node* readNodeFile( const std::string& inputFilename,
92  const LoadFileOptions& loadFileOptions);
93 
96  inline osg::ref_ptr<osg::Node> findNodeFile( const std::string& inputFilename )
97  {
98  return ts_findNodeFile(inputFilename);
99  }
100 
104  osg::Image* readImageFile( const std::string& inputFilename,
105  const LoadFileOptions& loadFileOptions);
106 
109  virtual osg::Texture* getTextureInstance(const std::string& filePath,
110  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
111  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
112  const LoadFileOptions& loadFileOptions);
113 
117  virtual void ts_getTextureInstance(const std::string& filePath,
118  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
119  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
120  const LoadFileOptions& loadFileOptions, osg::ref_ptr<osg::Texture>& texture);
121 
126  virtual bool getOrLoadTexture( DtTextureInterface* textureWrapper, const std::string& filename,
127  const DtFileCache::LoadFileOptions& loadFileOptions ) override;
128 
130  virtual void runMergeDuplicateTextureVisitor(osg::Node& node);
131 
133  virtual void encodeOptionsString(const LoadFileOptions& loadFileOptions,
134  osgDB::ReaderWriter::Options& options) const;
135 
137  virtual void decodeOptions(const osgDB::ReaderWriter::Options& options,
138  LoadFileOptions& loadFileOptions) const;
139 
141  DtMetaFileManager* metaFileManager();
142 
146  void cleanDataFilePathList(FilePathList& fileList);
147 
152  boost::signalslib::signal<void (osg::Node*, const std::string& origFileName,
153  const std::string& actualFileName)> signal_nodeFileLoaded;
154 
159  boost::signalslib::signal<void (osg::Image*, const std::string& origFileName,
160  const std::string& actualFileName)> signal_imageFileLoaded;
161 
166  boost::signalslib::signal<void(osg::Object*, const std::string& origFileName,
167  const std::string& actualFileName)> signal_objectFileLoaded;
168 
172  boost::signalslib::signal<void (const std::string& filename,
173  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
175 
179  boost::signalslib::signal<void (const std::string& filename,
180  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
182 
186  boost::signalslib::signal<void(const std::string& filename,
187  osgDB::ReaderWriter::ReadResult&, const osgDB::ReaderWriter::Options*)>
189 
191  virtual const DtOsgShaderFilesCache& shaderFilesCache(void) const;
192 
196  virtual const std::string& loadShaderSource(const std::string& shaderFile) const;
197 
200  virtual std::string ts_getTextureFilePathAndSetNameIfNotSet(const osg::Texture* baseTexture) const;
201 
203  virtual void ts_setEffectTextureName(osg::ref_ptr<osg::Texture>& effectTexture, const std::string& validFile) const;
204 
206  virtual void ts_setEffectTextureFilterAndHardwareMipMapGen(osg::Texture* effectTexture, osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, bool hardwareMipMapGen) const;
207 
209  virtual void ts_compareAndSwapIgnoreHint(osg::Texture* effectTexture, bool oldVal, bool newVal) const;
210 
215  virtual bool ts_checkAndSetIgnoreHint(osg::Object* obj, bool val, const char* hint) const;
216 
219  virtual bool ts_ignore(osg::Object* obj, const char* hint) const;
220 
222  virtual const DtEffectControllerShaderCache& effectControllerShaderCache(void) const;
223 
225  virtual void setNumActivePagerThreads(int active);
226 
228  virtual int numActivePagerThreads() const;
229 
231  virtual int numImageProcessingTasks() const;
232 
234  virtual void setNumDiguyWorkerThreads(int num);
235 
238  virtual void incrementNumSleepingPagerThreads();
239 
241  virtual void decrementNumSleepingPagerThreads();
242 
244  virtual DtOsgShaderManager& shaderManager(void);
245 
247  virtual const DtOsgShaderManager& shaderManager(void) const;
248 
250  virtual void ts_flushInstancingCache(bool multipass,
251  bool flushNodes, bool flushTextures, bool flushImages);
252 
254  virtual int numNodes() const;
255 
257  virtual int numTextures() const;
258 
260  virtual int numImages() const;
261  protected:
262 
263  friend class DtReadFileCallback;
264 
266  virtual osg::ref_ptr<osg::Node> ts_readNodeFile( const std::string& inputFilename,
267  const LoadFileOptions& loadFileOptions, const osg::UserDataContainer *optionsUserData);
268 
270  virtual osg::ref_ptr<osg::Node> ts_readCdbNodeFile(const std::string& inputFilename,
271  const LoadFileOptions& loadFileOptions, const osg::UserDataContainer *optionsUserData);
272 
274  virtual osg::ref_ptr<osg::Node> ts_findNodeFile( const std::string& inputFilename );
275 
277  virtual osg::ref_ptr<osg::Image> ts_readImageFile( const std::string& inputFilename,
278  const LoadFileOptions& loadFileOptions,
279  const osg::UserDataContainer* optionsUserData =0L);
280 
282  virtual osg::ref_ptr<osg::Image> ts_readCdbImageFile(const std::string& inputFilename,
283  const LoadFileOptions& loadFileOptions,
284  const osg::UserDataContainer* optionsUserData = 0L);
285 
287  virtual osg::ref_ptr<osg::Object> ts_readObject(
288  const std::string& filename, const osgDB::ReaderWriter::Options* options);
289 
291  void ts_encryptImage( const std::string& inputFileName,
292  const std::string& outputFilename, const osgDB::ReaderWriter::Options* options, bool printToConsole);
293 
295  bool ts_resolveRelativeFilename( const LoadFileOptions& loadFileOptions,
296  std::string& absoluteInputFilename );
297 
299  virtual void ts_clearInstancingCache();
300 
301 
303  virtual void applyEffectTexture(osg::Node* node, const std::string& extension,
304  bool isCdb, osgDB::ReaderWriter::Options* option);
305 
307  DtOsgFileCache(DtDe& de);
308 
311  virtual bool save(const std::string& origFilename,
312  const std::string& cachedFilename, bool optimize);
313 
315  bool saveToAcceleratedFile( const std::string& origFileName,
316  osg::Node* nodeRef, const std::string& cachedFilename,
317  bool writeExternalReferences);
318 
320  virtual void addMetaFlightOptions(std::string& optionsString);
321 
323  virtual bool needsShaderGeneration(const std::string& extension, const LoadFileOptions& options) const;
324 
326  virtual void updateGlobalOptions();
327 
329  virtual void slot_onDdsFlipChanged(bool flip);
330 
332  virtual void slot_instancingChanged(bool enabled);
333 
334  // check if an attrData object is in the cache (only for FLT and CDB)
335  virtual bool getAttrFromLocalCache(const std::string& filename, osg::Object** attrData);
336 
338  virtual void writeCacheFile(osg::ref_ptr<osg::Node> node, const std::string& acceleratedFileLocation, DtCVMarkerSeries& series);
339 
341  virtual void shadersGeneration(osg::ref_ptr<osg::Node> node, const std::string& fileToLoad);
342 
345  virtual void squishImage(const std::string& fileToLoad, const std::string& acceleratedFilename, DtCVMarkerSeries& objectCreation,
346  osg::ref_ptr<osg::Image> image, bool writeAcceleratedFile, bool isCDB);
347 
352  virtual void saveImageFilename(const std::string& absoluteInputFilename, osg::Image* image);
353 
355  virtual osg::ref_ptr<osg::Image> getCachedImage(const std::string& cacheKey, const std::string& inputExtension, const LoadFileOptions& loadFileOptions);
356 
357  protected:
358 
359  typedef std::unordered_map<std::string,std::string> RelativePathCache;
360 
364  typedef std::map< std::string, osg::ref_ptr<osg::Object> > AttrCacheMap;
366 
367  tbb::spin_rw_mutex myRelativePathMutex;
371 
375 
376  // effect controller shader cache
378 
381 
382  // determines threading behavior
384  std::atomic<int> myNumSleepingPagerThreads;
385  std::atomic<int> myNumDiguyWorkerThreads;
386 
387  // CDB specific driver
388  osgDB::ReaderWriter* myFltDriver;
389  osgDB::ReaderWriter* myFltCdbDriver;
390  osgDB::ReaderWriter* myMedfDriver;
391  // CDB specific driver
392  osgDB::ReaderWriter* myRgbDriver;
393  osgDB::ReaderWriter* myMeifDriver;
394  osgDB::ReaderWriter* myCDBZipDriver;
395  };
396 
400  {
401 
402  public:
403 
405  virtual DtFileCache* create(DtDe& de);
406 
407  };
408 }
409 
410 // Include the inl to solve a circular dependency problem for gcc
411 #include <vrvOsg/DtOsgReferencedCollection.inl>
412 
tbb::spin_rw_mutex myRelativePathMutex
Definition: DtOsgFileCache.h:367
RelativePathCache myRelativePathCache
Definition: DtOsgFileCache.h:368
Contains makVrv::DtTextureCollection class.
virtual void releaseResources()
Release all rendering resources.
Definition: DtOsgFileCache.h:72
std::map< std::string, osg::ref_ptr< osg::Object > > AttrCacheMap
Definition: DtOsgFileCache.h:364
#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:365
DtOsgReferencedCollection< osg::Node > myNodeCollection
Definition: DtOsgFileCache.h:361
Creates a series/span line in the CV tool.
Definition: DtConcurrencyViewerMacros.h:27
The abstract creator for the abstract DtFileCache class.
Definition: DtFileCache.h:266
brief DtEffectControllerShaderCache is a cache for shaders used by effect texture controller ...
Definition: DtEffectControllerShaderCache.h:26
Interface for a texture. Used to pass in a texture to vrvGraphics.
Definition: DtTextureInterface.h:24
osg::ref_ptr< osg::Node > findNodeFile(const std::string &inputFilename)
Find a node file. If the file was already cached then a copy will be returned.
Definition: DtOsgFileCache.h:96
class for holding loader shader files, so that they are not repeatedly loaded from disk ...
Definition: DtOsgShaderFilesCache.h:27
boost::signalslib::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readObjectCallback
Signaled emitted when osg calls readObject. This signal is emitted every time read object is called r...
Definition: DtOsgFileCache.h:188
The DtOsgFileCache creator..
Definition: DtOsgFileCache.h:399
boost::signalslib::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readNodeCallback
Signaled emitted when osg calls readNodeFile. This signal is emitted every time read image is called ...
Definition: DtOsgFileCache.h:174
Handles the set up and processing of .meta files. Meta files contain extra information about nodes in...
Definition: DtMetaFileManager.h:36
int myNumActivePagerThreads
Definition: DtOsgFileCache.h:383
std::atomic< int > myNumDiguyWorkerThreads
Definition: DtOsgFileCache.h:385
Contains makVrv::DtFileCache class.
The OSG implementation of makVrv::DtOsgFileCache. This will cache files as .ive&#39;s for quicker load ti...
Definition: DtOsgFileCache.h:56
DtOsgReferencedCollection< osg::Image > myImageCollection
Definition: DtOsgFileCache.h:363
boost::signalslib::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readImageCallback
Signaled emitted when osg calls readImageFile. This signal is emitted every time read image is called...
Definition: DtOsgFileCache.h:181
std::atomic< int > myNumSleepingPagerThreads
Definition: DtOsgFileCache.h:384
osgDB::ReaderWriter * myFltCdbDriver
Definition: DtOsgFileCache.h:389
osgDB::ReaderWriter * myFltDriver
Definition: DtOsgFileCache.h:388
Contains the DtEffectControllerShaderCache class declaration.
DtOsgShaderManager & myShaderManager
Definition: DtOsgFileCache.h:372
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))
boost::signalslib::signal< void(osg::Node *, const std::string &origFileName, const std::string &actualFileName)> signal_nodeFileLoaded
Signal emitted whenever a Node file is loaded from disk. When instancing is enabled then each file wi...
Definition: DtOsgFileCache.h:153
DtOsgShaderFilesCache & myShaderFilesCache
Definition: DtOsgFileCache.h:373
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
DtEffectControllerShaderCache myEffectControllerShaderCache
Definition: DtOsgFileCache.h:377
DtMetaFileManager * myMetaFileManager
Definition: DtOsgFileCache.h:370
Definition: DtFileCache.h:45
osg::ref_ptr< DtReadFileCallback > myReadFileCallback
Definition: DtOsgFileCache.h:379
DtOsgShaderManager injects custom shaders into the scenes, and keeps their uniform parameters set to ...
Definition: DtOsgShaderManager.h:41
Record for the settings associated with the VRV caching.
Definition: DtCacheSettingsRecord.h:17
Definition: DtReadFileCallback.h:22
DtEffectControllerFactory & myEffectControllerFactory
Definition: DtOsgFileCache.h:374
boost::signalslib::signal< void(osg::Image *, const std::string &origFileName, const std::string &actualFileName)> signal_imageFileLoaded
Signal emitted whenever an image file is loaded from disk. When instancing is enabled then each file ...
Definition: DtOsgFileCache.h:160
The scene object creators are registered with the scene object factory for accessing DtSceneObjectCre...
Definition: DtEffectControllerFactory.h:31
DtMeifConverter * myImageCompressor
Definition: DtOsgFileCache.h:369
osgDB::ReaderWriter * myMedfDriver
Definition: DtOsgFileCache.h:390
Contains DLL export macros.
osgDB::ReaderWriter * myRgbDriver
Definition: DtOsgFileCache.h:392
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
boost::signalslib::signal< void(osg::Object *, const std::string &origFileName, const std::string &actualFileName)> signal_objectFileLoaded
Signal emitted whenever an object file is loaded from disk. When instancing is enabled then each file...
Definition: DtOsgFileCache.h:167
osgDB::ReaderWriter * myMeifDriver
Definition: DtOsgFileCache.h:393
Contains makVrv::DtOsgReferencedCollection class.
Contains the DtCVMarkerSeries and DtCVMarkerSeries class declarations responsible for wrapping up to ...
Handles the caching of files. Includes functions for excluding files with certain extensions from bei...
Definition: DtFileCache.h:37
DtOsgReferencedCollection< DtTextureCollection > myTextureCollection
Definition: DtOsgFileCache.h:362
DtSignalConnectionManager myConnections
Definition: DtOsgFileCache.h:380
osgDB::ReaderWriter * myCDBZipDriver
Definition: DtOsgFileCache.h:394
Contains the DtEffectControllerContainer class.
std::unordered_map< std::string, std::string > RelativePathCache
Definition: DtOsgFileCache.h:359

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)