OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 
91  uint8 elemStart, uint8 elemCount)
92  : source(src), semantic(sem), elementStart(elemStart), elementCount(elemCount)
93  {
94  }
95  };
97 
101  {
106 
107  bool operator==(const TerrainLayerSampler& s) const
108  {
109  return alias == s.alias && format == s.format;
110  }
111 
113 
114  TerrainLayerSampler(const String& aliasName, PixelFormat fmt)
115  : alias(aliasName), format(fmt)
116  {
117  }
118  };
120 
126  {
129 
130  bool operator==(const TerrainLayerDeclaration& dcl) const
131  {
132  return samplers == dcl.samplers && elements == dcl.elements;
133  }
134  };
135 
156  {
157  public:
162  {
163  protected:
167  public:
168  Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc)
169  : mParent(parent), mName(name), mDesc(desc) {}
170  Profile(const Profile& prof)
171  : mParent(prof.mParent), mName(prof.mName), mDesc(prof.mDesc) {}
172  virtual ~Profile() {}
174  TerrainMaterialGenerator* getParent() const { return mParent; }
176  const String& getName() const { return mName; }
178  const String& getDescription() const { return mDesc; }
179 
181  virtual MaterialPtr generate(const Terrain* terrain) = 0;
183  virtual MaterialPtr generateForCompositeMap(const Terrain* terrain) = 0;
185  virtual uint8 getMaxLayers(const Terrain* terrain) const = 0;
187  virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect);
188 
190  virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain) = 0;
192  virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain) = 0;
193 
195  virtual void requestOptions(Terrain* terrain) = 0;
196 
197  };
198 
200  virtual ~TerrainMaterialGenerator();
201 
204 
207  virtual const ProfileList& getProfiles() const { return mProfiles; }
208 
210  virtual void setActiveProfile(const String& name)
211  {
212  if (!mActiveProfile || mActiveProfile->getName() != name)
213  {
214  for (ProfileList::iterator i = mProfiles.begin(); i != mProfiles.end(); ++i)
215  {
216  if ((*i)->getName() == name)
217  {
218  setActiveProfile(*i);
219  break;
220  }
221  }
222  }
223 
224  }
225 
227  virtual void setActiveProfile(Profile* p)
228  {
229  if (mActiveProfile != p)
230  {
231  mActiveProfile = p;
232  _markChanged();
233  }
234  }
237  {
238  // default if not chosen yet
239  if (!mActiveProfile && !mProfiles.empty())
240  mActiveProfile = mProfiles[0];
241 
242  return mActiveProfile;
243  }
244 
246  void _markChanged() { ++mChangeCounter; }
247 
251  unsigned long long int getChangeCount() const { return mChangeCounter; }
252 
255  virtual const TerrainLayerDeclaration& getLayerDeclaration() const { return mLayerDecl; }
263  {
264  return decl == mLayerDecl;
265  }
266 
269  virtual void requestOptions(Terrain* terrain)
270  {
271  Profile* p = getActiveProfile();
272  if (p)
273  p->requestOptions(terrain);
274 
275  }
278  virtual MaterialPtr generate(const Terrain* terrain)
279  {
280  Profile* p = getActiveProfile();
281  if (!p)
282  return MaterialPtr();
283  else
284  return p->generate(terrain);
285  }
289  {
290  Profile* p = getActiveProfile();
291  if (!p)
292  return MaterialPtr();
293  else
294  return p->generateForCompositeMap(terrain);
295  }
299  virtual uint8 getMaxLayers(const Terrain* terrain) const
300  {
301  Profile* p = getActiveProfile();
302  if (p)
303  return p->getMaxLayers(terrain);
304  else
305  return 0;
306  }
307 
314  virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect)
315  {
316  Profile* p = getActiveProfile();
317  if (!p)
318  return;
319  else
320  p->updateCompositeMap(terrain, rect);
321  }
322 
323 
326  virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain)
327  {
328  Profile* p = getActiveProfile();
329  if (p)
330  p->updateParams(mat, terrain);
331  }
334  virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain)
335  {
336  Profile* p = getActiveProfile();
337  if (p)
338  p->updateParamsForCompositeMap(mat, terrain);
339  }
340 
349  virtual void setDebugLevel(unsigned int dbg)
350  {
351  if (mDebugLevel != dbg)
352  {
353  mDebugLevel = dbg;
354  _markChanged();
355  }
356  }
358  virtual unsigned int getDebugLevel() const { return mDebugLevel; }
359 
367  virtual void _renderCompositeMap(size_t size, const Rect& rect,
368  const MaterialPtr& mat, const TexturePtr& destCompositeMap);
369 
370  Texture* _getCompositeMapRTT() { return mCompositeMapRTT; }
371  protected:
372 
375  unsigned long long int mChangeCounter;
377  unsigned int mDebugLevel;
380  Texture* mCompositeMapRTT; // deliberately holding this by raw pointer to avoid shutdown issues
383 
384 
385 
386  };
387 
389 
393 }
394 #endif
395 
unsigned char uint8
Definition: OgrePlatform.h:248
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:85
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:261
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
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:72
TerrainLayerSampler(const String &aliasName, PixelFormat fmt)
virtual MaterialPtr generate(const Terrain *terrain)=0
Generate / resuse 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 setActiveProfile(const String &name)
Set the active profile by name.
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 / resuse a material for the terrain.
Albedo colour (diffuse reflectance colour)
virtual void requestOptions(Terrain *terrain)=0
Request the options needed from the terrain.
Specialisation of SharedPtr to allow SharedPtr to be assigned to TexturePtr.
Definition: OgreTexture.h:440
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.
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.
_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.
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
Abstract class representing a Texture resource.
Definition: OgreTexture.h:101
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.