00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __RenderSystemCapabilitiesSerializer_H__ 00029 #define __RenderSystemCapabilitiesSerializer_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreRenderSystemCapabilities.h" 00033 #include "OgreStringVector.h" 00034 #include "OgreDataStream.h" 00035 00036 00037 00038 namespace Ogre { 00039 00040 00048 class _OgreExport RenderSystemCapabilitiesSerializer : public RenderSysAlloc 00049 { 00050 00051 public: 00053 RenderSystemCapabilitiesSerializer(); 00055 virtual ~RenderSystemCapabilitiesSerializer() {} 00056 00058 void writeScript(const RenderSystemCapabilities* caps, String name, String filename); 00059 00061 String writeString(const RenderSystemCapabilities* caps, String name); 00062 00066 void parseScript(DataStreamPtr& stream); 00067 00068 protected: 00069 00070 00071 enum CapabilityKeywordType {UNDEFINED_CAPABILITY_TYPE = 0, SET_STRING_METHOD, SET_INT_METHOD, SET_BOOL_METHOD, SET_REAL_METHOD, 00072 SET_CAPABILITY_ENUM_BOOL, ADD_SHADER_PROFILE_STRING}; 00073 // determines what keyword is what type of capability. For example: 00074 // "automipmap" and "pbuffer" are both activated with setCapability (passing RSC_AUTOMIPMAP and RSC_PBUFFER respectivelly) 00075 // while "max_num_multi_render_targets" is an integer and has it's own method: setMaxMultiNumRenderTargets 00076 // we need to know these types to automatically parse each capability 00077 typedef map<String, CapabilityKeywordType>::type KeywordTypeMap; 00078 KeywordTypeMap mKeywordTypeMap; 00079 00080 typedef void (RenderSystemCapabilities::*SetStringMethod)(const String&); 00081 // maps capability keywords to setCapability(String& cap) style methods 00082 typedef map<String, SetStringMethod>::type SetStringMethodDispatchTable; 00083 SetStringMethodDispatchTable mSetStringMethodDispatchTable; 00084 00085 // SET_INT_METHOD parsing tables 00086 typedef void (RenderSystemCapabilities::*SetIntMethod)(ushort); 00087 typedef map<String, SetIntMethod>::type SetIntMethodDispatchTable; 00088 SetIntMethodDispatchTable mSetIntMethodDispatchTable; 00089 00090 // SET_BOOL_METHOD parsing tables 00091 typedef void (RenderSystemCapabilities::*SetBoolMethod)(bool); 00092 typedef map<String, SetBoolMethod>::type SetBoolMethodDispatchTable; 00093 SetBoolMethodDispatchTable mSetBoolMethodDispatchTable; 00094 00095 // SET_REAL_METHOD parsing tables 00096 typedef void (RenderSystemCapabilities::*SetRealMethod)(Real); 00097 typedef map<String, SetRealMethod>::type SetRealMethodDispatchTable; 00098 SetRealMethodDispatchTable mSetRealMethodDispatchTable; 00099 00100 typedef map<String, Capabilities>::type CapabilitiesMap; 00101 CapabilitiesMap mCapabilitiesMap; 00102 00103 inline void addCapabilitiesMapping(String name, Capabilities cap) 00104 { 00105 mCapabilitiesMap.insert(CapabilitiesMap::value_type(name, cap)); 00106 } 00107 00108 00109 // capabilities lines for parsing are collected along with their line numbers for debugging 00110 typedef vector<std::pair<String, int> >::type CapabilitiesLinesList; 00111 // the set of states that the parser can be in 00112 enum ParseAction {PARSE_HEADER, FIND_OPEN_BRACE, COLLECT_LINES}; 00113 00114 int mCurrentLineNumber; 00115 String* mCurrentLine; 00116 DataStreamPtr mCurrentStream; 00117 00118 RenderSystemCapabilities* mCurrentCapabilities; 00119 00120 inline void addKeywordType(String keyword, CapabilityKeywordType type) 00121 { 00122 mKeywordTypeMap.insert(KeywordTypeMap::value_type(keyword, type)); 00123 } 00124 00125 inline CapabilityKeywordType getKeywordType(const String& keyword) const 00126 { 00127 KeywordTypeMap::const_iterator it = mKeywordTypeMap.find(keyword); 00128 if(it != mKeywordTypeMap.end()) 00129 return (*it).second; 00130 else 00131 { 00132 logParseError("Can't find the type for keyword: " + keyword); 00133 return UNDEFINED_CAPABILITY_TYPE; 00134 } 00135 } 00136 00137 inline void addSetStringMethod(String keyword, SetStringMethod method) 00138 { 00139 mSetStringMethodDispatchTable.insert(SetStringMethodDispatchTable::value_type(keyword, method)); 00140 } 00141 00142 inline void callSetStringMethod(String& keyword, String& val) 00143 { 00144 SetStringMethodDispatchTable::iterator methodIter = mSetStringMethodDispatchTable.find(keyword); 00145 if (methodIter != mSetStringMethodDispatchTable.end()) 00146 { 00147 SetStringMethod m = (*methodIter).second; 00148 (mCurrentCapabilities->*m)(val); 00149 } 00150 else 00151 { 00152 logParseError("undefined keyword: " + keyword); 00153 } 00154 } 00155 00156 00157 inline void addSetIntMethod(String keyword, SetIntMethod method) 00158 { 00159 mSetIntMethodDispatchTable.insert(SetIntMethodDispatchTable::value_type(keyword, method)); 00160 } 00161 00162 inline void callSetIntMethod(String& keyword, ushort val) 00163 { 00164 SetIntMethodDispatchTable::iterator methodIter = mSetIntMethodDispatchTable.find(keyword); 00165 if (methodIter != mSetIntMethodDispatchTable.end()) 00166 { 00167 SetIntMethod m = (*methodIter).second; 00168 (mCurrentCapabilities->*m)(val); 00169 } 00170 else 00171 { 00172 logParseError("undefined keyword: " + keyword); 00173 } 00174 } 00175 00176 00177 inline void addSetBoolMethod(String keyword, SetBoolMethod method) 00178 { 00179 mSetBoolMethodDispatchTable.insert(SetBoolMethodDispatchTable::value_type(keyword, method)); 00180 } 00181 00182 inline void callSetBoolMethod(String& keyword, bool val) 00183 { 00184 SetBoolMethodDispatchTable::iterator methodIter = mSetBoolMethodDispatchTable.find(keyword); 00185 if (methodIter != mSetBoolMethodDispatchTable.end()) 00186 { 00187 SetBoolMethod m = (*methodIter).second; 00188 (mCurrentCapabilities->*m)(val); 00189 } 00190 else 00191 { 00192 logParseError("undefined keyword: " + keyword); 00193 } 00194 } 00195 00196 00197 inline void addSetRealMethod(String keyword, SetRealMethod method) 00198 { 00199 mSetRealMethodDispatchTable.insert(SetRealMethodDispatchTable::value_type(keyword, method)); 00200 } 00201 00202 inline void callSetRealMethod(String& keyword, Real val) 00203 { 00204 SetRealMethodDispatchTable::iterator methodIter = mSetRealMethodDispatchTable.find(keyword); 00205 if (methodIter != mSetRealMethodDispatchTable.end()) 00206 { 00207 SetRealMethod m = (*methodIter).second; 00208 (mCurrentCapabilities->*m)(val); 00209 } 00210 else 00211 { 00212 logParseError("undefined keyword: " + keyword); 00213 } 00214 } 00215 00216 inline void addShaderProfile(String& val) 00217 { 00218 mCurrentCapabilities->addShaderProfile(val); 00219 } 00220 00221 inline void setCapabilityEnumBool(String& name, bool val) 00222 { 00223 // check for errors 00224 if(mCapabilitiesMap.find(name) == mCapabilitiesMap.end()) 00225 { 00226 logParseError("Undefined capability: " + name); 00227 return; 00228 } 00229 // only set true capabilities, we can't unset false 00230 if(val) 00231 { 00232 Capabilities cap = mCapabilitiesMap[name]; 00233 mCurrentCapabilities->setCapability(cap); 00234 } 00235 } 00236 00237 void initialiaseDispatchTables(); 00238 00239 void parseCapabilitiesLines(CapabilitiesLinesList& linesList); 00240 00241 void logParseError(const String& error) const; 00242 00243 }; 00247 } 00248 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:26 2012