# OgreRenderSystemCapabilitiesSerializer.h

Go to the documentation of this file.

    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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __RenderSystemCapabilitiesSerializer_H__
    00030 #define __RenderSystemCapabilitiesSerializer_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreRenderSystemCapabilities.h"
    00034 #include "OgreStringVector.h"
    00035 #include "OgreDataStream.h"
    00036
    00037
    00038
    00039 namespace Ogre {
    00040
    00041
    00043     class _OgreExport RenderSystemCapabilitiesSerializer : public RenderSysAlloc
    00044     {
    00045
    00046     public:
    00048         RenderSystemCapabilitiesSerializer();
    00050         virtual ~RenderSystemCapabilitiesSerializer() {};
    00051
    00053         void writeScript(const RenderSystemCapabilities* caps, String name, String filename);
    00054
    00058         void parseScript(DataStreamPtr& stream);
    00059
    00060     protected:
    00061
    00062
    00063         enum CapabilityKeywordType {UNDEFINED_CAPABILITY_TYPE = 0, SET_STRING_METHOD, SET_INT_METHOD, SET_BOOL_METHOD, SET_REAL_METHOD,
    00064                                 SET_CAPABILITY_ENUM_BOOL, ADD_SHADER_PROFILE_STRING};
    00065         // determines what keyword is what type of capability. For example:
    00066         // "automipmap" and "pbuffer" are both activated with setCapability (passing RSC_AUTOMIPMAP and RSC_PBUFFER respectivelly)
    00067         // while "max_num_multi_render_targets" is an integer and has it's own method: setMaxMultiNumRenderTargets
    00068         // we need to know these types to automatically parse each capability
    00069         typedef std::map<String, CapabilityKeywordType> KeywordTypeMap;
    00070         KeywordTypeMap mKeywordTypeMap;
    00071
    00072         typedef void (RenderSystemCapabilities::*SetStringMethod)(const String&);
    00073         // maps capability keywords to setCapability(String& cap) style methods
    00074         typedef std::map<String, SetStringMethod> SetStringMethodDispatchTable;
    00075         SetStringMethodDispatchTable mSetStringMethodDispatchTable;
    00076
    00077         // SET_INT_METHOD parsing tables
    00078         typedef void (RenderSystemCapabilities::*SetIntMethod)(ushort);
    00079         typedef std::map<String, SetIntMethod> SetIntMethodDispatchTable;
    00080         SetIntMethodDispatchTable mSetIntMethodDispatchTable;
    00081
    00082         // SET_BOOL_METHOD parsing tables
    00083         typedef void (RenderSystemCapabilities::*SetBoolMethod)(bool);
    00084         typedef std::map<String, SetBoolMethod> SetBoolMethodDispatchTable;
    00085         SetBoolMethodDispatchTable mSetBoolMethodDispatchTable;
    00086
    00087         // SET_REAL_METHOD parsing tables
    00088         typedef void (RenderSystemCapabilities::*SetRealMethod)(Real);
    00089         typedef std::map<String, SetRealMethod> SetRealMethodDispatchTable;
    00090         SetRealMethodDispatchTable mSetRealMethodDispatchTable;
    00091
    00092         typedef std::map<String, Capabilities> CapabilitiesMap;
    00093         CapabilitiesMap mCapabilitiesMap;
    00094
    00095         inline void addCapabilitiesMapping(String name, Capabilities cap)
    00096         {
    00097             mCapabilitiesMap.insert(CapabilitiesMap::value_type(name, cap));
    00098         }
    00099
    00100
    00101         // capabilities lines for parsing are collected along with their line numbers for debugging
    00102         typedef std::vector<std::pair<String, int> > CapabilitiesLinesList;
    00103         // the set of states that the parser can be in
    00104         enum ParseAction {PARSE_HEADER, FIND_OPEN_BRACE, COLLECT_LINES};
    00105
    00106         int mCurrentLineNumber;
    00107         String* mCurrentLine;
    00108         DataStreamPtr mCurrentStream;
    00109
    00110         RenderSystemCapabilities* mCurrentCapabilities;
    00111
    00112         inline void addKeywordType(String keyword, CapabilityKeywordType type)
    00113         {
    00114             mKeywordTypeMap.insert(KeywordTypeMap::value_type(keyword, type));
    00115         }
    00116
    00117         inline CapabilityKeywordType getKeywordType(const String& keyword) const
    00118         {
    00119                         KeywordTypeMap::const_iterator it = mKeywordTypeMap.find(keyword);
    00120             if(it != mKeywordTypeMap.end())
    00121                              return (*it).second;
    00122                         else
    00123                         {
    00124                              logParseError("Can't find the type for keyword: " + keyword);
    00125                              return UNDEFINED_CAPABILITY_TYPE;
    00126                         }
    00127         }
    00128
    00129         inline void addSetStringMethod(String keyword, SetStringMethod method)
    00130         {
    00131             mSetStringMethodDispatchTable.insert(SetStringMethodDispatchTable::value_type(keyword, method));
    00132         }
    00133
    00134         inline void callSetStringMethod(String& keyword, String& val)
    00135         {
    00136             SetStringMethodDispatchTable::iterator methodIter = mSetStringMethodDispatchTable.find(keyword);
    00137             if (methodIter != mSetStringMethodDispatchTable.end())
    00138             {
    00139                             SetStringMethod m = (*methodIter).second;
    00140                 (mCurrentCapabilities->*m)(val);
    00141             }
    00142             else
    00143             {
    00144                 logParseError("undefined keyword: " + keyword);
    00145             }
    00146         }
    00147
    00148
    00149         inline void addSetIntMethod(String keyword, SetIntMethod method)
    00150         {
    00151             mSetIntMethodDispatchTable.insert(SetIntMethodDispatchTable::value_type(keyword, method));
    00152         }
    00153
    00154         inline void callSetIntMethod(String& keyword, int val)
    00155         {
    00156             SetIntMethodDispatchTable::iterator methodIter = mSetIntMethodDispatchTable.find(keyword);
    00157             if (methodIter != mSetIntMethodDispatchTable.end())
    00158             {
    00159                             SetIntMethod m = (*methodIter).second;
    00160                 (mCurrentCapabilities->*m)(val);
    00161             }
    00162             else
    00163             {
    00164                 logParseError("undefined keyword: " + keyword);
    00165             }
    00166         }
    00167
    00168
    00169         inline void addSetBoolMethod(String keyword, SetBoolMethod method)
    00170         {
    00171             mSetBoolMethodDispatchTable.insert(SetBoolMethodDispatchTable::value_type(keyword, method));
    00172         }
    00173
    00174         inline void callSetBoolMethod(String& keyword, bool val)
    00175         {
    00176             SetBoolMethodDispatchTable::iterator methodIter = mSetBoolMethodDispatchTable.find(keyword);
    00177             if (methodIter != mSetBoolMethodDispatchTable.end())
    00178             {
    00179                             SetBoolMethod m = (*methodIter).second;
    00180                 (mCurrentCapabilities->*m)(val);
    00181             }
    00182             else
    00183             {
    00184                 logParseError("undefined keyword: " + keyword);
    00185                         }
    00186         }
    00187
    00188
    00189         inline void addSetRealMethod(String keyword, SetRealMethod method)
    00190         {
    00191             mSetRealMethodDispatchTable.insert(SetRealMethodDispatchTable::value_type(keyword, method));
    00192         }
    00193
    00194         inline void callSetRealMethod(String& keyword, Real val)
    00195         {
    00196             SetRealMethodDispatchTable::iterator methodIter = mSetRealMethodDispatchTable.find(keyword);
    00197             if (methodIter != mSetRealMethodDispatchTable.end())
    00198             {
    00199                             SetRealMethod m = (*methodIter).second;
    00200                 (mCurrentCapabilities->*m)(val);
    00201             }
    00202             else
    00203             {
    00204                 logParseError("undefined keyword: " + keyword);
    00205                         }
    00206         }
    00207
    00208         inline void addShaderProfile(String& val)
    00209         {
    00210             mCurrentCapabilities->addShaderProfile(val);
    00211         }
    00212
    00213         inline void setCapabilityEnumBool(String& name, bool val)
    00214         {
    00215             // check for errors
    00216             if(mCapabilitiesMap.find(name) == mCapabilitiesMap.end())
    00217             {
    00218                 logParseError("Undefined capability: " + name);
    00219                 return;
    00220             }
    00221             // only set true capabilities, we can't unset false
    00222             if(val)
    00223             {
    00224                 Capabilities cap = mCapabilitiesMap[name];
    00225                 mCurrentCapabilities->setCapability(cap);
    00226             }
    00227         }
    00228
    00229         void initialiaseDispatchTables();
    00230
    00231         void parseCapabilitiesLines(CapabilitiesLinesList& linesList);
    00232
    00233         void logParseError(const String& error) const;
    00234
    00235     };
    00236
    00237 }
    00238 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 14:26:45 2009