OgreTerrainMaterialGenerator.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 __Ogre_TerrainMaterialGenerator_H__
#define __Ogre_TerrainMaterialGenerator_H__
#include "OgreTerrainPrerequisites.h"
#include "OgrePixelFormat.h"
#include "OgreMaterial.h"
#include "OgreTexture.h"
namespace Ogre
{
class Terrain;
enum TerrainLayerSamplerSemantic
{
TLSS_ALBEDO = 0,
TLSS_NORMAL = 1,
TLSS_HEIGHT = 2,
TLSS_SPECULAR = 3
};
struct _OgreTerrainExport TerrainLayerSamplerElement
{
uint8 source;
TerrainLayerSamplerSemantic semantic;
uint8 elementStart;
uint8 elementCount;
bool operator==(const TerrainLayerSamplerElement& e) const
{
return source == e.source &&
semantic == e.semantic &&
elementStart == e.elementStart &&
elementCount == e.elementCount;
}
TerrainLayerSamplerElement() :
source(0), semantic(TLSS_ALBEDO), elementStart(0), elementCount(0)
{}
TerrainLayerSamplerElement(uint8 src, TerrainLayerSamplerSemantic sem,
uint8 elemStart, uint8 elemCount)
: source(src), semantic(sem), elementStart(elemStart), elementCount(elemCount)
{
}
};
typedef vector<TerrainLayerSamplerElement>::type TerrainLayerSamplerElementList;
struct _OgreTerrainExport TerrainLayerSampler
{
String alias;
PixelFormat format;
bool operator==(const TerrainLayerSampler& s) const
{
return alias == s.alias && format == s.format;
}
TerrainLayerSampler()
: alias(""), format(PF_UNKNOWN)
{
}
TerrainLayerSampler(const String& aliasName, PixelFormat fmt)
: alias(aliasName), format(fmt)
{
}
};
typedef vector<TerrainLayerSampler>::type TerrainLayerSamplerList;
struct _OgreTerrainExport TerrainLayerDeclaration
{
TerrainLayerSamplerList samplers;
TerrainLayerSamplerElementList elements;
bool operator==(const TerrainLayerDeclaration& dcl) const
{
return samplers == dcl.samplers && elements == dcl.elements;
}
};
class _OgreTerrainExport TerrainMaterialGenerator : public TerrainAlloc
{
public:
class _OgreTerrainExport Profile : public TerrainAlloc
{
protected:
TerrainMaterialGenerator* mParent;
String mName;
String mDesc;
public:
Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc)
: mParent(parent), mName(name), mDesc(desc) {}
Profile(const Profile& prof)
: mParent(prof.mParent), mName(prof.mName), mDesc(prof.mDesc) {}
virtual ~Profile() {}
TerrainMaterialGenerator* getParent() const { return mParent; }
const String& getName() const { return mName; }
const String& getDescription() const { return mDesc; }
virtual bool isVertexCompressionSupported() const = 0;
virtual MaterialPtr generate(const Terrain* terrain) = 0;
virtual MaterialPtr generateForCompositeMap(const Terrain* terrain) = 0;
virtual void setLightmapEnabled(bool enabled) = 0;
virtual uint8 getMaxLayers(const Terrain* terrain) const = 0;
virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect);
virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain) = 0;
virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain) = 0;
virtual void requestOptions(Terrain* terrain) = 0;
};
TerrainMaterialGenerator();
virtual ~TerrainMaterialGenerator();
typedef vector<Profile*>::type ProfileList;
virtual const ProfileList& getProfiles() const { return mProfiles; }
virtual void setActiveProfile(const String& name)
{
if (!mActiveProfile || mActiveProfile->getName() != name)
{
for (ProfileList::iterator i = mProfiles.begin(); i != mProfiles.end(); ++i)
{
if ((*i)->getName() == name)
{
setActiveProfile(*i);
break;
}
}
}
}
virtual void setActiveProfile(Profile* p)
{
if (mActiveProfile != p)
{
mActiveProfile = p;
_markChanged();
}
}
Profile* getActiveProfile() const
{
// default if not chosen yet
if (!mActiveProfile && !mProfiles.empty())
mActiveProfile = mProfiles[0];
return mActiveProfile;
}
void _markChanged() { ++mChangeCounter; }
unsigned long long int getChangeCount() const { return mChangeCounter; }
virtual const TerrainLayerDeclaration& getLayerDeclaration() const { return mLayerDecl; }
virtual bool canGenerateUsingDeclaration(const TerrainLayerDeclaration& decl)
{
return decl == mLayerDecl;
}
virtual bool isVertexCompressionSupported() const
{
return getActiveProfile()->isVertexCompressionSupported();
}
virtual void requestOptions(Terrain* terrain)
{
Profile* p = getActiveProfile();
if (p)
p->requestOptions(terrain);
}
virtual MaterialPtr generate(const Terrain* terrain)
{
Profile* p = getActiveProfile();
if (!p)
return MaterialPtr();
else
return p->generate(terrain);
}
virtual MaterialPtr generateForCompositeMap(const Terrain* terrain)
{
Profile* p = getActiveProfile();
if (!p)
return MaterialPtr();
else
return p->generateForCompositeMap(terrain);
}
virtual void setLightmapEnabled(bool enabled)
{
Profile* p = getActiveProfile();
if (p)
return p->setLightmapEnabled(enabled);
}
virtual uint8 getMaxLayers(const Terrain* terrain) const
{
Profile* p = getActiveProfile();
if (p)
return p->getMaxLayers(terrain);
else
return 0;
}
virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect)
{
Profile* p = getActiveProfile();
if (!p)
return;
else
p->updateCompositeMap(terrain, rect);
}
virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain)
{
Profile* p = getActiveProfile();
if (p)
p->updateParams(mat, terrain);
}
virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain)
{
Profile* p = getActiveProfile();
if (p)
p->updateParamsForCompositeMap(mat, terrain);
}
virtual void setDebugLevel(unsigned int dbg)
{
if (mDebugLevel != dbg)
{
mDebugLevel = dbg;
_markChanged();
}
}
virtual unsigned int getDebugLevel() const { return mDebugLevel; }
virtual void _renderCompositeMap(size_t size, const Rect& rect,
const MaterialPtr& mat, const TexturePtr& destCompositeMap);
Texture* _getCompositeMapRTT() { return mCompositeMapRTT; }
protected:
ProfileList mProfiles;
mutable Profile* mActiveProfile;
unsigned long long int mChangeCounter;
TerrainLayerDeclaration mLayerDecl;
unsigned int mDebugLevel;
SceneManager* mCompositeMapSM;
Camera* mCompositeMapCam;
Texture* mCompositeMapRTT; // deliberately holding this by raw pointer to avoid shutdown issues
ManualObject* mCompositeMapPlane;
Light* mCompositeMapLight;
};
typedef SharedPtr<TerrainMaterialGenerator> TerrainMaterialGeneratorPtr;
}
#endif
Ogre::TerrainMaterialGenerator::Profile
Inner class which should also be subclassed to provide profile-specific material generation.
Definition: OgreTerrainMaterialGenerator.h:167
Ogre::TerrainLayerSamplerElement::operator==
bool operator==(const TerrainLayerSamplerElement &e) const
Definition: OgreTerrainMaterialGenerator.h:81
Ogre::TerrainMaterialGenerator::updateParams
virtual void updateParams(const MaterialPtr &mat, const Terrain *terrain)
Update parameters for the given terrain using the active profile.
Definition: OgreTerrainMaterialGenerator.h:352
Ogre::TerrainMaterialGenerator::Profile::getMaxLayers
virtual uint8 getMaxLayers(const Terrain *terrain) const =0
Get the number of layers supported.
Ogre::TerrainMaterialGenerator::mCompositeMapRTT
Texture * mCompositeMapRTT
Definition: OgreTerrainMaterialGenerator.h:405
Ogre::TLSS_ALBEDO
Albedo colour (diffuse reflectance colour)
Definition: OgreTerrainMaterialGenerator.h:59
Ogre::TerrainLayerSampler::TerrainLayerSampler
TerrainLayerSampler()
Definition: OgreTerrainMaterialGenerator.h:115
Ogre::TerrainMaterialGenerator::setDebugLevel
virtual void setDebugLevel(unsigned int dbg)
Set the debug level of the material.
Definition: OgreTerrainMaterialGenerator.h:375
Ogre::PF_UNKNOWN
Unknown pixel format.
Definition: OgrePixelFormat.h:46
Ogre::TerrainMaterialGenerator::Profile::getName
const String & getName() const
Get the name of this profile.
Definition: OgreTerrainMaterialGenerator.h:182
OgrePixelFormat.h
Ogre::TerrainLayerSamplerElement::semantic
TerrainLayerSamplerSemantic semantic
The semantic this element represents.
Definition: OgreTerrainMaterialGenerator.h:75
Ogre::TerrainMaterialGenerator::getChangeCount
unsigned long long int getChangeCount() const
Returns the number of times the generator has undergone a change which would require materials to be ...
Definition: OgreTerrainMaterialGenerator.h:260
Ogre::TerrainMaterialGenerator::ProfileList
vector< Profile * >::type ProfileList
List of profiles - NB should be ordered in descending complexity.
Definition: OgreTerrainMaterialGenerator.h:212
Ogre::TerrainMaterialGenerator::updateParamsForCompositeMap
virtual void updateParamsForCompositeMap(const MaterialPtr &mat, const Terrain *terrain)
Update parameters for the given terrain composite map using the active profile.
Definition: OgreTerrainMaterialGenerator.h:360
Ogre::TRect< long >
Ogre::PixelFormat
PixelFormat
The pixel format used for images, textures, and render surfaces.
Definition: OgrePixelFormat.h:43
Ogre::TerrainMaterialGenerator::Profile::~Profile
virtual ~Profile()
Definition: OgreTerrainMaterialGenerator.h:178
Ogre::TerrainLayerSampler::alias
String alias
A descriptive name that is merely used to assist in recognition.
Definition: OgreTerrainMaterialGenerator.h:106
Ogre::TerrainLayerDeclaration::elements
TerrainLayerSamplerElementList elements
Definition: OgreTerrainMaterialGenerator.h:134
Ogre::TerrainMaterialGenerator::getMaxLayers
virtual uint8 getMaxLayers(const Terrain *terrain) const
Get the maximum number of layers supported with the given terrain.
Definition: OgreTerrainMaterialGenerator.h:325
Ogre::Texture
Abstract class representing a Texture resource.
Definition: OgreTexture.h:102
Ogre::TerrainMaterialGenerator::isVertexCompressionSupported
virtual bool isVertexCompressionSupported() const
Return whether this material generator supports using a compressed vertex format. ...
Definition: OgreTerrainMaterialGenerator.h:279
Ogre::TerrainMaterialGenerator::setActiveProfile
virtual void setActiveProfile(const String &name)
Set the active profile by name.
Definition: OgreTerrainMaterialGenerator.h:219
Ogre::ManualObject
Class providing a much simplified interface to generating manual objects with custom geometry...
Definition: OgreManualObject.h:106
Ogre::TerrainMaterialGenerator::mLayerDecl
TerrainLayerDeclaration mLayerDecl
Definition: OgreTerrainMaterialGenerator.h:401
Ogre::TerrainMaterialGenerator::Profile::Profile
Profile(TerrainMaterialGenerator *parent, const String &name, const String &desc)
Definition: OgreTerrainMaterialGenerator.h:174
Ogre::TerrainMaterialGenerator::mCompositeMapLight
Light * mCompositeMapLight
Definition: OgreTerrainMaterialGenerator.h:407
Ogre::MaterialPtr
SharedPtr< Material > MaterialPtr
Definition: OgrePrerequisites.h:314
Ogre::TerrainLayerSamplerElement::TerrainLayerSamplerElement
TerrainLayerSamplerElement()
Definition: OgreTerrainMaterialGenerator.h:89
Ogre::TerrainLayerDeclaration::operator==
bool operator==(const TerrainLayerDeclaration &dcl) const
Definition: OgreTerrainMaterialGenerator.h:136
Ogre::TerrainMaterialGenerator::mDebugLevel
unsigned int mDebugLevel
Definition: OgreTerrainMaterialGenerator.h:402
Ogre::Terrain
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:262
Ogre::TLSS_SPECULAR
Specular reflectance.
Definition: OgreTerrainMaterialGenerator.h:65
Ogre::TerrainMaterialGenerator::getActiveProfile
Profile * getActiveProfile() const
Get the active profile.
Definition: OgreTerrainMaterialGenerator.h:245
OgreTexture.h
Ogre::TerrainMaterialGenerator::Profile::getParent
TerrainMaterialGenerator * getParent() const
Get the generator which owns this profile.
Definition: OgreTerrainMaterialGenerator.h:180
Ogre::TerrainMaterialGenerator
Class that provides functionality to generate materials for use with a terrain.
Definition: OgreTerrainMaterialGenerator.h:161
Ogre::TerrainMaterialGenerator::Profile::updateCompositeMap
virtual void updateCompositeMap(const Terrain *terrain, const Rect &rect)
Update the composite map for a terrain.
Ogre::TLSS_HEIGHT
Height information for the detail texture.
Definition: OgreTerrainMaterialGenerator.h:63
Ogre::uint8
unsigned char uint8
Definition: OgrePlatform.h:361
Ogre::TerrainMaterialGenerator::Profile::Profile
Profile(const Profile &prof)
Definition: OgreTerrainMaterialGenerator.h:176
Ogre::TerrainMaterialGenerator::mChangeCounter
unsigned long long int mChangeCounter
Definition: OgreTerrainMaterialGenerator.h:400
Ogre::TerrainMaterialGenerator::getDebugLevel
virtual unsigned int getDebugLevel() const
Get the debug level of the material.
Definition: OgreTerrainMaterialGenerator.h:384
_OgreTerrainExport
#define _OgreTerrainExport
Definition: OgreTerrainPrerequisites.h:58
Ogre::TerrainLayerSamplerElement::elementCount
uint8 elementCount
The number of colour elements this semantic uses (usually standard per semantic)
Definition: OgreTerrainMaterialGenerator.h:79
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::TerrainMaterialGenerator::setActiveProfile
virtual void setActiveProfile(Profile *p)
Set the active Profile.
Definition: OgreTerrainMaterialGenerator.h:236
Ogre::TerrainMaterialGenerator::Profile::setLightmapEnabled
virtual void setLightmapEnabled(bool enabled)=0
Whether to support a light map over the terrain in the shader, if it&#39;s present (default true) ...
Ogre::TerrainMaterialGenerator::Profile::mName
String mName
Definition: OgreTerrainMaterialGenerator.h:171
Ogre::TerrainLayerSamplerElementList
vector< TerrainLayerSamplerElement >::type TerrainLayerSamplerElementList
Definition: OgreTerrainMaterialGenerator.h:99
Ogre::TerrainMaterialGenerator::getLayerDeclaration
virtual const TerrainLayerDeclaration & getLayerDeclaration() const
Get the layer declaration that this material generator operates with.
Definition: OgreTerrainMaterialGenerator.h:264
Ogre::TerrainMaterialGenerator::mProfiles
ProfileList mProfiles
Definition: OgreTerrainMaterialGenerator.h:398
Ogre::TerrainMaterialGeneratorPtr
SharedPtr< TerrainMaterialGenerator > TerrainMaterialGeneratorPtr
Definition: OgreTerrainMaterialGenerator.h:413
Ogre::TerrainLayerSampler::operator==
bool operator==(const TerrainLayerSampler &s) const
Definition: OgreTerrainMaterialGenerator.h:110
Ogre::Camera
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Ogre::TerrainLayerSamplerElement::elementStart
uint8 elementStart
The colour element at which this element starts.
Definition: OgreTerrainMaterialGenerator.h:77
Ogre::TerrainLayerSamplerSemantic
TerrainLayerSamplerSemantic
Enumeration of types of data that can be read from textures that are specific to a given layer...
Definition: OgreTerrainMaterialGenerator.h:56
Ogre::TerrainLayerSamplerList
vector< TerrainLayerSampler >::type TerrainLayerSamplerList
Definition: OgreTerrainMaterialGenerator.h:125
Ogre::TerrainMaterialGenerator::Profile::generateForCompositeMap
virtual MaterialPtr generateForCompositeMap(const Terrain *terrain)=0
Generate / reuse a material for the terrain.
Ogre::TerrainMaterialGenerator::requestOptions
virtual void requestOptions(Terrain *terrain)
Triggers the generator to request the options that it needs.
Definition: OgreTerrainMaterialGenerator.h:286
Ogre::TerrainLayerSampler::TerrainLayerSampler
TerrainLayerSampler(const String &aliasName, PixelFormat fmt)
Definition: OgreTerrainMaterialGenerator.h:120
Ogre::TerrainMaterialGenerator::Profile::getDescription
const String & getDescription() const
Get the description of this profile.
Definition: OgreTerrainMaterialGenerator.h:184
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::TerrainLayerSampler
Description of a sampler that will be used with each layer.
Definition: OgreTerrainMaterialGenerator.h:103
Ogre::TerrainLayerDeclaration
The definition of the information each layer will contain in this terrain.
Definition: OgreTerrainMaterialGenerator.h:131
Ogre::TerrainMaterialGenerator::_getCompositeMapRTT
Texture * _getCompositeMapRTT()
Definition: OgreTerrainMaterialGenerator.h:395
Ogre::TerrainMaterialGenerator::updateCompositeMap
virtual void updateCompositeMap(const Terrain *terrain, const Rect &rect)
Update the composite map for a terrain.
Definition: OgreTerrainMaterialGenerator.h:340
Ogre::TerrainLayerSamplerElement::TerrainLayerSamplerElement
TerrainLayerSamplerElement(uint8 src, TerrainLayerSamplerSemantic sem, uint8 elemStart, uint8 elemCount)
Definition: OgreTerrainMaterialGenerator.h:93
Ogre::TerrainMaterialGenerator::mCompositeMapPlane
ManualObject * mCompositeMapPlane
Definition: OgreTerrainMaterialGenerator.h:406
Ogre::SharedPtr< Material >
Ogre::TerrainLayerDeclaration::samplers
TerrainLayerSamplerList samplers
Definition: OgreTerrainMaterialGenerator.h:133
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::TerrainMaterialGenerator::mActiveProfile
Profile * mActiveProfile
Definition: OgreTerrainMaterialGenerator.h:399
Ogre::TerrainMaterialGenerator::_markChanged
void _markChanged()
Internal method - indicates that a change has been made that would require material regeneration...
Definition: OgreTerrainMaterialGenerator.h:255
Ogre::TerrainLayerSamplerElement
Information about one element of a sampler / texture within a layer.
Definition: OgreTerrainMaterialGenerator.h:70
Ogre::TerrainMaterialGenerator::Profile::updateParams
virtual void updateParams(const MaterialPtr &mat, const Terrain *terrain)=0
Update params for a terrain.
Ogre::TerrainLayerSampler::format
PixelFormat format
The format required of this texture.
Definition: OgreTerrainMaterialGenerator.h:108
OgreTerrainPrerequisites.h
Ogre::TerrainMaterialGenerator::mCompositeMapCam
Camera * mCompositeMapCam
Definition: OgreTerrainMaterialGenerator.h:404
Ogre::TerrainMaterialGenerator::setLightmapEnabled
virtual void setLightmapEnabled(bool enabled)
Whether to support a light map over the terrain in the shader, if it&#39;s present (default true)...
Definition: OgreTerrainMaterialGenerator.h:316
Ogre::TerrainMaterialGenerator::generate
virtual MaterialPtr generate(const Terrain *terrain)
Generate a material for the given terrain using the active profile.
Definition: OgreTerrainMaterialGenerator.h:295
Ogre::TerrainMaterialGenerator::Profile::generate
virtual MaterialPtr generate(const Terrain *terrain)=0
Generate / reuse a material for the terrain.
OgreMaterial.h
Ogre::TLSS_NORMAL
Tangent-space normal information from a detail texture.
Definition: OgreTerrainMaterialGenerator.h:61
Ogre::TerrainLayerSamplerElement::source
uint8 source
The source sampler index of this element relative to LayerDeclaration&#39;s list.
Definition: OgreTerrainMaterialGenerator.h:73
Ogre::TerrainMaterialGenerator::canGenerateUsingDeclaration
virtual bool canGenerateUsingDeclaration(const TerrainLayerDeclaration &decl)
Whether this generator can generate a material for a given declaration.
Definition: OgreTerrainMaterialGenerator.h:271
Ogre::SceneManager
Manages the organisation and rendering of a &#39;scene&#39; i.e.
Definition: OgreSceneManager.h:143
Ogre::TerrainMaterialGenerator::mCompositeMapSM
SceneManager * mCompositeMapSM
Definition: OgreTerrainMaterialGenerator.h:403
Ogre::TerrainMaterialGenerator::Profile::updateParamsForCompositeMap
virtual void updateParamsForCompositeMap(const MaterialPtr &mat, const Terrain *terrain)=0
Update params for a terrain.
Ogre::TerrainMaterialGenerator::Profile::requestOptions
virtual void requestOptions(Terrain *terrain)=0
Request the options needed from the terrain.
Ogre::TerrainMaterialGenerator::generateForCompositeMap
virtual MaterialPtr generateForCompositeMap(const Terrain *terrain)
Generate a material for the given composite map of the terrain using the active profile.
Definition: OgreTerrainMaterialGenerator.h:305
Ogre::TerrainMaterialGenerator::getProfiles
virtual const ProfileList & getProfiles() const
Get the list of profiles that this generator supports.
Definition: OgreTerrainMaterialGenerator.h:216
Ogre::Light
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:73
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::TerrainMaterialGenerator::Profile::mDesc
String mDesc
Definition: OgreTerrainMaterialGenerator.h:172
Ogre::TerrainMaterialGenerator::Profile::mParent
TerrainMaterialGenerator * mParent
Definition: OgreTerrainMaterialGenerator.h:170

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