OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreTerrainMaterialGenerator.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE 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 
37 namespace Ogre
38 {
39  class Terrain;
40 
57  {
66  };
67 
71  {
80 
82  {
83  return source == e.source &&
84  semantic == e.semantic &&
85  elementStart == e.elementStart &&
86  elementCount == e.elementCount;
87  }
88 
90  source(0), semantic(TLSS_ALBEDO), elementStart(0), elementCount(0)
91  {}
92 
94  uint8 elemStart, uint8 elemCount)
95  : source(src), semantic(sem), elementStart(elemStart), elementCount(elemCount)
96  {
97  }
98  };
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 
120  TerrainLayerSampler(const String& aliasName, PixelFormat fmt)
121  : alias(aliasName), format(fmt)
122  {
123  }
124  };
126 
132  {
135 
136  bool operator==(const TerrainLayerDeclaration& dcl) const
137  {
138  return samplers == dcl.samplers && elements == dcl.elements;
139  }
140  };
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() {}
180  TerrainMaterialGenerator* getParent() const { return mParent; }
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 
209  virtual ~TerrainMaterialGenerator();
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  {
227  setActiveProfile(*i);
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  }
246  {
247  // default if not chosen yet
248  if (!mActiveProfile && !mProfiles.empty())
249  mActiveProfile = mProfiles[0];
250 
251  return mActiveProfile;
252  }
253 
255  void _markChanged() { ++mChangeCounter; }
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  {
288  Profile* p = getActiveProfile();
289  if (p)
290  p->requestOptions(terrain);
291 
292  }
295  virtual MaterialPtr generate(const Terrain* terrain)
296  {
297  Profile* p = getActiveProfile();
298  if (!p)
299  return MaterialPtr();
300  else
301  return p->generate(terrain);
302  }
306  {
307  Profile* p = getActiveProfile();
308  if (!p)
309  return MaterialPtr();
310  else
311  return p->generateForCompositeMap(terrain);
312  }
316  virtual void setLightmapEnabled(bool enabled)
317  {
318  Profile* p = getActiveProfile();
319  if (p)
320  return p->setLightmapEnabled(enabled);
321  }
325  virtual uint8 getMaxLayers(const Terrain* terrain) const
326  {
327  Profile* p = getActiveProfile();
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  {
342  Profile* p = getActiveProfile();
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  {
354  Profile* p = getActiveProfile();
355  if (p)
356  p->updateParams(mat, terrain);
357  }
360  virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain)
361  {
362  Profile* p = getActiveProfile();
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  }
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 
395  Texture* _getCompositeMapRTT() { return mCompositeMapRTT; }
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 
418 }
419 #endif
420 
unsigned char uint8
Definition: OgrePlatform.h:346
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
virtual void updateParamsForCompositeMap(const MaterialPtr &mat, const Terrain *terrain)
Update parameters for the given terrain composite map using the active profile.
Class that provides functionality to generate materials for use with a terrain.
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:262
Class providing a much simplified interface to generating manual objects with custom geometry...
Profile(TerrainMaterialGenerator *parent, const String &name, const String &desc)
virtual uint8 getMaxLayers(const Terrain *terrain) const
Get the maximum number of layers supported with the given terrain.
const String & getName() const
Get the name of this profile.
Manages the organisation and rendering of a 'scene' i.e.
Profile * getActiveProfile() const
Get the active profile.
vector< TerrainLayerSampler >::type TerrainLayerSamplerList
Description of a sampler that will be used with each layer.
uint8 elementStart
The colour element at which this element starts.
virtual void requestOptions(Terrain *terrain)
Triggers the generator to request the options that it needs.
TerrainLayerSamplerElement(uint8 src, TerrainLayerSamplerSemantic sem, uint8 elemStart, uint8 elemCount)
virtual void updateParams(const MaterialPtr &mat, const Terrain *terrain)=0
Update params for a terrain.
virtual void setDebugLevel(unsigned int dbg)
Set the debug level of the material.
TerrainLayerSamplerElementList elements
Unknown pixel format.
void _markChanged()
Internal method - indicates that a change has been made that would require material regeneration...
TerrainMaterialGenerator * getParent() const
Get the generator which owns this profile.
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:73
TerrainLayerSampler(const String &aliasName, PixelFormat fmt)
virtual MaterialPtr generate(const Terrain *terrain)=0
Generate / reuse a material for the terrain.
vector< TerrainLayerSamplerElement >::type TerrainLayerSamplerElementList
PixelFormat format
The format required of this texture.
vector< Profile * >::type ProfileList
List of profiles - NB should be ordered in descending complexity.
virtual void setLightmapEnabled(bool enabled)=0
Whether to support a light map over the terrain in the shader, if it's present (default true) ...
virtual void setActiveProfile(const String &name)
Set the active profile by name.
SharedPtr< Material > MaterialPtr
Tangent-space normal information from a detail texture.
PixelFormat
The pixel format used for images, textures, and render surfaces.
bool operator==(const TerrainLayerDeclaration &dcl) const
virtual void updateParams(const MaterialPtr &mat, const Terrain *terrain)
Update parameters for the given terrain using the active profile.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
bool operator==(const TerrainLayerSamplerElement &e) const
virtual MaterialPtr generateForCompositeMap(const Terrain *terrain)=0
Generate / reuse a material for the terrain.
#define _OgreTerrainExport
Albedo colour (diffuse reflectance colour)
virtual void requestOptions(Terrain *terrain)=0
Request the options needed from the terrain.
Height information for the detail texture.
virtual void updateCompositeMap(const Terrain *terrain, const Rect &rect)
Update the composite map for a terrain.
unsigned long long int getChangeCount() const
Returns the number of times the generator has undergone a change which would require materials to be ...
virtual MaterialPtr generateForCompositeMap(const Terrain *terrain)
Generate a material for the given composite map of the terrain using the active profile.
The definition of the information each layer will contain in this terrain.
TerrainLayerSamplerSemantic semantic
The semantic this element represents.
virtual void setLightmapEnabled(bool enabled)
Whether to support a light map over the terrain in the shader, if it's present (default true)...
String alias
A descriptive name that is merely used to assist in recognition.
virtual void setActiveProfile(Profile *p)
Set the active Profile.
virtual const ProfileList & getProfiles() const
Get the list of profiles that this generator supports.
virtual MaterialPtr generate(const Terrain *terrain)
Generate a material for the given terrain using the active profile.
virtual unsigned int getDebugLevel() const
Get the debug level of the material.
SharedPtr< TerrainMaterialGenerator > TerrainMaterialGeneratorPtr
virtual void updateCompositeMap(const Terrain *terrain, const Rect &rect)
Update the composite map for a terrain.
virtual void updateParamsForCompositeMap(const MaterialPtr &mat, const Terrain *terrain)=0
Update params for a terrain.
uint8 source
The source sampler index of this element relative to LayerDeclaration's list.
virtual bool isVertexCompressionSupported() const
Return whether this material generator supports using a compressed vertex format. ...
_StringBase String
bool operator==(const TerrainLayerSampler &s) const
uint8 elementCount
The number of colour elements this semantic uses (usually standard per semantic)
Inner class which should also be subclassed to provide profile-specific material generation.
Abstract class representing a Texture resource.
Definition: OgreTexture.h:102
const String & getDescription() const
Get the description of this profile.
TerrainLayerSamplerSemantic
Enumeration of types of data that can be read from textures that are specific to a given layer...
virtual const TerrainLayerDeclaration & getLayerDeclaration() const
Get the layer declaration that this material generator operates with.
virtual bool canGenerateUsingDeclaration(const TerrainLayerDeclaration &decl)
Whether this generator can generate a material for a given declaration.
Information about one element of a sampler / texture within a layer.
virtual uint8 getMaxLayers(const Terrain *terrain) const =0
Get the number of layers supported.