OGRE  1.9
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 "OgreStringVector.h"
34 #include "OgreDataStream.h"
35 #include "OgreHeaderPrefix.h"
36 
37 
38 namespace Ogre {
39 
40 
49  {
50 
51  public:
56 
58  void writeScript(const RenderSystemCapabilities* caps, String name, String filename);
59 
61  String writeString(const RenderSystemCapabilities* caps, String name);
62 
66  void parseScript(DataStreamPtr& stream);
67 
68  protected:
69 
70 
71  enum CapabilityKeywordType {UNDEFINED_CAPABILITY_TYPE = 0, SET_STRING_METHOD, SET_INT_METHOD, SET_BOOL_METHOD, SET_REAL_METHOD,
72  SET_CAPABILITY_ENUM_BOOL, ADD_SHADER_PROFILE_STRING};
73  // determines what keyword is what type of capability. For example:
74  // "automipmap" and "pbuffer" are both activated with setCapability (passing RSC_AUTOMIPMAP and RSC_PBUFFER respectivelly)
75  // while "max_num_multi_render_targets" is an integer and has it's own method: setMaxMultiNumRenderTargets
76  // we need to know these types to automatically parse each capability
79 
80  typedef void (RenderSystemCapabilities::*SetStringMethod)(const String&);
81  // maps capability keywords to setCapability(String& cap) style methods
84 
85  // SET_INT_METHOD parsing tables
86  typedef void (RenderSystemCapabilities::*SetIntMethod)(ushort);
89 
90  // SET_BOOL_METHOD parsing tables
91  typedef void (RenderSystemCapabilities::*SetBoolMethod)(bool);
94 
95  // SET_REAL_METHOD parsing tables
96  typedef void (RenderSystemCapabilities::*SetRealMethod)(Real);
99 
102 
104  {
105  mCapabilitiesMap.insert(CapabilitiesMap::value_type(name, cap));
106  }
107 
108 
109  // capabilities lines for parsing are collected along with their line numbers for debugging
111  // the set of states that the parser can be in
112  enum ParseAction {PARSE_HEADER, FIND_OPEN_BRACE, COLLECT_LINES};
113 
117 
119 
120  inline void addKeywordType(String keyword, CapabilityKeywordType type)
121  {
122  mKeywordTypeMap.insert(KeywordTypeMap::value_type(keyword, type));
123  }
124 
125  inline CapabilityKeywordType getKeywordType(const String& keyword) const
126  {
127  KeywordTypeMap::const_iterator it = mKeywordTypeMap.find(keyword);
128  if(it != mKeywordTypeMap.end())
129  return (*it).second;
130  else
131  {
132  logParseError("Can't find the type for keyword: " + keyword);
133  return UNDEFINED_CAPABILITY_TYPE;
134  }
135  }
136 
137  inline void addSetStringMethod(String keyword, SetStringMethod method)
138  {
139  mSetStringMethodDispatchTable.insert(SetStringMethodDispatchTable::value_type(keyword, method));
140  }
141 
142  inline void callSetStringMethod(String& keyword, String& val)
143  {
144  SetStringMethodDispatchTable::iterator methodIter = mSetStringMethodDispatchTable.find(keyword);
145  if (methodIter != mSetStringMethodDispatchTable.end())
146  {
147  SetStringMethod m = (*methodIter).second;
148  (mCurrentCapabilities->*m)(val);
149  }
150  else
151  {
152  logParseError("undefined keyword: " + keyword);
153  }
154  }
155 
156 
157  inline void addSetIntMethod(String keyword, SetIntMethod method)
158  {
159  mSetIntMethodDispatchTable.insert(SetIntMethodDispatchTable::value_type(keyword, method));
160  }
161 
162  inline void callSetIntMethod(String& keyword, ushort val)
163  {
164  SetIntMethodDispatchTable::iterator methodIter = mSetIntMethodDispatchTable.find(keyword);
165  if (methodIter != mSetIntMethodDispatchTable.end())
166  {
167  SetIntMethod m = (*methodIter).second;
168  (mCurrentCapabilities->*m)(val);
169  }
170  else
171  {
172  logParseError("undefined keyword: " + keyword);
173  }
174  }
175 
176 
177  inline void addSetBoolMethod(String keyword, SetBoolMethod method)
178  {
179  mSetBoolMethodDispatchTable.insert(SetBoolMethodDispatchTable::value_type(keyword, method));
180  }
181 
182  inline void callSetBoolMethod(String& keyword, bool val)
183  {
184  SetBoolMethodDispatchTable::iterator methodIter = mSetBoolMethodDispatchTable.find(keyword);
185  if (methodIter != mSetBoolMethodDispatchTable.end())
186  {
187  SetBoolMethod m = (*methodIter).second;
188  (mCurrentCapabilities->*m)(val);
189  }
190  else
191  {
192  logParseError("undefined keyword: " + keyword);
193  }
194  }
195 
196 
197  inline void addSetRealMethod(String keyword, SetRealMethod method)
198  {
199  mSetRealMethodDispatchTable.insert(SetRealMethodDispatchTable::value_type(keyword, method));
200  }
201 
202  inline void callSetRealMethod(String& keyword, Real val)
203  {
204  SetRealMethodDispatchTable::iterator methodIter = mSetRealMethodDispatchTable.find(keyword);
205  if (methodIter != mSetRealMethodDispatchTable.end())
206  {
207  SetRealMethod m = (*methodIter).second;
208  (mCurrentCapabilities->*m)(val);
209  }
210  else
211  {
212  logParseError("undefined keyword: " + keyword);
213  }
214  }
215 
216  inline void addShaderProfile(String& val)
217  {
218  mCurrentCapabilities->addShaderProfile(val);
219  }
220 
221  inline void setCapabilityEnumBool(String& name, bool val)
222  {
223  // check for errors
224  if(mCapabilitiesMap.find(name) == mCapabilitiesMap.end())
225  {
226  logParseError("Undefined capability: " + name);
227  return;
228  }
229  // only set true capabilities, we can't unset false
230  if(val)
231  {
232  Capabilities cap = mCapabilitiesMap[name];
233  mCurrentCapabilities->setCapability(cap);
234  }
235  }
236 
237  void initialiaseDispatchTables();
238 
239  void parseCapabilitiesLines(CapabilitiesLinesList& linesList);
240 
241  void logParseError(const String& error) const;
242 
243  };
247 }
248 
249 #include "OgreHeaderSuffix.h"
250 
251 #endif
void addSetIntMethod(String keyword, SetIntMethod method)
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:260
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
Class for serializing RenderSystemCapabilities to / from a .rendercaps script.
vector< std::pair< String, int > >::type CapabilitiesLinesList