OGRE  1.9.0
OgreRenderSystemCapabilitiesSerializer.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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
38namespace Ogre {
39
40
49 {
50
51 public:
56
58 void writeScript(const RenderSystemCapabilities* caps, String name, String filename);
59
62
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
238
240
241 void logParseError(const String& error) const;
242
243 };
247}
248
249#include "OgreHeaderSuffix.h"
250
251#endif
#define _OgreExport
Definition: OgrePlatform.h:260
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Class for serializing RenderSystemCapabilities to / from a .rendercaps script.
map< String, SetStringMethod >::type SetStringMethodDispatchTable
void writeScript(const RenderSystemCapabilities *caps, String name, String filename)
Writes a RenderSystemCapabilities object to a data stream.
void addSetRealMethod(String keyword, SetRealMethod method)
void parseScript(DataStreamPtr &stream)
Parses a RenderSystemCapabilities script file passed as a stream.
void logParseError(const String &error) const
String writeString(const RenderSystemCapabilities *caps, String name)
Writes a RenderSystemCapabilities object to a string.
void addSetBoolMethod(String keyword, SetBoolMethod method)
void parseCapabilitiesLines(CapabilitiesLinesList &linesList)
CapabilityKeywordType getKeywordType(const String &keyword) const
void addSetIntMethod(String keyword, SetIntMethod method)
vector< std::pair< String, int > >::type CapabilitiesLinesList
RenderSystemCapabilitiesSerializer()
default constructor
map< String, CapabilityKeywordType >::type KeywordTypeMap
void addKeywordType(String keyword, CapabilityKeywordType type)
void addSetStringMethod(String keyword, SetStringMethod method)
singleton class for storing the capabilities of the graphics card.
Capabilities
Enum describing the different hardware capabilities we want to check for OGRE_CAPS_VALUE(a,...
float Real
Software floating point type.
_StringBase String
unsigned short ushort
std::map< K, V, P, A > type