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         bool mHashDirtyQueued; // needs to be dirtied when next loaded
00099         //-------------------------------------------------------------------------
00100         // Colour properties, only applicable in fixed-function passes
00101         ColourValue mAmbient;
00102         ColourValue mDiffuse;
00103         ColourValue mSpecular;
00104         ColourValue mEmissive;
00105         Real mShininess;
00106         TrackVertexColourType mTracking;
00107         //-------------------------------------------------------------------------
00108 
00109         //-------------------------------------------------------------------------
00110         // Blending factors
00111         SceneBlendFactor mSourceBlendFactor;
00112         SceneBlendFactor mDestBlendFactor;
00113         SceneBlendFactor mSourceBlendFactorAlpha;
00114         SceneBlendFactor mDestBlendFactorAlpha;
00115 
00116         // Used to determine if separate alpha blending should be used for color and alpha channels
00117         bool mSeparateBlend;
00118         //-------------------------------------------------------------------------
00119 
00120         //-------------------------------------------------------------------------
00121         // Depth buffer settings
00122         bool mDepthCheck;
00123         bool mDepthWrite;
00124         CompareFunction mDepthFunc;
00125         float mDepthBiasConstant;
00126         float mDepthBiasSlopeScale;
00127         float mDepthBiasPerIteration;
00128 
00129         // Colour buffer settings
00130         bool mColourWrite;
00131 
00132         // Alpha reject settings
00133         CompareFunction mAlphaRejectFunc;
00134         unsigned char mAlphaRejectVal;
00135         bool mAlphaToCoverageEnabled;
00136 
00137         // Transparent depth sorting
00138         bool mTransparentSorting;
00139         //-------------------------------------------------------------------------
00140 
00141         //-------------------------------------------------------------------------
00142         // Culling mode
00143         CullingMode mCullMode;
00144         ManualCullingMode mManualCullMode;
00145         //-------------------------------------------------------------------------
00146 
00148         bool mLightingEnabled;
00150         unsigned short mMaxSimultaneousLights;
00152         unsigned short mStartLight;
00154         bool mIteratePerLight;
00156         unsigned short mLightsPerIteration;
00157         // Should it only be run for a certain light type?
00158         bool mRunOnlyForOneLightType;
00159         Light::LightTypes mOnlyLightType;
00160 
00162         ShadeOptions mShadeOptions;
00164         PolygonMode mPolygonMode;
00166         bool mNormaliseNormals;
00167         bool mPolygonModeOverrideable;
00168         //-------------------------------------------------------------------------
00169         // Fog
00170         bool mFogOverride;
00171         FogMode mFogMode;
00172         ColourValue mFogColour;
00173         Real mFogStart;
00174         Real mFogEnd;
00175         Real mFogDensity;
00176         //-------------------------------------------------------------------------
00177 
00179         typedef std::vector<TextureUnitState*> TextureUnitStates;
00180         TextureUnitStates mTextureUnitStates;
00181 
00182         // Vertex program details
00183         GpuProgramUsage *mVertexProgramUsage;
00184         // Vertex program details
00185         GpuProgramUsage *mShadowCasterVertexProgramUsage;
00186         // Vertex program details
00187         GpuProgramUsage *mShadowReceiverVertexProgramUsage;
00188         // Fragment program details
00189         GpuProgramUsage *mFragmentProgramUsage;
00190         // Fragment program details
00191         GpuProgramUsage *mShadowReceiverFragmentProgramUsage;
00192         // Geometry program details
00193         GpuProgramUsage *mGeometryProgramUsage;
00194         // Is this pass queued for deletion?
00195         bool mQueuedForDeletion;
00196         // number of pass iterations to perform
00197         size_t mPassIterationCount;
00198         // point size, applies when not using per-vertex point size
00199         Real mPointSize;
00200         Real mPointMinSize;
00201         Real mPointMaxSize;
00202         bool mPointSpritesEnabled;
00203         bool mPointAttenuationEnabled;
00204         // constant, linear, quadratic coeffs
00205         Real mPointAttenuationCoeffs[3];
00206         // TU Content type lookups
00207         typedef std::vector<unsigned short> ContentTypeLookup;
00208         mutable ContentTypeLookup mShadowContentTypeLookup;
00209         mutable bool mContentTypeLookupBuilt;
00211         bool mLightScissoring;
00213         bool mLightClipPlanes;
00215         IlluminationStage mIlluminationStage;
00216 
00217         // Used to get scene blending flags from a blending type
00218         void _getBlendFlags(SceneBlendType type, SceneBlendFactor& source, SceneBlendFactor& dest);
00219 
00220     public:
00221         typedef std::set<Pass*> PassSet;
00222     protected:
00224         static PassSet msDirtyHashList;
00226         static PassSet msPassGraveyard;
00228         static HashFunc* msHashFunc;
00229     public:
00230         OGRE_STATIC_MUTEX(msDirtyHashListMutex)
00231         OGRE_STATIC_MUTEX(msPassGraveyardMutex)
00232         OGRE_MUTEX(mTexUnitChangeMutex)
00233         OGRE_MUTEX(mGpuProgramChangeMutex)
00235         Pass(Technique* parent, unsigned short index);
00237         Pass(Technique* parent, unsigned short index, const Pass& oth );
00239         Pass& operator=(const Pass& oth);
00240         virtual ~Pass();
00241 
00243         bool isProgrammable(void) const { return mVertexProgramUsage || mFragmentProgramUsage || mGeometryProgramUsage; }
00245         bool hasVertexProgram(void) const { return mVertexProgramUsage != NULL; }
00247         bool hasFragmentProgram(void) const { return mFragmentProgramUsage != NULL; }
00249         bool hasGeometryProgram(void) const { return mGeometryProgramUsage != NULL; }
00251         bool hasShadowCasterVertexProgram(void) const { return mShadowCasterVertexProgramUsage != NULL; }
00253         bool hasShadowReceiverVertexProgram(void) const { return mShadowReceiverVertexProgramUsage != NULL; }
00255         bool hasShadowReceiverFragmentProgram(void) const { return mShadowReceiverFragmentProgramUsage != NULL; }
00256 
00257 
00259         unsigned short getIndex(void) const { return mIndex; }
00260         /* Set the name of the pass
00261         @remarks
00262         The name of the pass is optional.  Its useful in material scripts where a material could inherit
00263         from another material and only want to modify a particular pass.
00264         */
00265         void setName(const String& name);
00267         const String& getName(void) const { return mName; }
00268 
00280         void setAmbient(Real red, Real green, Real blue);
00281 
00294         void setAmbient(const ColourValue& ambient);
00295 
00306         void setDiffuse(Real red, Real green, Real blue, Real alpha);
00307 
00318         void setDiffuse(const ColourValue& diffuse);
00319 
00332         void setSpecular(Real red, Real green, Real blue, Real alpha);
00333 
00346         void setSpecular(const ColourValue& specular);
00347 
00353         void setShininess(Real val);
00354 
00364         void setSelfIllumination(Real red, Real green, Real blue);
00365 
00375         void setSelfIllumination(const ColourValue& selfIllum);
00376 
00379         void setVertexColourTracking(TrackVertexColourType tracking);
00380 
00386         Real getPointSize(void) const;
00387 
00403         void setPointSize(Real ps);
00404 
00410         void setPointSpritesEnabled(bool enabled);
00411 
00415         bool getPointSpritesEnabled(void) const;
00416 
00433         void setPointAttenuation(bool enabled,
00434             Real constant = 0.0f, Real linear = 1.0f, Real quadratic = 0.0f);
00435 
00437         bool isPointAttenuationEnabled(void) const;
00438 
00440         Real getPointAttenuationConstant(void) const;
00442         Real getPointAttenuationLinear(void) const;
00444         Real getPointAttenuationQuadratic(void) const;
00445 
00447         void setPointMinSize(Real min);
00449         Real getPointMinSize(void) const;
00453         void setPointMaxSize(Real max);
00457         Real getPointMaxSize(void) const;
00458 
00461         const ColourValue& getAmbient(void) const;
00462 
00465         const ColourValue& getDiffuse(void) const;
00466 
00469         const ColourValue& getSpecular(void) const;
00470 
00473         const ColourValue& getSelfIllumination(void) const;
00474 
00477         Real getShininess(void) const;
00478 
00481         TrackVertexColourType getVertexColourTracking(void) const;
00482 
00487         TextureUnitState* createTextureUnitState(void);
00498         TextureUnitState* createTextureUnitState( const String& textureName, unsigned short texCoordSet = 0);
00504         void addTextureUnitState(TextureUnitState* state);
00507         TextureUnitState* getTextureUnitState(unsigned short index);
00511         TextureUnitState* getTextureUnitState(const String& name);
00514         const TextureUnitState* getTextureUnitState(unsigned short index) const;
00518         const TextureUnitState* getTextureUnitState(const String& name) const;
00519 
00526         unsigned short getTextureUnitStateIndex(const TextureUnitState* state) const;
00527 
00528         typedef VectorIterator<TextureUnitStates> TextureUnitStateIterator;
00530         TextureUnitStateIterator getTextureUnitStateIterator(void);
00531 
00532         typedef ConstVectorIterator<TextureUnitStates> ConstTextureUnitStateIterator;
00534         ConstTextureUnitStateIterator getTextureUnitStateIterator(void) const;
00535 
00540         void removeTextureUnitState(unsigned short index);
00541 
00544         void removeAllTextureUnitStates(void);
00545 
00548         unsigned short getNumTextureUnitStates(void) const
00549         {
00550             return static_cast<unsigned short>(mTextureUnitStates.size());
00551         }
00552 
00569         void setSceneBlending( const SceneBlendType sbt );
00570 
00589         void setSeparateSceneBlending( const SceneBlendType sbt, const SceneBlendType sbta );
00590 
00613         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
00614 
00641         void setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha );
00642 
00644         bool hasSeparateSceneBlending() const;
00645 
00648         SceneBlendFactor getSourceBlendFactor() const;
00649 
00652         SceneBlendFactor getDestBlendFactor() const;
00653 
00656         SceneBlendFactor getSourceBlendFactorAlpha() const;
00657 
00660         SceneBlendFactor getDestBlendFactorAlpha() const;
00661 
00663         bool isTransparent(void) const;
00664 
00676         void setDepthCheckEnabled(bool enabled);
00677 
00682         bool getDepthCheckEnabled(void) const;
00683 
00694         void setDepthWriteEnabled(bool enabled);
00695 
00700         bool getDepthWriteEnabled(void) const;
00701 
00709         void setDepthFunction( CompareFunction func );
00714         CompareFunction getDepthFunction(void) const;
00715 
00726         void setColourWriteEnabled(bool enabled);
00728         bool getColourWriteEnabled(void) const;
00729 
00743         void setCullingMode( CullingMode mode );
00744 
00747         CullingMode getCullingMode(void) const;
00748 
00762         void setManualCullingMode( ManualCullingMode mode );
00763 
00768         ManualCullingMode getManualCullingMode(void) const;
00769 
00778         void setLightingEnabled(bool enabled);
00779 
00782         bool getLightingEnabled(void) const;
00783 
00792         void setMaxSimultaneousLights(unsigned short maxLights);
00794         unsigned short getMaxSimultaneousLights(void) const;
00795 
00806         void setStartLight(unsigned short startLight);
00808         unsigned short getStartLight(void) const;
00809 
00814         void setShadingMode( ShadeOptions mode );
00815 
00818         ShadeOptions getShadingMode(void) const;
00819 
00824         void setPolygonMode( PolygonMode mode );
00825 
00828         PolygonMode getPolygonMode(void) const;
00829 
00835         virtual void setPolygonModeOverrideable(bool override)
00836         {
00837             mPolygonModeOverrideable = override;
00838         }
00839 
00843         virtual bool getPolygonModeOverrideable(void) const
00844         {
00845             return mPolygonModeOverrideable;
00846         }
00876         void setFog(
00877             bool overrideScene,
00878             FogMode mode = FOG_NONE,
00879             const ColourValue& colour = ColourValue::White,
00880             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
00881 
00884         bool getFogOverride(void) const;
00885 
00890         FogMode getFogMode(void) const;
00891 
00894         const ColourValue& getFogColour(void) const;
00895 
00900         Real getFogStart(void) const;
00901 
00906         Real getFogEnd(void) const;
00907 
00912         Real getFogDensity(void) const;
00913 
00933         void setDepthBias(float constantBias, float slopeScaleBias = 0.0f);
00934 
00936         float getDepthBiasConstant(void) const;
00938         float getDepthBiasSlopeScale(void) const;
00945         void setIterationDepthBias(float biasPerIteration);
00949         float getIterationDepthBias() const;
00950 
00960         void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverageEnabled = false);
00961 
00964         void setAlphaRejectFunction(CompareFunction func);
00965 
00968         void setAlphaRejectValue(unsigned char val);
00969 
00972         CompareFunction getAlphaRejectFunction(void) const { return mAlphaRejectFunc; }
00973 
00976         unsigned char getAlphaRejectValue(void) const { return mAlphaRejectVal; }
00977 
00985         void setAlphaToCoverageEnabled(bool enabled);
00986 
00989         bool isAlphaToCoverageEnabled() const { return mAlphaToCoverageEnabled; }
00990 
01003         void setTransparentSortingEnabled(bool enabled);
01004 
01007         bool getTransparentSortingEnabled(void) const;
01008 
01051         void setIteratePerLight(bool enabled,
01052             bool onlyForOneLightType = true, Light::LightTypes lightType = Light::LT_POINT);
01053 
01055         bool getIteratePerLight(void) const { return mIteratePerLight; }
01057         bool getRunOnlyForOneLightType(void) const { return mRunOnlyForOneLightType; }
01060         Light::LightTypes getOnlyLightType() const { return mOnlyLightType; }
01061 
01071         void setLightCountPerIteration(unsigned short c);
01075         unsigned short getLightCountPerIteration(void) const;
01076         
01078         Technique* getParent(void) const { return mParent; }
01079 
01081         const String& getResourceGroup(void) const;
01082 
01099         void setVertexProgram(const String& name, bool resetParams = true);
01106         void setVertexProgramParameters(GpuProgramParametersSharedPtr params);
01108         const String& getVertexProgramName(void) const;
01110         GpuProgramParametersSharedPtr getVertexProgramParameters(void) const;
01112         const GpuProgramPtr& getVertexProgram(void) const;
01113 
01114 
01144         void setShadowCasterVertexProgram(const String& name);
01151         void setShadowCasterVertexProgramParameters(GpuProgramParametersSharedPtr params);
01153         const String& getShadowCasterVertexProgramName(void) const;
01155         GpuProgramParametersSharedPtr getShadowCasterVertexProgramParameters(void) const;
01158         const GpuProgramPtr& getShadowCasterVertexProgram(void) const;
01159 
01185         void setShadowReceiverVertexProgram(const String& name);
01192         void setShadowReceiverVertexProgramParameters(GpuProgramParametersSharedPtr params);
01193 
01214         void setShadowReceiverFragmentProgram(const String& name);
01221         void setShadowReceiverFragmentProgramParameters(GpuProgramParametersSharedPtr params);
01222 
01224         const String& getShadowReceiverVertexProgramName(void) const;
01226         GpuProgramParametersSharedPtr getShadowReceiverVertexProgramParameters(void) const;
01229         const GpuProgramPtr& getShadowReceiverVertexProgram(void) const;
01230 
01232         const String& getShadowReceiverFragmentProgramName(void) const;
01234         GpuProgramParametersSharedPtr getShadowReceiverFragmentProgramParameters(void) const;
01237         const GpuProgramPtr& getShadowReceiverFragmentProgram(void) const;
01238 
01255         void setFragmentProgram(const String& name, bool resetParams = true);
01260         void setFragmentProgramParameters(GpuProgramParametersSharedPtr params);
01262         const String& getFragmentProgramName(void) const;
01264         GpuProgramParametersSharedPtr getFragmentProgramParameters(void) const;
01266         const GpuProgramPtr& getFragmentProgram(void) const;
01267 
01284         void setGeometryProgram(const String& name, bool resetParams = true);
01289         void setGeometryProgramParameters(GpuProgramParametersSharedPtr params);
01291         const String& getGeometryProgramName(void) const;
01293         GpuProgramParametersSharedPtr getGeometryProgramParameters(void) const;
01295         const GpuProgramPtr& getGeometryProgram(void) const;
01296 
01308         Pass* _split(unsigned short numUnits);
01309 
01311         void _notifyIndex(unsigned short index);
01312 
01314         void _prepare(void);
01316         void _unprepare(void);
01318         void _load(void);
01320         void _unload(void);
01321         // Is this loaded?
01322         bool isLoaded(void) const;
01323 
01330         uint32 getHash(void) const { return mHash; }
01332         void _dirtyHash(void);
01339         void _recalculateHash(void);
01341         void _notifyNeedsRecompile(void);
01342 
01344         void _updateAutoParamsNoLights(const AutoParamDataSource* source) const;
01346         void _updateAutoParamsLightsOnly(const AutoParamDataSource* source) const;
01347 
01354         unsigned short _getTextureUnitWithContentTypeIndex(
01355             TextureUnitState::ContentType contentType, unsigned short index) const;
01356 
01365         void setTextureFiltering(TextureFilterOptions filterType);
01374         void setTextureAnisotropy(unsigned int maxAniso);
01386         void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; }
01387 
01389         bool getNormaliseNormals(void) const {return mNormaliseNormals; }
01390 
01394         static const PassSet& getDirtyHashList(void)
01395         { return msDirtyHashList; }
01398         static const PassSet& getPassGraveyard(void)
01399         { return msPassGraveyard; }
01407         static void clearDirtyHashList(void);
01408 
01410         static void processPendingPassUpdates(void);
01411 
01413         void queueForDeletion(void);
01414 
01417         bool isAmbientOnly(void) const;
01418 
01432         void setPassIterationCount(const size_t count) { mPassIterationCount = count; }
01433 
01436         size_t getPassIterationCount(void) const { return mPassIterationCount; }
01437 
01449         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
01450 
01471         void setLightScissoringEnabled(bool enabled) { mLightScissoring = enabled; }
01475         bool getLightScissoringEnabled() const { return mLightScissoring; }
01476 
01500         void setLightClipPlanesEnabled(bool enabled) { mLightClipPlanes = enabled; }
01504         bool getLightClipPlanesEnabled() const { return mLightClipPlanes; }
01505 
01527         void setIlluminationStage(IlluminationStage is) { mIlluminationStage = is; }
01529         IlluminationStage getIlluminationStage() const { return mIlluminationStage; }
01533         enum BuiltinHashFunction
01534         {
01536             MIN_TEXTURE_CHANGE,
01541             MIN_GPU_PROGRAM_CHANGE
01542         };
01555         static void setHashFunction(BuiltinHashFunction builtin);
01556 
01568         static void setHashFunction(HashFunc* hashFunc) { msHashFunc = hashFunc; }
01569 
01572         static HashFunc* getHashFunction(void) { return msHashFunc; }
01573         
01574     };
01575 
01585     struct IlluminationPass : public PassAlloc
01586     {
01587         IlluminationStage stage;
01589         Pass* pass;
01591         bool destroyOnShutdown;
01593         Pass* originalPass;
01594 
01595         IlluminationPass() {}
01596     };
01597 
01598     typedef std::vector<IlluminationPass*> IlluminationPassList;
01599 
01600 
01601 }
01602 
01603 #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 Sun Sep 27 22:02:24 2009