OGRE  1.9.0
OgreTerrainMaterialGenerator.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
29#ifndef __Ogre_TerrainMaterialGenerator_H__
30#define __Ogre_TerrainMaterialGenerator_H__
31
33#include "OgrePixelFormat.h"
34#include "OgreMaterial.h"
35#include "OgreTexture.h"
36
37namespace Ogre
38{
39 class Terrain;
40
48
49
67
100
104 {
109
110 bool operator==(const TerrainLayerSampler& s) const
111 {
112 return alias == s.alias && format == s.format;
113 }
114
116 : alias(""), format(PF_UNKNOWN)
117 {
118 }
119
121 : alias(aliasName), format(fmt)
122 {
123 }
124 };
126
141
162 {
163 public:
168 {
169 protected:
173 public:
174 Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc)
175 : mParent(parent), mName(name), mDesc(desc) {}
176 Profile(const Profile& prof)
177 : mParent(prof.mParent), mName(prof.mName), mDesc(prof.mDesc) {}
178 virtual ~Profile() {}
182 const String& getName() const { return mName; }
184 const String& getDescription() const { return mDesc; }
186 virtual bool isVertexCompressionSupported() const = 0;
188 virtual MaterialPtr generate(const Terrain* terrain) = 0;
190 virtual MaterialPtr generateForCompositeMap(const Terrain* terrain) = 0;
192 virtual void setLightmapEnabled(bool enabled) = 0;
194 virtual uint8 getMaxLayers(const Terrain* terrain) const = 0;
196 virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect);
197
199 virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain) = 0;
201 virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain) = 0;
202
204 virtual void requestOptions(Terrain* terrain) = 0;
205
206 };
207
210
213
216 virtual const ProfileList& getProfiles() const { return mProfiles; }
217
219 virtual void setActiveProfile(const String& name)
220 {
221 if (!mActiveProfile || mActiveProfile->getName() != name)
222 {
223 for (ProfileList::iterator i = mProfiles.begin(); i != mProfiles.end(); ++i)
224 {
225 if ((*i)->getName() == name)
226 {
228 break;
229 }
230 }
231 }
232
233 }
234
236 virtual void setActiveProfile(Profile* p)
237 {
238 if (mActiveProfile != p)
239 {
240 mActiveProfile = p;
241 _markChanged();
242 }
243 }
244
246 {
247 // default if not chosen yet
248 if (!mActiveProfile && !mProfiles.empty())
250
251 return mActiveProfile;
252 }
253
256
260 unsigned long long int getChangeCount() const { return mChangeCounter; }
261
264 virtual const TerrainLayerDeclaration& getLayerDeclaration() const { return mLayerDecl; }
272 {
273 return decl == mLayerDecl;
274 }
275
279 virtual bool isVertexCompressionSupported() const
280 {
281 return getActiveProfile()->isVertexCompressionSupported();
282 }
283
286 virtual void requestOptions(Terrain* terrain)
287 {
289 if (p)
290 p->requestOptions(terrain);
291
292 }
293
295 virtual MaterialPtr generate(const Terrain* terrain)
296 {
298 if (!p)
299 return MaterialPtr();
300 else
301 return p->generate(terrain);
302 }
303
306 {
308 if (!p)
309 return MaterialPtr();
310 else
311 return p->generateForCompositeMap(terrain);
312 }
313
316 virtual void setLightmapEnabled(bool enabled)
317 {
319 if (p)
320 return p->setLightmapEnabled(enabled);
321 }
322
325 virtual uint8 getMaxLayers(const Terrain* terrain) const
326 {
328 if (p)
329 return p->getMaxLayers(terrain);
330 else
331 return 0;
332 }
333
340 virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect)
341 {
343 if (!p)
344 return;
345 else
346 p->updateCompositeMap(terrain, rect);
347 }
348
349
352 virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain)
353 {
355 if (p)
356 p->updateParams(mat, terrain);
357 }
358
360 virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain)
361 {
363 if (p)
364 p->updateParamsForCompositeMap(mat, terrain);
365 }
366
375 virtual void setDebugLevel(unsigned int dbg)
376 {
377 if (mDebugLevel != dbg)
378 {
379 mDebugLevel = dbg;
380 _markChanged();
381 }
382 }
383
384 virtual unsigned int getDebugLevel() const { return mDebugLevel; }
385
392 virtual void _renderCompositeMap(size_t size, const Rect& rect,
393 const MaterialPtr& mat, const TexturePtr& destCompositeMap);
394
396 protected:
397
400 unsigned long long int mChangeCounter;
402 unsigned int mDebugLevel;
405 Texture* mCompositeMapRTT; // deliberately holding this by raw pointer to avoid shutdown issues
408
409
410
411 };
412
414
417
418}
419#endif
420
#define _OgreTerrainExport
A viewpoint from which the scene will be rendered.
Definition OgreCamera.h:87
Representation of a dynamic light source in the scene.
Definition OgreLight.h:74
Class providing a much simplified interface to generating manual objects with custom geometry.
Manages the organisation and rendering of a 'scene' i.e.
Reference-counted shared pointer, used for objects where implicit destruction is required.
Inner class which should also be subclassed to provide profile-specific material generation.
virtual MaterialPtr generate(const Terrain *terrain)=0
Generate / reuse a material for the terrain.
virtual uint8 getMaxLayers(const Terrain *terrain) const =0
Get the number of layers supported.
virtual void setLightmapEnabled(bool enabled)=0
Whether to support a light map over the terrain in the shader, if it's present (default true)
TerrainMaterialGenerator * getParent() const
Get the generator which owns this profile.
virtual MaterialPtr generateForCompositeMap(const Terrain *terrain)=0
Generate / reuse a material for the terrain.
const String & getName() const
Get the name of this profile.
virtual void updateParams(const MaterialPtr &mat, const Terrain *terrain)=0
Update params for a terrain.
virtual void updateCompositeMap(const Terrain *terrain, const Rect &rect)
Update the composite map for a terrain.
const String & getDescription() const
Get the description of this profile.
virtual void updateParamsForCompositeMap(const MaterialPtr &mat, const Terrain *terrain)=0
Update params for a terrain.
virtual bool isVertexCompressionSupported() const =0
Compressed vertex format supported?
virtual void requestOptions(Terrain *terrain)=0
Request the options needed from the terrain.
Profile(TerrainMaterialGenerator *parent, const String &name, const String &desc)
virtual void setActiveProfile(Profile *p)
Set the active Profile.
virtual void updateParamsForCompositeMap(const MaterialPtr &mat, const Terrain *terrain)
Update parameters for the given terrain composite map using the active profile.
vector< Profile * >::type ProfileList
List of profiles - NB should be ordered in descending complexity.
Profile * getActiveProfile() const
Get the active profile.
virtual uint8 getMaxLayers(const Terrain *terrain) const
Get the maximum number of layers supported with the given terrain.
virtual bool isVertexCompressionSupported() const
Return whether this material generator supports using a compressed vertex format.
unsigned long long int getChangeCount() const
Returns the number of times the generator has undergone a change which would require materials to be ...
virtual bool canGenerateUsingDeclaration(const TerrainLayerDeclaration &decl)
Whether this generator can generate a material for a given declaration.
virtual void setLightmapEnabled(bool enabled)
Whether to support a light map over the terrain in the shader, if it's present (default true).
virtual const TerrainLayerDeclaration & getLayerDeclaration() const
Get the layer declaration that this material generator operates with.
virtual MaterialPtr generate(const Terrain *terrain)
Generate a material for the given terrain using the active profile.
virtual void updateCompositeMap(const Terrain *terrain, const Rect &rect)
Update the composite map for a terrain.
virtual void setActiveProfile(const String &name)
Set the active profile by name.
virtual void _renderCompositeMap(size_t size, const Rect &rect, const MaterialPtr &mat, const TexturePtr &destCompositeMap)
Helper method to render a composite map.
virtual const ProfileList & getProfiles() const
Get the list of profiles that this generator supports.
virtual unsigned int getDebugLevel() const
Get the debug level of the material.
virtual MaterialPtr generateForCompositeMap(const Terrain *terrain)
Generate a material for the given composite map of the terrain using the active profile.
virtual void setDebugLevel(unsigned int dbg)
Set the debug level of the material.
void _markChanged()
Internal method - indicates that a change has been made that would require material regeneration.
virtual void updateParams(const MaterialPtr &mat, const Terrain *terrain)
Update parameters for the given terrain using the active profile.
virtual void requestOptions(Terrain *terrain)
Triggers the generator to request the options that it needs.
The main containing class for a chunk of terrain.
Abstract class representing a Texture resource.
TRect< long > Rect
Structure used to define a rectangle in a 2-D integer space.
Definition OgreCommon.h:653
PixelFormat
The pixel format used for images, textures, and render surfaces.
@ PF_UNKNOWN
Unknown pixel format.
SharedPtr< TerrainMaterialGenerator > TerrainMaterialGeneratorPtr
TerrainLayerSamplerSemantic
Enumeration of types of data that can be read from textures that are specific to a given layer.
vector< TerrainLayerSampler >::type TerrainLayerSamplerList
vector< TerrainLayerSamplerElement >::type TerrainLayerSamplerElementList
@ TLSS_ALBEDO
Albedo colour (diffuse reflectance colour)
@ TLSS_HEIGHT
Height information for the detail texture.
@ TLSS_SPECULAR
Specular reflectance.
@ TLSS_NORMAL
Tangent-space normal information from a detail texture.
unsigned char uint8
SharedPtr< Material > MaterialPtr
SharedPtr< Texture > TexturePtr
GeneralAllocatedObject TerrainAlloc
_StringBase String
The definition of the information each layer will contain in this terrain.
bool operator==(const TerrainLayerDeclaration &dcl) const
TerrainLayerSamplerElementList elements
uint8 elementCount
The number of colour elements this semantic uses (usually standard per semantic)
uint8 elementStart
The colour element at which this element starts.
uint8 source
The source sampler index of this element relative to LayerDeclaration's list.
bool operator==(const TerrainLayerSamplerElement &e) const
TerrainLayerSamplerElement(uint8 src, TerrainLayerSamplerSemantic sem, uint8 elemStart, uint8 elemCount)
TerrainLayerSamplerSemantic semantic
The semantic this element represents.
TerrainLayerSampler(const String &aliasName, PixelFormat fmt)
bool operator==(const TerrainLayerSampler &s) const
PixelFormat format
The format required of this texture.
String alias
A descriptive name that is merely used to assist in recognition.
std::vector< T, A > type