15 #include <osgDB/ReaderWriter>
17 #include <boost/unordered_map.hpp>
18 #include <boost/unordered_set.hpp>
19 #include <osgDB/ReaderWriter>
21 #include <boost/thread/mutex.hpp>
22 #include <boost/signals2.hpp>
27 class GraphicsContext;
34 class DtMeifConverter;
35 class DtMetaFileManager;
36 class DtOsgShaderManager;
54 virtual void releaseResources()
60 virtual void releaseResources(osg::State* state);
68 static void optimizeNodeGeometry(osg::Node* node);
73 osg::Node* readNodeFile(
const std::string& inputFilename,
74 const LoadFileOptions& loadFileOptions);
78 inline osg::ref_ptr<osg::Node> findNodeFile(
const std::string& inputFilename )
80 return ts_findNodeFile(inputFilename);
86 osg::Image* readImageFile(
const std::string& inputFilename,
87 const LoadFileOptions& loadFileOptions);
91 virtual osg::Texture* getTextureInstance(
const std::string& filePath,
92 osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
93 osg::Texture::WrapMode s, osg::Texture::WrapMode t,
94 const LoadFileOptions& loadFileOptions);
97 virtual void encodeOptionsString(
const LoadFileOptions& loadFileOptions,
98 osgDB::ReaderWriter::Options& options)
const;
101 virtual void decodeOptions(
const osgDB::ReaderWriter::Options& options,
102 LoadFileOptions& loadFileOptions)
const;
111 boost::signals2::signal<void (osg::Node*,
const std::string& origFileName,
118 boost::signals2::signal<void (osg::Image*,
const std::string& origFileName,
124 boost::signals2::signal<void (
const std::string& filename,
125 osgDB::ReaderWriter::ReadResult&,
const osgDB::ReaderWriter::Options*)>
131 boost::signals2::signal<void (
const std::string& filename,
132 osgDB::ReaderWriter::ReadResult&,
const osgDB::ReaderWriter::Options*)>
143 unsigned int min : 4;
144 unsigned int max : 4;
145 unsigned int wrap_s : 4;
146 unsigned int wrap_t : 4;
155 TextureList::iterator i = myTextures.begin();
156 TextureList::iterator e = myTextures.end();
159 if(i->second->referenceCount() > 1)
161 replacementList.push_back(*i);
164 if(replacementList.size() != myTextures.size())
166 myTextures.swap(replacementList);
168 return myTextures.size() == 0;
171 void releaseGLObjects()
173 TextureList::iterator i = myTextures.begin();
174 TextureList::iterator e = myTextures.end();
177 i->second->releaseGLObjects();
181 bool findTexture(
unsigned int minFilter,
unsigned int magFilter,
182 unsigned int wrapS,
unsigned wrapT, osg::ref_ptr<osg::Texture>& texture)
185 k.
min = ((minFilter ^ 0x2600) & 0x3) + ((minFilter ^ 0x2600) >> 7);
186 k.
max = ((magFilter ^ 0x2600) & 0x3) + ((magFilter ^ 0x2600) >> 7);
187 k.
wrap_s = (wrapS & 0x0F) | ((wrapS & 0x10) >> 3);
188 k.
wrap_t = (wrapT & 0x0F) | ((wrapT & 0x10) >> 3);
190 TextureList::iterator i = myTextures.begin();
191 TextureList::iterator e = myTextures.end();
194 if(i->first.key == k.
key)
207 pair.first.min = ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) & 0x3) +
208 ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) >> 7);
210 pair.first.max = ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) & 0x3) +
211 ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) >> 7);
213 pair.first.wrap_s = (texture->getWrap(osg::Texture::WRAP_S) & 0x0F) |
214 ((texture->getWrap(osg::Texture::WRAP_S) & 0x10) >> 3);
216 pair.first.wrap_t = (texture->getWrap(osg::Texture::WRAP_T) & 0x0F) |
217 ((texture->getWrap(osg::Texture::WRAP_T) & 0x10) >> 3);
218 pair.second = texture;
219 myTextures.push_back(pair);
229 friend class DtReadFileCallback;
232 virtual osg::ref_ptr<osg::Node> ts_readNodeFile(
const std::string& inputFilename,
236 virtual osg::ref_ptr<osg::Node> ts_findNodeFile(
const std::string& inputFilename );
239 virtual osg::ref_ptr<osg::Image> ts_readImageFile(
const std::string& inputFilename,
243 void ts_encryptImage(
const std::string& inputFileName,
244 const std::string& outputFilename,
bool printToConsole);
247 bool ts_resolveRelativeFilename(
const LoadFileOptions& loadFileOptions,
248 std::string& absoluteInputFilename );
251 virtual void ts_clearInstancingCache();
254 virtual void ts_flushInstancingCache(
bool multipass,
255 bool flushNodes,
bool flushTextures,
bool flushImages);
263 std::string ts_buildAcceleratedFilename(
const std::string& filePathIn,
264 const std::string& cachedDir,
265 const std::string& cachedExtension)
const;
269 virtual bool save(
const std::string& origFilename,
270 const std::string& cachedFilename,
bool optimize);
273 bool shouldSaveFile(
const std::string& filename);
276 bool saveToAcceleratedFile(
const std::string& origFileName,
277 osg::Node* nodeRef,
const std::string& cachedFilename,
278 bool writeExternalReferences);
281 virtual void addMetaFlightOptions(std::string& optionsString);
284 virtual bool needsShaderGeneration(
const std::string& filename,
const LoadFileOptions& options)
const;
287 virtual void updateGlobalOptions();
290 virtual void slot_onDdsFlipChanged(
bool flip);
293 virtual void slot_instancingChanged(
bool enabled);
330 #include <vrvOsg/DtOsgReferencedCollection.inl>