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-2013 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; }
180  virtual bool isVertexCompressionSupported() const = 0;
182  virtual MaterialPtr generate(const Terrain* terrain) = 0;
184  virtual MaterialPtr generateForCompositeMap(const Terrain* terrain) = 0;
186  virtual void setLightmapEnabled(bool enabled) = 0;
188  virtual uint8 getMaxLayers(const Terrain* terrain) const = 0;
190  virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect);
191 
193  virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain) = 0;
195  virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain) = 0;
196 
198  virtual void requestOptions(Terrain* terrain) = 0;
199 
200  };
201 
203  virtual ~TerrainMaterialGenerator();
204 
207 
210  virtual const ProfileList& getProfiles() const { return mProfiles; }
211 
213  virtual void setActiveProfile(const String& name)
214  {
215  if (!mActiveProfile || mActiveProfile->getName() != name)
216  {
217  for (ProfileList::iterator i = mProfiles.begin(); i != mProfiles.end(); ++i)
218  {
219  if ((*i)->getName() == name)
220  {
221  setActiveProfile(*i);
222  break;
223  }
224  }
225  }
226 
227  }
228 
230  virtual void setActiveProfile(Profile* p)
231  {
232  if (mActiveProfile != p)
233  {
234  mActiveProfile = p;
235  _markChanged();
236  }
237  }
240  {
241  // default if not chosen yet
242  if (!mActiveProfile && !mProfiles.empty())
243  mActiveProfile = mProfiles[0];
244 
245  return mActiveProfile;
246  }
247 
249  void _markChanged() { ++mChangeCounter; }
250 
254  unsigned long long int getChangeCount() const { return mChangeCounter; }
255 
258  virtual const TerrainLayerDeclaration& getLayerDeclaration() const { return mLayerDecl; }
266  {
267  return decl == mLayerDecl;
268  }
269 
273  virtual bool isVertexCompressionSupported() const
274  {
275  return getActiveProfile()->isVertexCompressionSupported();
276  }
277 
280  virtual void requestOptions(Terrain* terrain)
281  {
282  Profile* p = getActiveProfile();
283  if (p)
284  p->requestOptions(terrain);
285 
286  }
289  virtual MaterialPtr generate(const Terrain* terrain)
290  {
291  Profile* p = getActiveProfile();
292  if (!p)
293  return MaterialPtr();
294  else
295  return p->generate(terrain);
296  }
300  {
301  Profile* p = getActiveProfile();
302  if (!p)
303  return MaterialPtr();
304  else
305  return p->generateForCompositeMap(terrain);
306  }
310  virtual void setLightmapEnabled(bool enabled)
311  {
312  Profile* p = getActiveProfile();
313  if (p)
314  return p->setLightmapEnabled(enabled);
315  }
319  virtual uint8 getMaxLayers(const Terrain* terrain) const
320  {
321  Profile* p = getActiveProfile();
322  if (p)
323  return p->getMaxLayers(terrain);
324  else
325  return 0;
326  }
327 
334  virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect)
335  {
336  Profile* p = getActiveProfile();
337  if (!p)
338  return;
339  else
340  p->updateCompositeMap(terrain, rect);
341  }
342 
343 
346  virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain)
347  {
348  Profile* p = getActiveProfile();
349  if (p)
350  p->updateParams(mat, terrain);
351  }
354  virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain)
355  {
356  Profile* p = getActiveProfile();
357  if (p)
358  p->updateParamsForCompositeMap(mat, terrain);
359  }
360 
369  virtual void setDebugLevel(unsigned int dbg)
370  {
371  if (mDebugLevel != dbg)
372  {
373  mDebugLevel = dbg;
374  _markChanged();
375  }
376  }
378  virtual unsigned int getDebugLevel() const { return mDebugLevel; }
379 
386  virtual void _renderCompositeMap(size_t size, const Rect& rect,
387  const MaterialPtr& mat, const TexturePtr& destCompositeMap);
388 
389  Texture* _getCompositeMapRTT() { return mCompositeMapRTT; }
390  protected:
391 
394  unsigned long long int mChangeCounter;
396  unsigned int mDebugLevel;
399  Texture* mCompositeMapRTT; // deliberately holding this by raw pointer to avoid shutdown issues
402 
403 
404 
405  };
406 
408 
412 }
413 #endif
414 

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Oct 16 2013 14:35:46