# OgrePass.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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __Pass_H__
    00030 #define __Pass_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreGpuProgram.h"
    00034 #include "OgreColourValue.h"
    00035 #include "OgreBlendMode.h"
    00036 #include "OgreCommon.h"
    00037 #include "OgreLight.h"
    00038 #include "OgreTextureUnitState.h"
    00039
    00040 namespace Ogre {
    00060     class _OgreExport Pass
    00061     {
    00062     public:
    00073         struct HashFunc
    00074         {
    00075             virtual uint32 operator()(const Pass* p) const = 0;
    00077             virtual ~HashFunc() {}
    00078         };
    00079     protected:
    00080         Technique* mParent;
    00081         unsigned short mIndex; // pass index
    00082         String mName; // optional name for the pass
    00083         uint32 mHash; // pass hash
    00084         //-------------------------------------------------------------------------
    00085         // Colour properties, only applicable in fixed-function passes
    00086         ColourValue mAmbient;
    00087         ColourValue mDiffuse;
    00088         ColourValue mSpecular;
    00089         ColourValue mEmissive;
    00090         Real mShininess;
    00091         TrackVertexColourType mTracking;
    00092         //-------------------------------------------------------------------------
    00093
    00094         //-------------------------------------------------------------------------
    00095         // Blending factors
    00096         SceneBlendFactor mSourceBlendFactor;
    00097         SceneBlendFactor mDestBlendFactor;
    00098         //-------------------------------------------------------------------------
    00099
    00100         //-------------------------------------------------------------------------
    00101         // Depth buffer settings
    00102         bool mDepthCheck;
    00103         bool mDepthWrite;
    00104         CompareFunction mDepthFunc;
    00105         float mDepthBiasConstant;
    00106         float mDepthBiasSlopeScale;
    00107
    00108         // Colour buffer settings
    00109         bool mColourWrite;
    00110
    00111         // Alpha reject settings
    00112         CompareFunction mAlphaRejectFunc;
    00113         unsigned char mAlphaRejectVal;
    00114         //-------------------------------------------------------------------------
    00115
    00116         //-------------------------------------------------------------------------
    00117         // Culling mode
    00118         CullingMode mCullMode;
    00119         ManualCullingMode mManualCullMode;
    00120         //-------------------------------------------------------------------------
    00121
    00123         bool mLightingEnabled;
    00125         unsigned short mMaxSimultaneousLights;
    00127         unsigned short mStartLight;
    00129         bool mIteratePerLight;
    00131         unsigned short mLightsPerIteration;
    00132         // Should it only be run for a certain light type?
    00133         bool mRunOnlyForOneLightType;
    00134         Light::LightTypes mOnlyLightType;
    00135
    00137         ShadeOptions mShadeOptions;
    00139         PolygonMode mPolygonMode;
    00140
    00141         //-------------------------------------------------------------------------
    00142         // Fog
    00143         bool mFogOverride;
    00144         FogMode mFogMode;
    00145         ColourValue mFogColour;
    00146         Real mFogStart;
    00147         Real mFogEnd;
    00148         Real mFogDensity;
    00149         //-------------------------------------------------------------------------
    00150
    00152         typedef std::vector<TextureUnitState*> TextureUnitStates;
    00153         TextureUnitStates mTextureUnitStates;
    00154
    00155         // Vertex program details
    00156         GpuProgramUsage *mVertexProgramUsage;
    00157         // Vertex program details
    00158         GpuProgramUsage *mShadowCasterVertexProgramUsage;
    00159         // Vertex program details
    00160         GpuProgramUsage *mShadowReceiverVertexProgramUsage;
    00161         // Fragment program details
    00162         GpuProgramUsage *mFragmentProgramUsage;
    00163         // Fragment program details
    00164         GpuProgramUsage *mShadowReceiverFragmentProgramUsage;
    00165         // Is this pass queued for deletion?
    00166         bool mQueuedForDeletion;
    00167         // number of pass iterations to perform
    00168         size_t mPassIterationCount;
    00169         // point size, applies when not using per-vertex point size
    00170         Real mPointSize;
    00171         Real mPointMinSize;
    00172         Real mPointMaxSize;
    00173         bool mPointSpritesEnabled;
    00174         bool mPointAttenuationEnabled;
    00175         // constant, linear, quadratic coeffs
    00176         Real mPointAttenuationCoeffs[3];
    00177         // TU Content type lookups
    00178         typedef std::vector<unsigned short> ContentTypeLookup;
    00179         mutable ContentTypeLookup mShadowContentTypeLookup;
    00180         mutable bool mContentTypeLookupBuilt;
    00181
    00182     public:
    00183         typedef std::set<Pass*> PassSet;
    00184     protected:
    00186         static PassSet msDirtyHashList;
    00188         static PassSet msPassGraveyard;
    00190         static HashFunc* msHashFunc;
    00191     public:
    00192         OGRE_STATIC_MUTEX(msDirtyHashListMutex);
    00193         OGRE_STATIC_MUTEX(msPassGraveyardMutex);
    00195         Pass(Technique* parent, unsigned short index);
    00197         Pass(Technique* parent, unsigned short index, const Pass& oth );
    00199         Pass& operator=(const Pass& oth);
    00200         ~Pass();
    00201
    00203         bool isProgrammable(void) const { return mVertexProgramUsage || mFragmentProgramUsage; }
    00205         bool hasVertexProgram(void) const { return mVertexProgramUsage != NULL; }
    00207         bool hasFragmentProgram(void) const { return mFragmentProgramUsage != NULL; }
    00209         bool hasShadowCasterVertexProgram(void) const { return mShadowCasterVertexProgramUsage != NULL; }
    00211         bool hasShadowReceiverVertexProgram(void) const { return mShadowReceiverVertexProgramUsage != NULL; }
    00213         bool hasShadowReceiverFragmentProgram(void) const { return mShadowReceiverFragmentProgramUsage != NULL; }
    00214
    00215
    00217         unsigned short getIndex(void) const { return mIndex; }
    00218         /* Set the name of the pass
    00219         @remarks
    00220         The name of the pass is optional.  Its usefull in material scripts where a material could inherit
    00221         from another material and only want to modify a particalar pass.
    00222         */
    00223         void setName(const String& name);
    00225         const String& getName(void) const { return mName; }
    00226
    00238         void setAmbient(Real red, Real green, Real blue);
    00239
    00252         void setAmbient(const ColourValue& ambient);
    00253
    00264         void setDiffuse(Real red, Real green, Real blue, Real alpha);
    00265
    00276         void setDiffuse(const ColourValue& diffuse);
    00277
    00290         void setSpecular(Real red, Real green, Real blue, Real alpha);
    00291
    00304         void setSpecular(const ColourValue& specular);
    00305
    00311         void setShininess(Real val);
    00312
    00322         void setSelfIllumination(Real red, Real green, Real blue);
    00323
    00333         void setSelfIllumination(const ColourValue& selfIllum);
    00334
    00337         void setVertexColourTracking(TrackVertexColourType tracking);
    00338
    00344         Real getPointSize(void) const;
    00345
    00361         void setPointSize(Real ps);
    00362
    00368         void setPointSpritesEnabled(bool enabled);
    00369
    00373         bool getPointSpritesEnabled(void) const;
    00374
    00391         void setPointAttenuation(bool enabled,
    00392             Real constant = 0.0f, Real linear = 1.0f, Real quadratic = 0.0f);
    00393
    00395         bool isPointAttenuationEnabled(void) const;
    00396
    00398         Real getPointAttenuationConstant(void) const;
    00400         Real getPointAttenuationLinear(void) const;
    00402         Real getPointAttenuationQuadratic(void) const;
    00403
    00405         void setPointMinSize(Real min);
    00407         Real getPointMinSize(void) const;
    00411         void setPointMaxSize(Real max);
    00415         Real getPointMaxSize(void) const;
    00416
    00419         const ColourValue& getAmbient(void) const;
    00420
    00423         const ColourValue& getDiffuse(void) const;
    00424
    00427         const ColourValue& getSpecular(void) const;
    00428
    00431         const ColourValue& getSelfIllumination(void) const;
    00432
    00435         Real getShininess(void) const;
    00436
    00439         TrackVertexColourType getVertexColourTracking(void) const;
    00440
    00445         TextureUnitState* createTextureUnitState(void);
    00456         TextureUnitState* createTextureUnitState( const String& textureName, unsigned short texCoordSet = 0);
    00462         void addTextureUnitState(TextureUnitState* state);
    00465         TextureUnitState* getTextureUnitState(unsigned short index);
    00469         TextureUnitState* getTextureUnitState(const String& name);
    00472         const TextureUnitState* getTextureUnitState(unsigned short index) const;
    00476         const TextureUnitState* getTextureUnitState(const String& name) const;
    00477
    00484         unsigned short getTextureUnitStateIndex(const TextureUnitState* state) const;
    00485
    00486         typedef VectorIterator<TextureUnitStates> TextureUnitStateIterator;
    00488         TextureUnitStateIterator getTextureUnitStateIterator(void);
    00489
    00490         typedef ConstVectorIterator<TextureUnitStates> ConstTextureUnitStateIterator;
    00492         ConstTextureUnitStateIterator getTextureUnitStateIterator(void) const;
    00493
    00498         void removeTextureUnitState(unsigned short index);
    00499
    00502         void removeAllTextureUnitStates(void);
    00503
    00506         unsigned short getNumTextureUnitStates(void) const
    00507         {
    00508             return static_cast<unsigned short>(mTextureUnitStates.size());
    00509         }
    00510
    00527         void setSceneBlending( const SceneBlendType sbt );
    00528
    00551         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
    00552
    00555         SceneBlendFactor getSourceBlendFactor() const;
    00556
    00559         SceneBlendFactor getDestBlendFactor() const;
    00560
    00562         bool isTransparent(void) const;
    00563
    00575         void setDepthCheckEnabled(bool enabled);
    00576
    00581         bool getDepthCheckEnabled(void) const;
    00582
    00593         void setDepthWriteEnabled(bool enabled);
    00594
    00599         bool getDepthWriteEnabled(void) const;
    00600
    00608         void setDepthFunction( CompareFunction func );
    00613         CompareFunction getDepthFunction(void) const;
    00614
    00625         void setColourWriteEnabled(bool enabled);
    00627         bool getColourWriteEnabled(void) const;
    00628
    00642         void setCullingMode( CullingMode mode );
    00643
    00646         CullingMode getCullingMode(void) const;
    00647
    00661         void setManualCullingMode( ManualCullingMode mode );
    00662
    00667         ManualCullingMode getManualCullingMode(void) const;
    00668
    00677         void setLightingEnabled(bool enabled);
    00678
    00681         bool getLightingEnabled(void) const;
    00682
    00691         void setMaxSimultaneousLights(unsigned short maxLights);
    00693         unsigned short getMaxSimultaneousLights(void) const;
    00694
    00705         void setStartLight(unsigned short startLight);
    00707         unsigned short getStartLight(void) const;
    00708
    00713         void setShadingMode( ShadeOptions mode );
    00714
    00717         ShadeOptions getShadingMode(void) const;
    00718
    00723         void setPolygonMode( PolygonMode mode );
    00724
    00727         PolygonMode getPolygonMode(void) const;
    00728
    00758         void setFog(
    00759             bool overrideScene,
    00760             FogMode mode = FOG_NONE,
    00761             const ColourValue& colour = ColourValue::White,
    00762             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
    00763
    00766         bool getFogOverride(void) const;
    00767
    00772         FogMode getFogMode(void) const;
    00773
    00776         const ColourValue& getFogColour(void) const;
    00777
    00782         Real getFogStart(void) const;
    00783
    00788         Real getFogEnd(void) const;
    00789
    00794         Real getFogDensity(void) const;
    00795
    00815         void setDepthBias(float constantBias, float slopeScaleBias = 0.0f);
    00816
    00818         float getDepthBiasConstant(void) const;
    00820         float getDepthBiasSlopeScale(void) const;
    00821
    00830         void setAlphaRejectSettings(CompareFunction func, unsigned char value);
    00831
    00834         void setAlphaRejectFunction(CompareFunction func);
    00835
    00838         void setAlphaRejectValue(unsigned char val);
    00839
    00842         CompareFunction getAlphaRejectFunction(void) const { return mAlphaRejectFunc; }
    00843
    00846         unsigned char getAlphaRejectValue(void) const { return mAlphaRejectVal; }
    00889         void setIteratePerLight(bool enabled,
    00890             bool onlyForOneLightType = true, Light::LightTypes lightType = Light::LT_POINT);
    00891
    00893         bool getIteratePerLight(void) const { return mIteratePerLight; }
    00895         bool getRunOnlyForOneLightType(void) const { return mRunOnlyForOneLightType; }
    00898         Light::LightTypes getOnlyLightType() const { return mOnlyLightType; }
    00899
    00909         void setLightCountPerIteration(unsigned short c);
    00913         unsigned short getLightCountPerIteration(void) const;
    00914
    00916         Technique* getParent(void) const { return mParent; }
    00917
    00919         const String& getResourceGroup(void) const;
    00920
    00937         void setVertexProgram(const String& name, bool resetParams = true);
    00944         void setVertexProgramParameters(GpuProgramParametersSharedPtr params);
    00946         const String& getVertexProgramName(void) const;
    00948         GpuProgramParametersSharedPtr getVertexProgramParameters(void) const;
    00950         const GpuProgramPtr& getVertexProgram(void) const;
    00951
    00952
    00982         void setShadowCasterVertexProgram(const String& name);
    00989         void setShadowCasterVertexProgramParameters(GpuProgramParametersSharedPtr params);
    00991         const String& getShadowCasterVertexProgramName(void) const;
    00993         GpuProgramParametersSharedPtr getShadowCasterVertexProgramParameters(void) const;
    00996         const GpuProgramPtr& getShadowCasterVertexProgram(void) const;
    00997
    01023         void setShadowReceiverVertexProgram(const String& name);
    01030         void setShadowReceiverVertexProgramParameters(GpuProgramParametersSharedPtr params);
    01031
    01052         void setShadowReceiverFragmentProgram(const String& name);
    01059         void setShadowReceiverFragmentProgramParameters(GpuProgramParametersSharedPtr params);
    01060
    01062         const String& getShadowReceiverVertexProgramName(void) const;
    01064         GpuProgramParametersSharedPtr getShadowReceiverVertexProgramParameters(void) const;
    01067         const GpuProgramPtr& getShadowReceiverVertexProgram(void) const;
    01068
    01070         const String& getShadowReceiverFragmentProgramName(void) const;
    01072         GpuProgramParametersSharedPtr getShadowReceiverFragmentProgramParameters(void) const;
    01075         const GpuProgramPtr& getShadowReceiverFragmentProgram(void) const;
    01076
    01093         void setFragmentProgram(const String& name, bool resetParams = true);
    01098         void setFragmentProgramParameters(GpuProgramParametersSharedPtr params);
    01100         const String& getFragmentProgramName(void) const;
    01102         GpuProgramParametersSharedPtr getFragmentProgramParameters(void) const;
    01104         const GpuProgramPtr& getFragmentProgram(void) const;
    01105
    01117         Pass* _split(unsigned short numUnits);
    01118
    01120         void _notifyIndex(unsigned short index);
    01121
    01123         void _load(void);
    01125         void _unload(void);
    01126         // Is this loaded?
    01127         bool isLoaded(void) const;
    01128
    01135         uint32 getHash(void) const { return mHash; }
    01137         void _dirtyHash(void);
    01144         void _recalculateHash(void);
    01146         void _notifyNeedsRecompile(void);
    01147
    01149         void _updateAutoParamsNoLights(const AutoParamDataSource& source) const;
    01151         void _updateAutoParamsLightsOnly(const AutoParamDataSource& source) const;
    01152
    01159         unsigned short _getTextureUnitWithContentTypeIndex(
    01160             TextureUnitState::ContentType contentType, unsigned short index) const;
    01161
    01170         void setTextureFiltering(TextureFilterOptions filterType);
    01179         void setTextureAnisotropy(unsigned int maxAniso);
    01183         static const PassSet& getDirtyHashList(void)
    01184         { return msDirtyHashList; }
    01187         static const PassSet& getPassGraveyard(void)
    01188         { return msPassGraveyard; }
    01196         static void clearDirtyHashList(void);
    01197
    01199         static void processPendingPassUpdates(void);
    01200
    01202         void queueForDeletion(void);
    01203
    01206         bool isAmbientOnly(void) const;
    01207
    01221         void setPassIterationCount(const size_t count) { mPassIterationCount = count; }
    01222
    01225         size_t getPassIterationCount(void) const { return mPassIterationCount; }
    01226
    01238         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
    01239
    01240
    01244         enum BuiltinHashFunction
    01245         {
    01247             MIN_TEXTURE_CHANGE,
    01252             MIN_GPU_PROGRAM_CHANGE
    01253         };
    01266         static void setHashFunction(BuiltinHashFunction builtin);
    01267
    01279         static void setHashFunction(HashFunc* hashFunc) { msHashFunc = hashFunc; }
    01280
    01283         static HashFunc* getHashFunction(void) { return msHashFunc; }
    01284
    01285     };
    01286
    01287     enum IlluminationStage
    01288     {
    01290         IS_AMBIENT,
    01292         IS_PER_LIGHT,
    01294         IS_DECAL
    01295     };
    01305     struct IlluminationPass
    01306     {
    01307         IlluminationStage stage;
    01309         Pass* pass;
    01311         bool destroyOnShutdown;
    01313         Pass* originalPass;
    01314     };
    01315
    01316     typedef std::vector<IlluminationPass*> IlluminationPassList;
    01317
    01318
    01319 }
    01320
    01321 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat May 10 16:25:01 2008