1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4     (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #include "OgreStableHeaders.h"
29 
30 #include "OgreStringVector.h"
31 #include "OgreLogManager.h"
32 #include "OgreArchiveManager.h"
33 #include "OgreArchive.h"
34 #include "OgreStringConverter.h"
35 
36 #include "OgreException.h"
37 #include "OgreRenderSystemCapabilitiesManager.h"
38 #include "OgreRenderSystemCapabilitiesSerializer.h"
39 
40 
41 
42 namespace Ogre {
43 
44     //-----------------------------------------------------------------------
45     template<> RenderSystemCapabilitiesManager* Singleton<RenderSystemCapabilitiesManager>::msSingleton = 0;
getSingletonPtr(void)46     RenderSystemCapabilitiesManager* RenderSystemCapabilitiesManager::getSingletonPtr(void)
47     {
48         return msSingleton;
49     }
getSingleton(void)50     RenderSystemCapabilitiesManager& RenderSystemCapabilitiesManager::getSingleton(void)
51     {
52         assert( msSingleton );  return ( *msSingleton );
53     }
54 
55     //-----------------------------------------------------------------------
RenderSystemCapabilitiesManager()56     RenderSystemCapabilitiesManager::RenderSystemCapabilitiesManager() : mSerializer(0), mScriptPattern("*.rendercaps")
57     {
58         mSerializer = OGRE_NEW RenderSystemCapabilitiesSerializer();
59     }
60     //-----------------------------------------------------------------------
~RenderSystemCapabilitiesManager()61     RenderSystemCapabilitiesManager::~RenderSystemCapabilitiesManager()
62     {
63         for (CapabilitiesMap::iterator it = mCapabilitiesMap.begin(), end = mCapabilitiesMap.end(); it != end; ++it)
64         {
65         // free memory in RenderSystemCapabilities*
66             OGRE_DELETE it->second;
67         }
68 
69         OGRE_DELETE mSerializer;
70     }
71 
72     //-----------------------------------------------------------------------
parseCapabilitiesFromArchive(const String & filename,const String & archiveType,bool recursive)73     void RenderSystemCapabilitiesManager::parseCapabilitiesFromArchive(const String& filename, const String& archiveType, bool recursive)
74     {
75         // get the list of .rendercaps files
76         Archive* arch = ArchiveManager::getSingleton().load(filename, archiveType, true);
77         StringVectorPtr files = arch->find(mScriptPattern, recursive);
78 
79         // loop through .rendercaps files and load each one
80         for (StringVector::iterator it = files->begin(), end = files->end(); it != end; ++it)
81         {
82             DataStreamPtr stream = arch->open(*it);
83             mSerializer->parseScript(stream);
84             stream->close();
85         }
86     }
87 
loadParsedCapabilities(const String & name)88     RenderSystemCapabilities* RenderSystemCapabilitiesManager::loadParsedCapabilities(const String& name)
89     {
90         return mCapabilitiesMap[name];
91     }
92 
getCapabilities() const93 	const map<String, RenderSystemCapabilities*>::type &RenderSystemCapabilitiesManager::getCapabilities() const
94 	{
95 		return mCapabilitiesMap;
96 	}
97 
98     /** Method used by RenderSystemCapabilitiesSerializer::parseScript */
_addRenderSystemCapabilities(const String & name,RenderSystemCapabilities * caps)99     void RenderSystemCapabilitiesManager::_addRenderSystemCapabilities(const String& name, RenderSystemCapabilities* caps)
100     {
101         mCapabilitiesMap.insert(CapabilitiesMap::value_type(name, caps));
102     }
103 }
104 
105 
106 
107 
108 
109