# OgreTerrainMaterialGenerator.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028
    00029 #ifndef __Ogre_TerrainMaterialGenerator_H__
    00030 #define __Ogre_TerrainMaterialGenerator_H__
    00031
    00032 #include "OgreTerrainPrerequisites.h"
    00033 #include "OgrePixelFormat.h"
    00034 #include "OgreMaterial.h"
    00035 #include "OgreTexture.h"
    00036
    00037 namespace Ogre
    00038 {
    00039     class Terrain;
    00040
    00056     enum TerrainLayerSamplerSemantic
    00057     {
    00059         TLSS_ALBEDO = 0,
    00061         TLSS_NORMAL = 1,
    00063         TLSS_HEIGHT = 2,
    00065         TLSS_SPECULAR = 3
    00066     };
    00067
    00070     struct _OgreTerrainExport TerrainLayerSamplerElement
    00071     {
    00073         uint8 source;
    00075         TerrainLayerSamplerSemantic semantic;
    00077         uint8 elementStart;
    00079         uint8 elementCount;
    00080
    00081         bool operator==(const TerrainLayerSamplerElement& e) const
    00082         {
    00083             return source == e.source &&
    00084                 semantic == e.semantic &&
    00085                 elementStart == e.elementStart &&
    00086                 elementCount == e.elementCount;
    00087         }
    00088
    00089         TerrainLayerSamplerElement() {}
    00090         TerrainLayerSamplerElement(uint8 src, TerrainLayerSamplerSemantic sem,
    00091             uint8 elemStart, uint8 elemCount)
    00092             : source(src), semantic(sem), elementStart(elemStart), elementCount(elemCount)
    00093         {
    00094         }
    00095     };
    00096     typedef vector<TerrainLayerSamplerElement>::type TerrainLayerSamplerElementList;
    00097
    00100     struct _OgreTerrainExport TerrainLayerSampler
    00101     {
    00103         String alias;
    00105         PixelFormat format;
    00106
    00107         bool operator==(const TerrainLayerSampler& s) const
    00108         {
    00109             return alias == s.alias && format == s.format;
    00110         }
    00111
    00112         TerrainLayerSampler() {}
    00113
    00114         TerrainLayerSampler(const String& aliasName, PixelFormat fmt)
    00115             : alias(aliasName), format(fmt)
    00116         {
    00117         }
    00118     };
    00119     typedef vector<TerrainLayerSampler>::type TerrainLayerSamplerList;
    00120
    00125     struct _OgreTerrainExport TerrainLayerDeclaration
    00126     {
    00127         TerrainLayerSamplerList samplers;
    00128         TerrainLayerSamplerElementList elements;
    00129
    00130         bool operator==(const TerrainLayerDeclaration& dcl) const
    00131         {
    00132             return samplers == dcl.samplers && elements == dcl.elements;
    00133         }
    00134     };
    00135
    00155     class _OgreTerrainExport TerrainMaterialGenerator : public TerrainAlloc
    00156     {
    00157     public:
    00161         class _OgreTerrainExport Profile : public TerrainAlloc
    00162         {
    00163         protected:
    00164             TerrainMaterialGenerator* mParent;
    00165             String mName;
    00166             String mDesc;
    00167         public:
    00168             Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc)
    00169                 : mParent(parent), mName(name), mDesc(desc) {}
    00170             Profile(const Profile& prof)
    00171                 : mParent(prof.mParent), mName(prof.mName), mDesc(prof.mDesc) {}
    00172             virtual ~Profile() {}
    00174             TerrainMaterialGenerator* getParent() const { return mParent; }
    00176             const String& getName() const { return mName; }
    00178             const String& getDescription() const { return mDesc; }
    00179
    00181             virtual MaterialPtr generate(const Terrain* terrain) = 0;
    00183             virtual MaterialPtr generateForCompositeMap(const Terrain* terrain) = 0;
    00185             virtual uint8 getMaxLayers(const Terrain* terrain) const = 0;
    00187             virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect);
    00188
    00190             virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain) = 0;
    00192             virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain) = 0;
    00193
    00195             virtual void requestOptions(Terrain* terrain) = 0;
    00196
    00197         };
    00198
    00199         TerrainMaterialGenerator();
    00200         virtual ~TerrainMaterialGenerator();
    00201
    00203         typedef vector<Profile*>::type ProfileList;
    00204
    00207         virtual const ProfileList& getProfiles() const { return mProfiles; }
    00208
    00210         virtual void setActiveProfile(const String& name)
    00211         {
    00212             if (!mActiveProfile || mActiveProfile->getName() != name)
    00213             {
    00214                 for (ProfileList::iterator i = mProfiles.begin(); i != mProfiles.end(); ++i)
    00215                 {
    00216                     if ((*i)->getName() == name)
    00217                     {
    00218                         setActiveProfile(*i);
    00219                         break;
    00220                     }
    00221                 }
    00222             }
    00223
    00224         }
    00225
    00227         virtual void setActiveProfile(Profile* p)
    00228         {
    00229             if (mActiveProfile != p)
    00230             {
    00231                 mActiveProfile = p;
    00232                 _markChanged();
    00233             }
    00234         }
    00236         Profile* getActiveProfile() const
    00237         {
    00238             // default if not chosen yet
    00239             if (!mActiveProfile && !mProfiles.empty())
    00240                 mActiveProfile = mProfiles[0];
    00241
    00242             return mActiveProfile;
    00243         }
    00244
    00246         void _markChanged() { ++mChangeCounter; }
    00247
    00251         unsigned long long int getChangeCount() const { return mChangeCounter; }
    00252
    00255         virtual const TerrainLayerDeclaration& getLayerDeclaration() const { return mLayerDecl; }
    00262         virtual bool canGenerateUsingDeclaration(const TerrainLayerDeclaration& decl)
    00263         {
    00264             return decl == mLayerDecl;
    00265         }
    00266
    00269         virtual void requestOptions(Terrain* terrain)
    00270         {
    00271             Profile* p = getActiveProfile();
    00272             if (p)
    00273                 p->requestOptions(terrain);
    00274
    00275         }
    00278         virtual MaterialPtr generate(const Terrain* terrain)
    00279         {
    00280             Profile* p = getActiveProfile();
    00281             if (!p)
    00282                 return MaterialPtr();
    00283             else
    00284                 return p->generate(terrain);
    00285         }
    00288         virtual MaterialPtr generateForCompositeMap(const Terrain* terrain)
    00289         {
    00290             Profile* p = getActiveProfile();
    00291             if (!p)
    00292                 return MaterialPtr();
    00293             else
    00294                 return p->generateForCompositeMap(terrain);
    00295         }
    00299         virtual uint8 getMaxLayers(const Terrain* terrain) const
    00300         {
    00301             Profile* p = getActiveProfile();
    00302             if (p)
    00303                 return p->getMaxLayers(terrain);
    00304             else
    00305                 return 0;
    00306         }
    00307
    00314         virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect)
    00315         {
    00316             Profile* p = getActiveProfile();
    00317             if (!p)
    00318                 return;
    00319             else
    00320                 p->updateCompositeMap(terrain, rect);
    00321         }
    00322
    00323
    00326         virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain)
    00327         {
    00328             Profile* p = getActiveProfile();
    00329             if (p)
    00330                 p->updateParams(mat, terrain);
    00331         }
    00334         virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain)
    00335         {
    00336             Profile* p = getActiveProfile();
    00337             if (p)
    00338                 p->updateParamsForCompositeMap(mat, terrain);
    00339         }
    00340
    00349         virtual void setDebugLevel(unsigned int dbg)
    00350         {
    00351             if (mDebugLevel != dbg)
    00352             {
    00353                 mDebugLevel = dbg;
    00354                 _markChanged();
    00355             }
    00356         }
    00358         virtual unsigned int getDebugLevel() const { return mDebugLevel; }
    00359
    00367         virtual void _renderCompositeMap(size_t size, const Rect& rect,
    00368             const MaterialPtr& mat, const TexturePtr& destCompositeMap);
    00369
    00370         Texture* _getCompositeMapRTT() { return mCompositeMapRTT; }
    00371     protected:
    00372
    00373         ProfileList mProfiles;
    00374         mutable Profile* mActiveProfile;
    00375         unsigned long long int mChangeCounter;
    00376         TerrainLayerDeclaration mLayerDecl;
    00377         unsigned int mDebugLevel;
    00378         SceneManager* mCompositeMapSM;
    00379         Camera* mCompositeMapCam;
    00380         Texture* mCompositeMapRTT; // deliberately holding this by raw pointer to avoid shutdown issues
    00381         ManualObject* mCompositeMapPlane;
    00382         Light* mCompositeMapLight;
    00383
    00384
    00385
    00386     };
    00387
    00388     typedef SharedPtr<TerrainMaterialGenerator> TerrainMaterialGeneratorPtr;
    00389
    00393 }
    00394 #endif
    00395

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:09