OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreRenderSystemCapabilitiesSerializer.h
Go to the documentation of this file.
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-2014 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 #ifndef __RenderSystemCapabilitiesSerializer_H__
29 #define __RenderSystemCapabilitiesSerializer_H__
30 
31 #include "OgrePrerequisites.h"
33 #include "OgreHeaderPrefix.h"
34 
35 
36 namespace Ogre {
37 
38 
47  {
48 
49  public:
54 
56  void writeScript(const RenderSystemCapabilities* caps, const String &name, String filename);
57 
59  String writeString(const RenderSystemCapabilities* caps, const String &name);
60 
64  void parseScript(DataStreamPtr& stream);
65 
66  protected:
67 
68 
69  enum CapabilityKeywordType {UNDEFINED_CAPABILITY_TYPE = 0, SET_STRING_METHOD, SET_INT_METHOD, SET_BOOL_METHOD, SET_REAL_METHOD,
70  SET_CAPABILITY_ENUM_BOOL, ADD_SHADER_PROFILE_STRING};
71  // determines what keyword is what type of capability. For example:
72  // "automipmap" and "pbuffer" are both activated with setCapability (passing RSC_AUTOMIPMAP and RSC_PBUFFER respectivelly)
73  // while "max_num_multi_render_targets" is an integer and has it's own method: setMaxMultiNumRenderTargets
74  // we need to know these types to automatically parse each capability
77 
78  typedef void (RenderSystemCapabilities::*SetStringMethod)(const String&);
79  // maps capability keywords to setCapability(String& cap) style methods
82 
83  // SET_INT_METHOD parsing tables
84  typedef void (RenderSystemCapabilities::*SetIntMethod)(ushort);
87 
88  // SET_BOOL_METHOD parsing tables
89  typedef void (RenderSystemCapabilities::*SetBoolMethod)(bool);
92 
93  // SET_REAL_METHOD parsing tables
94  typedef void (RenderSystemCapabilities::*SetRealMethod)(Real);
97 
100 
102  {
103  mCapabilitiesMap.insert(CapabilitiesMap::value_type(name, cap));
104  }
105 
106 
107  // capabilities lines for parsing are collected along with their line numbers for debugging
109  // the set of states that the parser can be in
110  enum ParseAction {PARSE_HEADER, FIND_OPEN_BRACE, COLLECT_LINES};
111 
115 
117 
118  inline void addKeywordType(String keyword, CapabilityKeywordType type)
119  {
120  mKeywordTypeMap.insert(KeywordTypeMap::value_type(keyword, type));
121  }
122 
123  inline CapabilityKeywordType getKeywordType(const String& keyword) const
124  {
125  KeywordTypeMap::const_iterator it = mKeywordTypeMap.find(keyword);
126  if(it != mKeywordTypeMap.end())
127  return (*it).second;
128  else
129  {
130  logParseError("Can't find the type for keyword: " + keyword);
131  return UNDEFINED_CAPABILITY_TYPE;
132  }
133  }
134 
135  inline void addSetStringMethod(String keyword, SetStringMethod method)
136  {
137  mSetStringMethodDispatchTable.insert(SetStringMethodDispatchTable::value_type(keyword, method));
138  }
139 
140  inline void callSetStringMethod(String& keyword, String& val)
141  {
142  SetStringMethodDispatchTable::iterator methodIter = mSetStringMethodDispatchTable.find(keyword);
143  if (methodIter != mSetStringMethodDispatchTable.end())
144  {
145  SetStringMethod m = (*methodIter).second;
146  (mCurrentCapabilities->*m)(val);
147  }
148  else
149  {
150  logParseError("undefined keyword: " + keyword);
151  }
152  }
153 
154 
155  inline void addSetIntMethod(String keyword, SetIntMethod method)
156  {
157  mSetIntMethodDispatchTable.insert(SetIntMethodDispatchTable::value_type(keyword, method));
158  }
159 
160  inline void callSetIntMethod(String& keyword, ushort val)
161  {
162  SetIntMethodDispatchTable::iterator methodIter = mSetIntMethodDispatchTable.find(keyword);
163  if (methodIter != mSetIntMethodDispatchTable.end())
164  {
165  SetIntMethod m = (*methodIter).second;
166  (mCurrentCapabilities->*m)(val);
167  }
168  else
169  {
170  logParseError("undefined keyword: " + keyword);
171  }
172  }
173 
174 
175  inline void addSetBoolMethod(String keyword, SetBoolMethod method)
176  {
177  mSetBoolMethodDispatchTable.insert(SetBoolMethodDispatchTable::value_type(keyword, method));
178  }
179 
180  inline void callSetBoolMethod(String& keyword, bool val)
181  {
182  SetBoolMethodDispatchTable::iterator methodIter = mSetBoolMethodDispatchTable.find(keyword);
183  if (methodIter != mSetBoolMethodDispatchTable.end())
184  {
185  SetBoolMethod m = (*methodIter).second;
186  (mCurrentCapabilities->*m)(val);
187  }
188  else
189  {
190  logParseError("undefined keyword: " + keyword);
191  }
192  }
193 
194 
195  inline void addSetRealMethod(String keyword, SetRealMethod method)
196  {
197  mSetRealMethodDispatchTable.insert(SetRealMethodDispatchTable::value_type(keyword, method));
198  }
199 
200  inline void callSetRealMethod(String& keyword, Real val)
201  {
202  SetRealMethodDispatchTable::iterator methodIter = mSetRealMethodDispatchTable.find(keyword);
203  if (methodIter != mSetRealMethodDispatchTable.end())
204  {
205  SetRealMethod m = (*methodIter).second;
206  (mCurrentCapabilities->*m)(val);
207  }
208  else
209  {
210  logParseError("undefined keyword: " + keyword);
211  }
212  }
213 
214  inline void addShaderProfile(String& val)
215  {
216  mCurrentCapabilities->addShaderProfile(val);
217  }
218 
219  inline void setCapabilityEnumBool(String& name, bool val)
220  {
221  // check for errors
222  if(mCapabilitiesMap.find(name) == mCapabilitiesMap.end())
223  {
224  logParseError("Undefined capability: " + name);
225  return;
226  }
227  // only set true capabilities, we can't unset false
228  if(val)
229  {
230  Capabilities cap = mCapabilitiesMap[name];
231  mCurrentCapabilities->setCapability(cap);
232  }
233  }
234 
235  void initialiaseDispatchTables();
236 
237  void parseCapabilitiesLines(CapabilitiesLinesList& linesList);
238 
239  void logParseError(const String& error) const;
240 
241  };
245 }
246 
247 #include "OgreHeaderSuffix.h"
248 
249 #endif
void addSetIntMethod(String keyword, SetIntMethod method)
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:255
CapabilityKeywordType getKeywordType(const String &keyword) const
void addSetRealMethod(String keyword, SetRealMethod method)
map< String, CapabilityKeywordType >::type KeywordTypeMap
Capabilities
Enum describing the different hardware capabilities we want to check for OGRE_CAPS_VALUE(a, b) defines each capability.
void addSetStringMethod(String keyword, SetStringMethod method)
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
void addKeywordType(String keyword, CapabilityKeywordType type)
map< String, SetStringMethod >::type SetStringMethodDispatchTable
void addSetBoolMethod(String keyword, SetBoolMethod method)
unsigned short ushort
singleton class for storing the capabilities of the graphics card.
_StringBase String
Definition: OgreCommon.h:53
Class for serializing RenderSystemCapabilities to / from a .rendercaps script.
vector< std::pair< String, int > >::type CapabilitiesLinesList