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 {
00041 
00043     enum IlluminationStage
00044     {
00046         IS_AMBIENT,
00048         IS_PER_LIGHT,
00050         IS_DECAL, 
00052         IS_UNKNOWN
00053     };
00054 
00074     class _OgreExport Pass : public PassAlloc
00075     {
00076     public:
00087         struct HashFunc
00088         {
00089             virtual uint32 operator()(const Pass* p) const = 0;
00091             virtual ~HashFunc() {}
00092         };
00093     protected:
00094         Technique* mParent;
00095         unsigned short mIndex; // pass index
00096         String mName; // optional name for the pass
00097         uint32 mHash; // pass hash
00098         //-------------------------------------------------------------------------
00099         // Colour properties, only applicable in fixed-function passes
00100         ColourValue mAmbient;
00101         ColourValue mDiffuse;
00102         ColourValue mSpecular;
00103         ColourValue mEmissive;
00104         Real mShininess;
00105         TrackVertexColourType mTracking;
00106         //-------------------------------------------------------------------------
00107 
00108         //-------------------------------------------------------------------------
00109         // Blending factors
00110         SceneBlendFactor mSourceBlendFactor;
00111         SceneBlendFactor mDestBlendFactor;
00112         SceneBlendFactor mSourceBlendFactorAlpha;
00113         SceneBlendFactor mDestBlendFactorAlpha;
00114 
00115         // Used to determine if separate alpha blending should be used for color and alpha channels
00116         bool mSeparateBlend;
00117         //-------------------------------------------------------------------------
00118 
00119         //-------------------------------------------------------------------------
00120         // Depth buffer settings
00121         bool mDepthCheck;
00122         bool mDepthWrite;
00123         CompareFunction mDepthFunc;
00124         float mDepthBiasConstant;
00125         float mDepthBiasSlopeScale;
00126         float mDepthBiasPerIteration;
00127 
00128         // Colour buffer settings
00129         bool mColourWrite;
00130 
00131         // Alpha reject settings
00132         CompareFunction mAlphaRejectFunc;
00133         unsigned char mAlphaRejectVal;
00134         bool mAlphaToCoverageEnabled;
00135 
00136         // Transparent depth sorting
00137         bool mTransparentSorting;
00138         //-------------------------------------------------------------------------
00139 
00140         //-------------------------------------------------------------------------
00141         // Culling mode
00142         CullingMode mCullMode;
00143         ManualCullingMode mManualCullMode;
00144         //-------------------------------------------------------------------------
00145 
00147         bool mLightingEnabled;
00149         unsigned short mMaxSimultaneousLights;
00151         unsigned short mStartLight;
00153         bool mIteratePerLight;
00155         unsigned short mLightsPerIteration;
00156         // Should it only be run for a certain light type?
00157         bool mRunOnlyForOneLightType;
00158         Light::LightTypes mOnlyLightType;
00159 
00161         ShadeOptions mShadeOptions;
00163         PolygonMode mPolygonMode;
00165         bool mNormaliseNormals;
00166         bool mPolygonModeOverrideable;
00167         //-------------------------------------------------------------------------
00168         // Fog
00169         bool mFogOverride;
00170         FogMode mFogMode;
00171         ColourValue mFogColour;
00172         Real mFogStart;
00173         Real mFogEnd;
00174         Real mFogDensity;
00175         //-------------------------------------------------------------------------
00176 
00178         typedef std::vector<TextureUnitState*> TextureUnitStates;
00179         TextureUnitStates mTextureUnitStates;
00180 
00181         // Vertex program details
00182         GpuProgramUsage *mVertexProgramUsage;
00183         // Vertex program details
00184         GpuProgramUsage *mShadowCasterVertexProgramUsage;
00185         // Vertex program details
00186         GpuProgramUsage *mShadowReceiverVertexProgramUsage;
00187         // Fragment program details
00188         GpuProgramUsage *mFragmentProgramUsage;
00189         // Fragment program details
00190         GpuProgramUsage *mShadowReceiverFragmentProgramUsage;
00191         // Geometry program details
00192         GpuProgramUsage *mGeometryProgramUsage;
00193         // Is this pass queued for deletion?
00194         bool mQueuedForDeletion;
00195         // number of pass iterations to perform
00196         size_t mPassIterationCount;
00197         // point size, applies when not using per-vertex point size
00198         Real mPointSize;
00199         Real mPointMinSize;
00200         Real mPointMaxSize;
00201         bool mPointSpritesEnabled;
00202         bool mPointAttenuationEnabled;
00203         // constant, linear, quadratic coeffs
00204         Real mPointAttenuationCoeffs[3];
00205         // TU Content type lookups
00206         typedef std::vector<unsigned short> ContentTypeLookup;
00207         mutable ContentTypeLookup mShadowContentTypeLookup;
00208         mutable bool mContentTypeLookupBuilt;
00210         bool mLightScissoring;
00212         bool mLightClipPlanes;
00214         IlluminationStage mIlluminationStage;
00215 
00216         // Used to get scene blending flags from a blending type
00217         void _getBlendFlags(SceneBlendType type, SceneBlendFactor& source, SceneBlendFactor& dest);
00218 
00219     public:
00220         typedef std::set<Pass*> PassSet;
00221     protected:
00223         static PassSet msDirtyHashList;
00225         static PassSet msPassGraveyard;
00227         static HashFunc* msHashFunc;
00228     public:
00229         OGRE_STATIC_MUTEX(msDirtyHashListMutex)
00230         OGRE_STATIC_MUTEX(msPassGraveyardMutex)
00232         Pass(Technique* parent, unsigned short index);
00234         Pass(Technique* parent, unsigned short index, const Pass& oth );
00236         Pass& operator=(const Pass& oth);
00237         virtual ~Pass();
00238 
00240         bool isProgrammable(void) const { return mVertexProgramUsage || mFragmentProgramUsage || mGeometryProgramUsage; }
00242         bool hasVertexProgram(void) const { return mVertexProgramUsage != NULL; }
00244         bool hasFragmentProgram(void) const { return mFragmentProgramUsage != NULL; }
00246         bool hasGeometryProgram(void) const { return mGeometryProgramUsage != NULL; }
00248         bool hasShadowCasterVertexProgram(void) const { return mShadowCasterVertexProgramUsage != NULL; }
00250         bool hasShadowReceiverVertexProgram(void) const { return mShadowReceiverVertexProgramUsage != NULL; }
00252         bool hasShadowReceiverFragmentProgram(void) const { return mShadowReceiverFragmentProgramUsage != NULL; }
00253 
00254 
00256         unsigned short getIndex(void) const { return mIndex; }
00257         /* Set the name of the pass
00258         @remarks
00259         The name of the pass is optional.  Its useful in material scripts where a material could inherit
00260         from another material and only want to modify a particular pass.
00261         */
00262         void setName(const String& name);
00264         const String& getName(void) const { return mName; }
00265 
00277         void setAmbient(Real red, Real green, Real blue);
00278 
00291         void setAmbient(const ColourValue& ambient);
00292 
00303         void setDiffuse(Real red, Real green, Real blue, Real alpha);
00304 
00315         void setDiffuse(const ColourValue& diffuse);
00316 
00329         void setSpecular(Real red, Real green, Real blue, Real alpha);
00330 
00343         void setSpecular(const ColourValue& specular);
00344 
00350         void setShininess(Real val);
00351 
00361         void setSelfIllumination(Real red, Real green, Real blue);
00362 
00372         void setSelfIllumination(const ColourValue& selfIllum);
00373 
00376         void setVertexColourTracking(TrackVertexColourType tracking);
00377 
00383         Real getPointSize(void) const;
00384 
00400         void setPointSize(Real ps);
00401 
00407         void setPointSpritesEnabled(bool enabled);
00408 
00412         bool getPointSpritesEnabled(void) const;
00413 
00430         void setPointAttenuation(bool enabled,
00431             Real constant = 0.0f, Real linear = 1.0f, Real quadratic = 0.0f);
00432 
00434         bool isPointAttenuationEnabled(void) const;
00435 
00437         Real getPointAttenuationConstant(void) const;
00439         Real getPointAttenuationLinear(void) const;
00441         Real getPointAttenuationQuadratic(void) const;
00442 
00444         void setPointMinSize(Real min);
00446         Real getPointMinSize(void) const;
00450         void setPointMaxSize(Real max);
00454         Real getPointMaxSize(void) const;
00455 
00458         const ColourValue& getAmbient(void) const;
00459 
00462         const ColourValue& getDiffuse(void) const;
00463 
00466         const ColourValue& getSpecular(void) const;
00467 
00470         const ColourValue& getSelfIllumination(void) const;
00471 
00474         Real getShininess(void) const;
00475 
00478         TrackVertexColourType getVertexColourTracking(void) const;
00479 
00484         TextureUnitState* createTextureUnitState(void);
00495         TextureUnitState* createTextureUnitState( const String& textureName, unsigned short texCoordSet = 0);
00501         void addTextureUnitState(TextureUnitState* state);
00504         TextureUnitState* getTextureUnitState(unsigned short index);
00508         TextureUnitState* getTextureUnitState(const String& name);
00511         const TextureUnitState* getTextureUnitState(unsigned short index) const;
00515         const TextureUnitState* getTextureUnitState(const String& name) const;
00516 
00523         unsigned short getTextureUnitStateIndex(const TextureUnitState* state) const;
00524 
00525         typedef VectorIterator<TextureUnitStates> TextureUnitStateIterator;
00527         TextureUnitStateIterator getTextureUnitStateIterator(void);
00528 
00529         typedef ConstVectorIterator<TextureUnitStates> ConstTextureUnitStateIterator;
00531         ConstTextureUnitStateIterator getTextureUnitStateIterator(void) const;
00532 
00537         void removeTextureUnitState(unsigned short index);
00538 
00541         void removeAllTextureUnitStates(void);
00542 
00545         unsigned short getNumTextureUnitStates(void) const
00546         {
00547             return static_cast<unsigned short>(mTextureUnitStates.size());
00548         }
00549 
00566         void setSceneBlending( const SceneBlendType sbt );
00567 
00586         void setSeparateSceneBlending( const SceneBlendType sbt, const SceneBlendType sbta );
00587 
00610         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
00611 
00638         void setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha );
00639 
00641         bool hasSeparateSceneBlending() const;
00642 
00645         SceneBlendFactor getSourceBlendFactor() const;
00646 
00649         SceneBlendFactor getDestBlendFactor() const;
00650 
00653         SceneBlendFactor getSourceBlendFactorAlpha() const;
00654 
00657         SceneBlendFactor getDestBlendFactorAlpha() const;
00658 
00660         bool isTransparent(void) const;
00661 
00673         void setDepthCheckEnabled(bool enabled);
00674 
00679         bool getDepthCheckEnabled(void) const;
00680 
00691         void setDepthWriteEnabled(bool enabled);
00692 
00697         bool getDepthWriteEnabled(void) const;
00698 
00706         void setDepthFunction( CompareFunction func );
00711         CompareFunction getDepthFunction(void) const;
00712 
00723         void setColourWriteEnabled(bool enabled);
00725         bool getColourWriteEnabled(void) const;
00726 
00740         void setCullingMode( CullingMode mode );
00741 
00744         CullingMode getCullingMode(void) const;
00745 
00759         void setManualCullingMode( ManualCullingMode mode );
00760 
00765         ManualCullingMode getManualCullingMode(void) const;
00766 
00775         void setLightingEnabled(bool enabled);
00776 
00779         bool getLightingEnabled(void) const;
00780 
00789         void setMaxSimultaneousLights(unsigned short maxLights);
00791         unsigned short getMaxSimultaneousLights(void) const;
00792 
00803         void setStartLight(unsigned short startLight);
00805         unsigned short getStartLight(void) const;
00806 
00811         void setShadingMode( ShadeOptions mode );
00812 
00815         ShadeOptions getShadingMode(void) const;
00816 
00821         void setPolygonMode( PolygonMode mode );
00822 
00825         PolygonMode getPolygonMode(void) const;
00826 
00832         virtual void setPolygonModeOverrideable(bool override)
00833         {
00834             mPolygonModeOverrideable = override;
00835         }
00836 
00840         virtual bool getPolygonModeOverrideable(void) const
00841         {
00842             return mPolygonModeOverrideable;
00843         }
00873         void setFog(
00874             bool overrideScene,
00875             FogMode mode = FOG_NONE,
00876             const ColourValue& colour = ColourValue::White,
00877             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
00878 
00881         bool getFogOverride(void) const;
00882 
00887         FogMode getFogMode(void) const;
00888 
00891         const ColourValue& getFogColour(void) const;
00892 
00897         Real getFogStart(void) const;
00898 
00903         Real getFogEnd(void) const;
00904 
00909         Real getFogDensity(void) const;
00910 
00930         void setDepthBias(float constantBias, float slopeScaleBias = 0.0f);
00931 
00933         float getDepthBiasConstant(void) const;
00935         float getDepthBiasSlopeScale(void) const;
00942         void setIterationDepthBias(float biasPerIteration);
00946         float getIterationDepthBias() const;
00947 
00957         void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverageEnabled = false);
00958 
00961         void setAlphaRejectFunction(CompareFunction func);
00962 
00965         void setAlphaRejectValue(unsigned char val);
00966 
00969         CompareFunction getAlphaRejectFunction(void) const { return mAlphaRejectFunc; }
00970 
00973         unsigned char getAlphaRejectValue(void) const { return mAlphaRejectVal; }
00974 
00982         void setAlphaToCoverageEnabled(bool enabled);
00983 
00986         bool isAlphaToCoverageEnabled() const { return mAlphaToCoverageEnabled; }
00987 
01000         void setTransparentSortingEnabled(bool enabled);
01001 
01004         bool getTransparentSortingEnabled(void) const;
01005 
01048         void setIteratePerLight(bool enabled,
01049             bool onlyForOneLightType = true, Light::LightTypes lightType = Light::LT_POINT);
01050 
01052         bool getIteratePerLight(void) const { return mIteratePerLight; }
01054         bool getRunOnlyForOneLightType(void) const { return mRunOnlyForOneLightType; }
01057         Light::LightTypes getOnlyLightType() const { return mOnlyLightType; }
01058 
01068         void setLightCountPerIteration(unsigned short c);
01072         unsigned short getLightCountPerIteration(void) const;
01073         
01075         Technique* getParent(void) const { return mParent; }
01076 
01078         const String& getResourceGroup(void) const;
01079 
01096         void setVertexProgram(const String& name, bool resetParams = true);
01103         void setVertexProgramParameters(GpuProgramParametersSharedPtr params);
01105         const String& getVertexProgramName(void) const;
01107         GpuProgramParametersSharedPtr getVertexProgramParameters(void) const;
01109         const GpuProgramPtr& getVertexProgram(void) const;
01110 
01111 
01141         void setShadowCasterVertexProgram(const String& name);
01148         void setShadowCasterVertexProgramParameters(GpuProgramParametersSharedPtr params);
01150         const String& getShadowCasterVertexProgramName(void) const;
01152         GpuProgramParametersSharedPtr getShadowCasterVertexProgramParameters(void) const;
01155         const GpuProgramPtr& getShadowCasterVertexProgram(void) const;
01156 
01182         void setShadowReceiverVertexProgram(const String& name);
01189         void setShadowReceiverVertexProgramParameters(GpuProgramParametersSharedPtr params);
01190 
01211         void setShadowReceiverFragmentProgram(const String& name);
01218         void setShadowReceiverFragmentProgramParameters(GpuProgramParametersSharedPtr params);
01219 
01221         const String& getShadowReceiverVertexProgramName(void) const;
01223         GpuProgramParametersSharedPtr getShadowReceiverVertexProgramParameters(void) const;
01226         const GpuProgramPtr& getShadowReceiverVertexProgram(void) const;
01227 
01229         const String& getShadowReceiverFragmentProgramName(void) const;
01231         GpuProgramParametersSharedPtr getShadowReceiverFragmentProgramParameters(void) const;
01234         const GpuProgramPtr& getShadowReceiverFragmentProgram(void) const;
01235 
01252         void setFragmentProgram(const String& name, bool resetParams = true);
01257         void setFragmentProgramParameters(GpuProgramParametersSharedPtr params);
01259         const String& getFragmentProgramName(void) const;
01261         GpuProgramParametersSharedPtr getFragmentProgramParameters(void) const;
01263         const GpuProgramPtr& getFragmentProgram(void) const;
01264 
01281         void setGeometryProgram(const String& name, bool resetParams = true);
01286         void setGeometryProgramParameters(GpuProgramParametersSharedPtr params);
01288         const String& getGeometryProgramName(void) const;
01290         GpuProgramParametersSharedPtr getGeometryProgramParameters(void) const;
01292         const GpuProgramPtr& getGeometryProgram(void) const;
01293 
01305         Pass* _split(unsigned short numUnits);
01306 
01308         void _notifyIndex(unsigned short index);
01309 
01311         void _prepare(void);
01313         void _unprepare(void);
01315         void _load(void);
01317         void _unload(void);
01318         // Is this loaded?
01319         bool isLoaded(void) const;
01320 
01327         uint32 getHash(void) const { return mHash; }
01329         void _dirtyHash(void);
01336         void _recalculateHash(void);
01338         void _notifyNeedsRecompile(void);
01339 
01341         void _updateAutoParamsNoLights(const AutoParamDataSource* source) const;
01343         void _updateAutoParamsLightsOnly(const AutoParamDataSource* source) const;
01344 
01351         unsigned short _getTextureUnitWithContentTypeIndex(
01352             TextureUnitState::ContentType contentType, unsigned short index) const;
01353 
01362         void setTextureFiltering(TextureFilterOptions filterType);
01371         void setTextureAnisotropy(unsigned int maxAniso);
01383         void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; }
01384 
01386         bool getNormaliseNormals(void) const {return mNormaliseNormals; }
01387 
01391         static const PassSet& getDirtyHashList(void)
01392         { return msDirtyHashList; }
01395         static const PassSet& getPassGraveyard(void)
01396         { return msPassGraveyard; }
01404         static void clearDirtyHashList(void);
01405 
01407         static void processPendingPassUpdates(void);
01408 
01410         void queueForDeletion(void);
01411 
01414         bool isAmbientOnly(void) const;
01415 
01429         void setPassIterationCount(const size_t count) { mPassIterationCount = count; }
01430 
01433         size_t getPassIterationCount(void) const { return mPassIterationCount; }
01434 
01446         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
01447 
01468         void setLightScissoringEnabled(bool enabled) { mLightScissoring = enabled; }
01472         bool getLightScissoringEnabled() const { return mLightScissoring; }
01473 
01497         void setLightClipPlanesEnabled(bool enabled) { mLightClipPlanes = enabled; }
01501         bool getLightClipPlanesEnabled() const { return mLightClipPlanes; }
01502 
01524         void setIlluminationStage(IlluminationStage is) { mIlluminationStage = is; }
01526         IlluminationStage getIlluminationStage() const { return mIlluminationStage; }
01530         enum BuiltinHashFunction
01531         {
01533             MIN_TEXTURE_CHANGE,
01538             MIN_GPU_PROGRAM_CHANGE
01539         };
01552         static void setHashFunction(BuiltinHashFunction builtin);
01553 
01565         static void setHashFunction(HashFunc* hashFunc) { msHashFunc = hashFunc; }
01566 
01569         static HashFunc* getHashFunction(void) { return msHashFunc; }
01570         
01571     };
01572 
01582     struct IlluminationPass : public PassAlloc
01583     {
01584         IlluminationStage stage;
01586         Pass* pass;
01588         bool destroyOnShutdown;
01590         Pass* originalPass;
01591 
01592         IlluminationPass() {}
01593     };
01594 
01595     typedef std::vector<IlluminationPass*> IlluminationPassList;
01596 
01597 
01598 }
01599 
01600 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Aug 28 20:53:50 2008