OgreRenderSystemCapabilitiesSerializer.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __RenderSystemCapabilitiesSerializer_H__
#define __RenderSystemCapabilitiesSerializer_H__
#include "OgrePrerequisites.h"
#include "OgreRenderSystemCapabilities.h"
#include "OgreStringVector.h"
#include "OgreDataStream.h"
#include "OgreHeaderPrefix.h"
namespace Ogre {
class _OgreExport RenderSystemCapabilitiesSerializer : public RenderSysAlloc
{
public:
RenderSystemCapabilitiesSerializer();
virtual ~RenderSystemCapabilitiesSerializer() {}
void writeScript(const RenderSystemCapabilities* caps, String name, String filename);
String writeString(const RenderSystemCapabilities* caps, String name);
void parseScript(DataStreamPtr& stream);
protected:
enum CapabilityKeywordType {UNDEFINED_CAPABILITY_TYPE = 0, SET_STRING_METHOD, SET_INT_METHOD, SET_BOOL_METHOD, SET_REAL_METHOD,
SET_CAPABILITY_ENUM_BOOL, ADD_SHADER_PROFILE_STRING};
// determines what keyword is what type of capability. For example:
// "automipmap" and "pbuffer" are both activated with setCapability (passing RSC_AUTOMIPMAP and RSC_PBUFFER respectivelly)
// while "max_num_multi_render_targets" is an integer and has it's own method: setMaxMultiNumRenderTargets
// we need to know these types to automatically parse each capability
typedef map<String, CapabilityKeywordType>::type KeywordTypeMap;
KeywordTypeMap mKeywordTypeMap;
typedef void (RenderSystemCapabilities::*SetStringMethod)(const String&);
// maps capability keywords to setCapability(String& cap) style methods
typedef map<String, SetStringMethod>::type SetStringMethodDispatchTable;
SetStringMethodDispatchTable mSetStringMethodDispatchTable;
// SET_INT_METHOD parsing tables
typedef void (RenderSystemCapabilities::*SetIntMethod)(ushort);
typedef map<String, SetIntMethod>::type SetIntMethodDispatchTable;
SetIntMethodDispatchTable mSetIntMethodDispatchTable;
// SET_BOOL_METHOD parsing tables
typedef void (RenderSystemCapabilities::*SetBoolMethod)(bool);
typedef map<String, SetBoolMethod>::type SetBoolMethodDispatchTable;
SetBoolMethodDispatchTable mSetBoolMethodDispatchTable;
// SET_REAL_METHOD parsing tables
typedef void (RenderSystemCapabilities::*SetRealMethod)(Real);
typedef map<String, SetRealMethod>::type SetRealMethodDispatchTable;
SetRealMethodDispatchTable mSetRealMethodDispatchTable;
typedef map<String, Capabilities>::type CapabilitiesMap;
CapabilitiesMap mCapabilitiesMap;
inline void addCapabilitiesMapping(String name, Capabilities cap)
{
mCapabilitiesMap.insert(CapabilitiesMap::value_type(name, cap));
}
// capabilities lines for parsing are collected along with their line numbers for debugging
typedef vector<std::pair<String, int> >::type CapabilitiesLinesList;
// the set of states that the parser can be in
enum ParseAction {PARSE_HEADER, FIND_OPEN_BRACE, COLLECT_LINES};
int mCurrentLineNumber;
String* mCurrentLine;
DataStreamPtr mCurrentStream;
RenderSystemCapabilities* mCurrentCapabilities;
inline void addKeywordType(String keyword, CapabilityKeywordType type)
{
mKeywordTypeMap.insert(KeywordTypeMap::value_type(keyword, type));
}
inline CapabilityKeywordType getKeywordType(const String& keyword) const
{
KeywordTypeMap::const_iterator it = mKeywordTypeMap.find(keyword);
if(it != mKeywordTypeMap.end())
return (*it).second;
else
{
logParseError("Can't find the type for keyword: " + keyword);
return UNDEFINED_CAPABILITY_TYPE;
}
}
inline void addSetStringMethod(String keyword, SetStringMethod method)
{
mSetStringMethodDispatchTable.insert(SetStringMethodDispatchTable::value_type(keyword, method));
}
inline void callSetStringMethod(String& keyword, String& val)
{
SetStringMethodDispatchTable::iterator methodIter = mSetStringMethodDispatchTable.find(keyword);
if (methodIter != mSetStringMethodDispatchTable.end())
{
SetStringMethod m = (*methodIter).second;
(mCurrentCapabilities->*m)(val);
}
else
{
logParseError("undefined keyword: " + keyword);
}
}
inline void addSetIntMethod(String keyword, SetIntMethod method)
{
mSetIntMethodDispatchTable.insert(SetIntMethodDispatchTable::value_type(keyword, method));
}
inline void callSetIntMethod(String& keyword, ushort val)
{
SetIntMethodDispatchTable::iterator methodIter = mSetIntMethodDispatchTable.find(keyword);
if (methodIter != mSetIntMethodDispatchTable.end())
{
SetIntMethod m = (*methodIter).second;
(mCurrentCapabilities->*m)(val);
}
else
{
logParseError("undefined keyword: " + keyword);
}
}
inline void addSetBoolMethod(String keyword, SetBoolMethod method)
{
mSetBoolMethodDispatchTable.insert(SetBoolMethodDispatchTable::value_type(keyword, method));
}
inline void callSetBoolMethod(String& keyword, bool val)
{
SetBoolMethodDispatchTable::iterator methodIter = mSetBoolMethodDispatchTable.find(keyword);
if (methodIter != mSetBoolMethodDispatchTable.end())
{
SetBoolMethod m = (*methodIter).second;
(mCurrentCapabilities->*m)(val);
}
else
{
logParseError("undefined keyword: " + keyword);
}
}
inline void addSetRealMethod(String keyword, SetRealMethod method)
{
mSetRealMethodDispatchTable.insert(SetRealMethodDispatchTable::value_type(keyword, method));
}
inline void callSetRealMethod(String& keyword, Real val)
{
SetRealMethodDispatchTable::iterator methodIter = mSetRealMethodDispatchTable.find(keyword);
if (methodIter != mSetRealMethodDispatchTable.end())
{
SetRealMethod m = (*methodIter).second;
(mCurrentCapabilities->*m)(val);
}
else
{
logParseError("undefined keyword: " + keyword);
}
}
inline void addShaderProfile(String& val)
{
mCurrentCapabilities->addShaderProfile(val);
}
inline void setCapabilityEnumBool(String& name, bool val)
{
// check for errors
if(mCapabilitiesMap.find(name) == mCapabilitiesMap.end())
{
logParseError("Undefined capability: " + name);
return;
}
// only set true capabilities, we can't unset false
if(val)
{
Capabilities cap = mCapabilitiesMap[name];
mCurrentCapabilities->setCapability(cap);
}
}
void initialiaseDispatchTables();
void parseCapabilitiesLines(CapabilitiesLinesList& linesList);
void logParseError(const String& error) const;
};
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::RenderSystemCapabilitiesSerializer::callSetBoolMethod
void callSetBoolMethod(String &keyword, bool val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:182
Ogre::RenderSystemCapabilitiesSerializer::mCapabilitiesMap
CapabilitiesMap mCapabilitiesMap
Definition: OgreRenderSystemCapabilitiesSerializer.h:101
Ogre::RenderSystemCapabilitiesSerializer::SET_CAPABILITY_ENUM_BOOL
Definition: OgreRenderSystemCapabilitiesSerializer.h:72
Ogre::RenderSystemCapabilitiesSerializer::addShaderProfile
void addShaderProfile(String &val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:216
Ogre::RenderSystemCapabilitiesSerializer::mCurrentCapabilities
RenderSystemCapabilities * mCurrentCapabilities
Definition: OgreRenderSystemCapabilitiesSerializer.h:118
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::RenderSystemCapabilitiesSerializer::getKeywordType
CapabilityKeywordType getKeywordType(const String &keyword) const
Definition: OgreRenderSystemCapabilitiesSerializer.h:125
Ogre::RenderSystemCapabilitiesSerializer::SetRealMethodDispatchTable
map< String, SetRealMethod >::type SetRealMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:97
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::RenderSystemCapabilitiesSerializer::SetIntMethodDispatchTable
map< String, SetIntMethod >::type SetIntMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:87
Ogre::RenderSystemCapabilitiesSerializer::CapabilityKeywordType
CapabilityKeywordType
Definition: OgreRenderSystemCapabilitiesSerializer.h:71
Ogre::RenderSystemCapabilitiesSerializer::addSetRealMethod
void addSetRealMethod(String keyword, SetRealMethod method)
Definition: OgreRenderSystemCapabilitiesSerializer.h:197
Ogre::RenderSystemCapabilitiesSerializer::mSetRealMethodDispatchTable
SetRealMethodDispatchTable mSetRealMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:98
OgreDataStream.h
Ogre::RenderSystemCapabilitiesSerializer::mSetBoolMethodDispatchTable
SetBoolMethodDispatchTable mSetBoolMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:93
OgreRenderSystemCapabilities.h
Ogre::RenderSystemCapabilitiesSerializer::mSetIntMethodDispatchTable
SetIntMethodDispatchTable mSetIntMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:88
OgrePrerequisites.h
Ogre::RenderSystemCapabilitiesSerializer::mKeywordTypeMap
KeywordTypeMap mKeywordTypeMap
Definition: OgreRenderSystemCapabilitiesSerializer.h:78
Ogre::RenderSystemCapabilitiesSerializer::callSetRealMethod
void callSetRealMethod(String &keyword, Real val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:202
Ogre::RenderSystemCapabilitiesSerializer::addCapabilitiesMapping
void addCapabilitiesMapping(String name, Capabilities cap)
Definition: OgreRenderSystemCapabilitiesSerializer.h:103
Ogre::RenderSystemCapabilitiesSerializer::addSetBoolMethod
void addSetBoolMethod(String keyword, SetBoolMethod method)
Definition: OgreRenderSystemCapabilitiesSerializer.h:177
Ogre::RenderSystemCapabilitiesSerializer::addSetStringMethod
void addSetStringMethod(String keyword, SetStringMethod method)
Definition: OgreRenderSystemCapabilitiesSerializer.h:137
Ogre::RenderSystemCapabilitiesSerializer::mCurrentStream
DataStreamPtr mCurrentStream
Definition: OgreRenderSystemCapabilitiesSerializer.h:116
OgreStringVector.h
Ogre::RenderSystemCapabilitiesSerializer::mCurrentLineNumber
int mCurrentLineNumber
Definition: OgreRenderSystemCapabilitiesSerializer.h:114
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::RenderSystemCapabilitiesSerializer
Class for serializing RenderSystemCapabilities to / from a .rendercaps script.
Definition: OgreRenderSystemCapabilitiesSerializer.h:48
Ogre::RenderSystemCapabilitiesSerializer::CapabilitiesLinesList
vector< std::pair< String, int > >::type CapabilitiesLinesList
Definition: OgreRenderSystemCapabilitiesSerializer.h:110
Ogre::RenderSystemCapabilities
singleton class for storing the capabilities of the graphics card.
Definition: OgreRenderSystemCapabilities.h:279
OgreHeaderSuffix.h
Ogre::Capabilities
Capabilities
Enum describing the different hardware capabilities we want to check for OGRE_CAPS_VALUE(a, b) defines each capability.
Definition: OgreRenderSystemCapabilities.h:77
Ogre::RenderSystemCapabilitiesSerializer::callSetStringMethod
void callSetStringMethod(String &keyword, String &val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:142
Ogre::RenderSystemCapabilitiesSerializer::~RenderSystemCapabilitiesSerializer
virtual ~RenderSystemCapabilitiesSerializer()
default destructor
Definition: OgreRenderSystemCapabilitiesSerializer.h:55
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::RenderSystemCapabilitiesSerializer::CapabilitiesMap
map< String, Capabilities >::type CapabilitiesMap
Definition: OgreRenderSystemCapabilitiesSerializer.h:100
Ogre::RenderSystemCapabilitiesSerializer::mCurrentLine
String * mCurrentLine
Definition: OgreRenderSystemCapabilitiesSerializer.h:115
Ogre::RenderSystemCapabilitiesSerializer::mSetStringMethodDispatchTable
SetStringMethodDispatchTable mSetStringMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:83
Ogre::SharedPtr< DataStream >
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::RenderSystemCapabilitiesSerializer::SetStringMethodDispatchTable
map< String, SetStringMethod >::type SetStringMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:82
OgreHeaderPrefix.h
Ogre::RenderSystemCapabilitiesSerializer::addSetIntMethod
void addSetIntMethod(String keyword, SetIntMethod method)
Definition: OgreRenderSystemCapabilitiesSerializer.h:157
Ogre::RenderSystemCapabilitiesSerializer::addKeywordType
void addKeywordType(String keyword, CapabilityKeywordType type)
Definition: OgreRenderSystemCapabilitiesSerializer.h:120
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::ushort
unsigned short ushort
Definition: OgrePrerequisites.h:113
Ogre::RenderSystemCapabilitiesSerializer::setCapabilityEnumBool
void setCapabilityEnumBool(String &name, bool val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:221
Ogre::RenderSystemCapabilitiesSerializer::callSetIntMethod
void callSetIntMethod(String &keyword, ushort val)
Definition: OgreRenderSystemCapabilitiesSerializer.h:162
Ogre::RenderSystemCapabilitiesSerializer::ParseAction
ParseAction
Definition: OgreRenderSystemCapabilitiesSerializer.h:112
Ogre::RenderSystemCapabilitiesSerializer::KeywordTypeMap
map< String, CapabilityKeywordType >::type KeywordTypeMap
Definition: OgreRenderSystemCapabilitiesSerializer.h:77
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::RenderSystemCapabilitiesSerializer::SetBoolMethodDispatchTable
map< String, SetBoolMethod >::type SetBoolMethodDispatchTable
Definition: OgreRenderSystemCapabilitiesSerializer.h:92

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