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-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 #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
OgreHeaderSuffix.h
Ogre::RenderSystemCapabilitiesSerializer::SetStringMethodDispatchTable
map< String, SetStringMethod >::type SetStringMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:82
Ogre::RenderSystemCapabilitiesSerializer::mCurrentLineNumber
int mCurrentLineNumber
Definition: OgreRenderSystemCapabilitiesSerializer.h:114
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::ushort
unsigned short ushort
Definition: OgrePrerequisites.h:113
Ogre::RenderSystemCapabilitiesSerializer::mCapabilitiesMap
CapabilitiesMap mCapabilitiesMap
Definition: OgreRenderSystemCapabilitiesSerializer.h:101
Ogre::RenderSystemCapabilitiesSerializer::mSetIntMethodDispatchTable
SetIntMethodDispatchTable mSetIntMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:88
Ogre::RenderSystemCapabilitiesSerializer::CapabilitiesMap
map< String, Capabilities >::type CapabilitiesMap
Definition: OgreRenderSystemCapabilitiesSerializer.h:100
Ogre::RenderSystemCapabilitiesSerializer::addSetStringMethod
void addSetStringMethod(String keyword, SetStringMethod method)
Definition: OgreRenderSystemCapabilitiesSerializer.h:137
Ogre::RenderSystemCapabilitiesSerializer::SET_CAPABILITY_ENUM_BOOL
Definition: OgreRenderSystemCapabilitiesSerializer.h:72
Ogre::RenderSystemCapabilitiesSerializer::SetRealMethodDispatchTable
map< String, SetRealMethod >::type SetRealMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:97
Ogre::RenderSystemCapabilitiesSerializer::addSetBoolMethod
void addSetBoolMethod(String keyword, SetBoolMethod method)
Definition: OgreRenderSystemCapabilitiesSerializer.h:177
Ogre::RenderSystemCapabilitiesSerializer::ParseAction
ParseAction
Definition: OgreRenderSystemCapabilitiesSerializer.h:112
Ogre::RenderSystemCapabilitiesSerializer::mSetStringMethodDispatchTable
SetStringMethodDispatchTable mSetStringMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:83
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::RenderSystemCapabilitiesSerializer::addSetIntMethod
void addSetIntMethod(String keyword, SetIntMethod method)
Definition: OgreRenderSystemCapabilitiesSerializer.h:157
Ogre::RenderSystemCapabilitiesSerializer::addCapabilitiesMapping
void addCapabilitiesMapping(String name, Capabilities cap)
Definition: OgreRenderSystemCapabilitiesSerializer.h:103
Ogre::RenderSystemCapabilitiesSerializer::~RenderSystemCapabilitiesSerializer
virtual ~RenderSystemCapabilitiesSerializer()
default destructor
Definition: OgreRenderSystemCapabilitiesSerializer.h:55
Ogre::RenderSystemCapabilitiesSerializer::callSetStringMethod
void callSetStringMethod(String &keyword, String &val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:142
Ogre::RenderSystemCapabilitiesSerializer::SetBoolMethodDispatchTable
map< String, SetBoolMethod >::type SetBoolMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:92
OgreHeaderPrefix.h
OgrePrerequisites.h
Ogre::RenderSystemCapabilitiesSerializer::mCurrentStream
DataStreamPtr mCurrentStream
Definition: OgreRenderSystemCapabilitiesSerializer.h:116
Ogre::RenderSystemCapabilitiesSerializer::getKeywordType
CapabilityKeywordType getKeywordType(const String &keyword) const
Definition: OgreRenderSystemCapabilitiesSerializer.h:125
Ogre::RenderSystemCapabilitiesSerializer::callSetBoolMethod
void callSetBoolMethod(String &keyword, bool val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:182
Ogre::RenderSystemCapabilitiesSerializer::addShaderProfile
void addShaderProfile(String &val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:216
Ogre::RenderSystemCapabilities
singleton class for storing the capabilities of the graphics card.
Definition: OgreRenderSystemCapabilities.h:279
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::RenderSystemCapabilitiesSerializer::CapabilityKeywordType
CapabilityKeywordType
Definition: OgreRenderSystemCapabilitiesSerializer.h:71
Ogre::RenderSystemCapabilitiesSerializer::mSetRealMethodDispatchTable
SetRealMethodDispatchTable mSetRealMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:98
Ogre::RenderSystemCapabilitiesSerializer::callSetIntMethod
void callSetIntMethod(String &keyword, ushort val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:162
Ogre::SharedPtr< DataStream >
Ogre::RenderSystemCapabilitiesSerializer
Class for serializing RenderSystemCapabilities to / from a .rendercaps script.
Definition: OgreRenderSystemCapabilitiesSerializer.h:48
Ogre::RenderSystemCapabilitiesSerializer::addSetRealMethod
void addSetRealMethod(String keyword, SetRealMethod method)
Definition: OgreRenderSystemCapabilitiesSerializer.h:197
Ogre::RenderSystemCapabilitiesSerializer::setCapabilityEnumBool
void setCapabilityEnumBool(String &name, bool val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:221
Ogre::RenderSystemCapabilitiesSerializer::mSetBoolMethodDispatchTable
SetBoolMethodDispatchTable mSetBoolMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:93
Ogre::RenderSystemCapabilitiesSerializer::mKeywordTypeMap
KeywordTypeMap mKeywordTypeMap
Definition: OgreRenderSystemCapabilitiesSerializer.h:78
Ogre::RenderSystemCapabilitiesSerializer::callSetRealMethod
void callSetRealMethod(String &keyword, Real val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:202
Ogre::Capabilities
Capabilities
Enum describing the different hardware capabilities we want to check for OGRE_CAPS_VALUE(a,...
Definition: OgreRenderSystemCapabilities.h:77
Ogre::RenderSystemCapabilitiesSerializer::CapabilitiesLinesList
vector< std::pair< String, int > >::type CapabilitiesLinesList
Definition: OgreRenderSystemCapabilitiesSerializer.h:110
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
OgreRenderSystemCapabilities.h
Ogre::RenderSystemCapabilitiesSerializer::SetIntMethodDispatchTable
map< String, SetIntMethod >::type SetIntMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:87
OgreStringVector.h
Ogre::RenderSystemCapabilitiesSerializer::KeywordTypeMap
map< String, CapabilityKeywordType >::type KeywordTypeMap
Definition: OgreRenderSystemCapabilitiesSerializer.h:77
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::RenderSystemCapabilitiesSerializer::mCurrentCapabilities
RenderSystemCapabilities * mCurrentCapabilities
Definition: OgreRenderSystemCapabilitiesSerializer.h:118
OgreDataStream.h
Ogre::RenderSystemCapabilitiesSerializer::mCurrentLine
String * mCurrentLine
Definition: OgreRenderSystemCapabilitiesSerializer.h:115
Ogre::RenderSystemCapabilitiesSerializer::addKeywordType
void addKeywordType(String keyword, CapabilityKeywordType type)
Definition: OgreRenderSystemCapabilitiesSerializer.h:120

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.