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-2012 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; }
    00180             virtual bool isVertexCompressionSupported() const = 0;
    00182             virtual MaterialPtr generate(const Terrain* terrain) = 0;
    00184             virtual MaterialPtr generateForCompositeMap(const Terrain* terrain) = 0;
    00186             virtual uint8 getMaxLayers(const Terrain* terrain) const = 0;
    00188             virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect);
    00189
    00191             virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain) = 0;
    00193             virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain) = 0;
    00194
    00196             virtual void requestOptions(Terrain* terrain) = 0;
    00197
    00198         };
    00199
    00200         TerrainMaterialGenerator();
    00201         virtual ~TerrainMaterialGenerator();
    00202
    00204         typedef vector<Profile*>::type ProfileList;
    00205
    00208         virtual const ProfileList& getProfiles() const { return mProfiles; }
    00209
    00211         virtual void setActiveProfile(const String& name)
    00212         {
    00213             if (!mActiveProfile || mActiveProfile->getName() != name)
    00214             {
    00215                 for (ProfileList::iterator i = mProfiles.begin(); i != mProfiles.end(); ++i)
    00216                 {
    00217                     if ((*i)->getName() == name)
    00218                     {
    00219                         setActiveProfile(*i);
    00220                         break;
    00221                     }
    00222                 }
    00223             }
    00224
    00225         }
    00226
    00228         virtual void setActiveProfile(Profile* p)
    00229         {
    00230             if (mActiveProfile != p)
    00231             {
    00232                 mActiveProfile = p;
    00233                 _markChanged();
    00234             }
    00235         }
    00237         Profile* getActiveProfile() const
    00238         {
    00239             // default if not chosen yet
    00240             if (!mActiveProfile && !mProfiles.empty())
    00241                 mActiveProfile = mProfiles[0];
    00242
    00243             return mActiveProfile;
    00244         }
    00245
    00247         void _markChanged() { ++mChangeCounter; }
    00248
    00252         unsigned long long int getChangeCount() const { return mChangeCounter; }
    00253
    00256         virtual const TerrainLayerDeclaration& getLayerDeclaration() const { return mLayerDecl; }
    00263         virtual bool canGenerateUsingDeclaration(const TerrainLayerDeclaration& decl)
    00264         {
    00265             return decl == mLayerDecl;
    00266         }
    00267
    00271         virtual bool isVertexCompressionSupported() const
    00272         {
    00273             return getActiveProfile()->isVertexCompressionSupported();
    00274         }
    00275
    00278         virtual void requestOptions(Terrain* terrain)
    00279         {
    00280             Profile* p = getActiveProfile();
    00281             if (p)
    00282                 p->requestOptions(terrain);
    00283
    00284         }
    00287         virtual MaterialPtr generate(const Terrain* terrain)
    00288         {
    00289             Profile* p = getActiveProfile();
    00290             if (!p)
    00291                 return MaterialPtr();
    00292             else
    00293                 return p->generate(terrain);
    00294         }
    00297         virtual MaterialPtr generateForCompositeMap(const Terrain* terrain)
    00298         {
    00299             Profile* p = getActiveProfile();
    00300             if (!p)
    00301                 return MaterialPtr();
    00302             else
    00303                 return p->generateForCompositeMap(terrain);
    00304         }
    00308         virtual uint8 getMaxLayers(const Terrain* terrain) const
    00309         {
    00310             Profile* p = getActiveProfile();
    00311             if (p)
    00312                 return p->getMaxLayers(terrain);
    00313             else
    00314                 return 0;
    00315         }
    00316
    00323         virtual void updateCompositeMap(const Terrain* terrain, const Rect& rect)
    00324         {
    00325             Profile* p = getActiveProfile();
    00326             if (!p)
    00327                 return;
    00328             else
    00329                 p->updateCompositeMap(terrain, rect);
    00330         }
    00331
    00332
    00335         virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain)
    00336         {
    00337             Profile* p = getActiveProfile();
    00338             if (p)
    00339                 p->updateParams(mat, terrain);
    00340         }
    00343         virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain)
    00344         {
    00345             Profile* p = getActiveProfile();
    00346             if (p)
    00347                 p->updateParamsForCompositeMap(mat, terrain);
    00348         }
    00349
    00358         virtual void setDebugLevel(unsigned int dbg)
    00359         {
    00360             if (mDebugLevel != dbg)
    00361             {
    00362                 mDebugLevel = dbg;
    00363                 _markChanged();
    00364             }
    00365         }
    00367         virtual unsigned int getDebugLevel() const { return mDebugLevel; }
    00368
    00376         virtual void _renderCompositeMap(size_t size, const Rect& rect,
    00377             const MaterialPtr& mat, const TexturePtr& destCompositeMap);
    00378
    00379         Texture* _getCompositeMapRTT() { return mCompositeMapRTT; }
    00380     protected:
    00381
    00382         ProfileList mProfiles;
    00383         mutable Profile* mActiveProfile;
    00384         unsigned long long int mChangeCounter;
    00385         TerrainLayerDeclaration mLayerDecl;
    00386         unsigned int mDebugLevel;
    00387         SceneManager* mCompositeMapSM;
    00388         Camera* mCompositeMapCam;
    00389         Texture* mCompositeMapRTT; // deliberately holding this by raw pointer to avoid shutdown issues
    00390         ManualObject* mCompositeMapPlane;
    00391         Light* mCompositeMapLight;
    00392
    00393
    00394
    00395     };
    00396
    00397     typedef SharedPtr<TerrainMaterialGenerator> TerrainMaterialGeneratorPtr;
    00398
    00402 }
    00403 #endif
    00404

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:24