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) 00231 OGRE_MUTEX(mTexUnitChangeMutex) 00232 OGRE_MUTEX(mGpuProgramChangeMutex) 00234 Pass(Technique* parent, unsigned short index); 00236 Pass(Technique* parent, unsigned short index, const Pass& oth ); 00238 Pass& operator=(const Pass& oth); 00239 virtual ~Pass(); 00240 00242 bool isProgrammable(void) const { return mVertexProgramUsage || mFragmentProgramUsage || mGeometryProgramUsage; } 00244 bool hasVertexProgram(void) const { return mVertexProgramUsage != NULL; } 00246 bool hasFragmentProgram(void) const { return mFragmentProgramUsage != NULL; } 00248 bool hasGeometryProgram(void) const { return mGeometryProgramUsage != NULL; } 00250 bool hasShadowCasterVertexProgram(void) const { return mShadowCasterVertexProgramUsage != NULL; } 00252 bool hasShadowReceiverVertexProgram(void) const { return mShadowReceiverVertexProgramUsage != NULL; } 00254 bool hasShadowReceiverFragmentProgram(void) const { return mShadowReceiverFragmentProgramUsage != NULL; } 00255 00256 00258 unsigned short getIndex(void) const { return mIndex; } 00259 /* Set the name of the pass 00260 @remarks 00261 The name of the pass is optional. Its useful in material scripts where a material could inherit 00262 from another material and only want to modify a particular pass. 00263 */ 00264 void setName(const String& name); 00266 const String& getName(void) const { return mName; } 00267 00279 void setAmbient(Real red, Real green, Real blue); 00280 00293 void setAmbient(const ColourValue& ambient); 00294 00305 void setDiffuse(Real red, Real green, Real blue, Real alpha); 00306 00317 void setDiffuse(const ColourValue& diffuse); 00318 00331 void setSpecular(Real red, Real green, Real blue, Real alpha); 00332 00345 void setSpecular(const ColourValue& specular); 00346 00352 void setShininess(Real val); 00353 00363 void setSelfIllumination(Real red, Real green, Real blue); 00364 00374 void setSelfIllumination(const ColourValue& selfIllum); 00375 00378 void setVertexColourTracking(TrackVertexColourType tracking); 00379 00385 Real getPointSize(void) const; 00386 00402 void setPointSize(Real ps); 00403 00409 void setPointSpritesEnabled(bool enabled); 00410 00414 bool getPointSpritesEnabled(void) const; 00415 00432 void setPointAttenuation(bool enabled, 00433 Real constant = 0.0f, Real linear = 1.0f, Real quadratic = 0.0f); 00434 00436 bool isPointAttenuationEnabled(void) const; 00437 00439 Real getPointAttenuationConstant(void) const; 00441 Real getPointAttenuationLinear(void) const; 00443 Real getPointAttenuationQuadratic(void) const; 00444 00446 void setPointMinSize(Real min); 00448 Real getPointMinSize(void) const; 00452 void setPointMaxSize(Real max); 00456 Real getPointMaxSize(void) const; 00457 00460 const ColourValue& getAmbient(void) const; 00461 00464 const ColourValue& getDiffuse(void) const; 00465 00468 const ColourValue& getSpecular(void) const; 00469 00472 const ColourValue& getSelfIllumination(void) const; 00473 00476 Real getShininess(void) const; 00477 00480 TrackVertexColourType getVertexColourTracking(void) const; 00481 00486 TextureUnitState* createTextureUnitState(void); 00497 TextureUnitState* createTextureUnitState( const String& textureName, unsigned short texCoordSet = 0); 00503 void addTextureUnitState(TextureUnitState* state); 00506 TextureUnitState* getTextureUnitState(unsigned short index); 00510 TextureUnitState* getTextureUnitState(const String& name); 00513 const TextureUnitState* getTextureUnitState(unsigned short index) const; 00517 const TextureUnitState* getTextureUnitState(const String& name) const; 00518 00525 unsigned short getTextureUnitStateIndex(const TextureUnitState* state) const; 00526 00527 typedef VectorIterator<TextureUnitStates> TextureUnitStateIterator; 00529 TextureUnitStateIterator getTextureUnitStateIterator(void); 00530 00531 typedef ConstVectorIterator<TextureUnitStates> ConstTextureUnitStateIterator; 00533 ConstTextureUnitStateIterator getTextureUnitStateIterator(void) const; 00534 00539 void removeTextureUnitState(unsigned short index); 00540 00543 void removeAllTextureUnitStates(void); 00544 00547 unsigned short getNumTextureUnitStates(void) const 00548 { 00549 return static_cast<unsigned short>(mTextureUnitStates.size()); 00550 } 00551 00568 void setSceneBlending( const SceneBlendType sbt ); 00569 00588 void setSeparateSceneBlending( const SceneBlendType sbt, const SceneBlendType sbta ); 00589 00612 void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor); 00613 00640 void setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha ); 00641 00643 bool hasSeparateSceneBlending() const; 00644 00647 SceneBlendFactor getSourceBlendFactor() const; 00648 00651 SceneBlendFactor getDestBlendFactor() const; 00652 00655 SceneBlendFactor getSourceBlendFactorAlpha() const; 00656 00659 SceneBlendFactor getDestBlendFactorAlpha() const; 00660 00662 bool isTransparent(void) const; 00663 00675 void setDepthCheckEnabled(bool enabled); 00676 00681 bool getDepthCheckEnabled(void) const; 00682 00693 void setDepthWriteEnabled(bool enabled); 00694 00699 bool getDepthWriteEnabled(void) const; 00700 00708 void setDepthFunction( CompareFunction func ); 00713 CompareFunction getDepthFunction(void) const; 00714 00725 void setColourWriteEnabled(bool enabled); 00727 bool getColourWriteEnabled(void) const; 00728 00742 void setCullingMode( CullingMode mode ); 00743 00746 CullingMode getCullingMode(void) const; 00747 00761 void setManualCullingMode( ManualCullingMode mode ); 00762 00767 ManualCullingMode getManualCullingMode(void) const; 00768 00777 void setLightingEnabled(bool enabled); 00778 00781 bool getLightingEnabled(void) const; 00782 00791 void setMaxSimultaneousLights(unsigned short maxLights); 00793 unsigned short getMaxSimultaneousLights(void) const; 00794 00805 void setStartLight(unsigned short startLight); 00807 unsigned short getStartLight(void) const; 00808 00813 void setShadingMode( ShadeOptions mode ); 00814 00817 ShadeOptions getShadingMode(void) const; 00818 00823 void setPolygonMode( PolygonMode mode ); 00824 00827 PolygonMode getPolygonMode(void) const; 00828 00834 virtual void setPolygonModeOverrideable(bool override) 00835 { 00836 mPolygonModeOverrideable = override; 00837 } 00838 00842 virtual bool getPolygonModeOverrideable(void) const 00843 { 00844 return mPolygonModeOverrideable; 00845 } 00875 void setFog( 00876 bool overrideScene, 00877 FogMode mode = FOG_NONE, 00878 const ColourValue& colour = ColourValue::White, 00879 Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 ); 00880 00883 bool getFogOverride(void) const; 00884 00889 FogMode getFogMode(void) const; 00890 00893 const ColourValue& getFogColour(void) const; 00894 00899 Real getFogStart(void) const; 00900 00905 Real getFogEnd(void) const; 00906 00911 Real getFogDensity(void) const; 00912 00932 void setDepthBias(float constantBias, float slopeScaleBias = 0.0f); 00933 00935 float getDepthBiasConstant(void) const; 00937 float getDepthBiasSlopeScale(void) const; 00944 void setIterationDepthBias(float biasPerIteration); 00948 float getIterationDepthBias() const; 00949 00959 void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverageEnabled = false); 00960 00963 void setAlphaRejectFunction(CompareFunction func); 00964 00967 void setAlphaRejectValue(unsigned char val); 00968 00971 CompareFunction getAlphaRejectFunction(void) const { return mAlphaRejectFunc; } 00972 00975 unsigned char getAlphaRejectValue(void) const { return mAlphaRejectVal; } 00976 00984 void setAlphaToCoverageEnabled(bool enabled); 00985 00988 bool isAlphaToCoverageEnabled() const { return mAlphaToCoverageEnabled; } 00989 01002 void setTransparentSortingEnabled(bool enabled); 01003 01006 bool getTransparentSortingEnabled(void) const; 01007 01050 void setIteratePerLight(bool enabled, 01051 bool onlyForOneLightType = true, Light::LightTypes lightType = Light::LT_POINT); 01052 01054 bool getIteratePerLight(void) const { return mIteratePerLight; } 01056 bool getRunOnlyForOneLightType(void) const { return mRunOnlyForOneLightType; } 01059 Light::LightTypes getOnlyLightType() const { return mOnlyLightType; } 01060 01070 void setLightCountPerIteration(unsigned short c); 01074 unsigned short getLightCountPerIteration(void) const; 01075 01077 Technique* getParent(void) const { return mParent; } 01078 01080 const String& getResourceGroup(void) const; 01081 01098 void setVertexProgram(const String& name, bool resetParams = true); 01105 void setVertexProgramParameters(GpuProgramParametersSharedPtr params); 01107 const String& getVertexProgramName(void) const; 01109 GpuProgramParametersSharedPtr getVertexProgramParameters(void) const; 01111 const GpuProgramPtr& getVertexProgram(void) const; 01112 01113 01143 void setShadowCasterVertexProgram(const String& name); 01150 void setShadowCasterVertexProgramParameters(GpuProgramParametersSharedPtr params); 01152 const String& getShadowCasterVertexProgramName(void) const; 01154 GpuProgramParametersSharedPtr getShadowCasterVertexProgramParameters(void) const; 01157 const GpuProgramPtr& getShadowCasterVertexProgram(void) const; 01158 01184 void setShadowReceiverVertexProgram(const String& name); 01191 void setShadowReceiverVertexProgramParameters(GpuProgramParametersSharedPtr params); 01192 01213 void setShadowReceiverFragmentProgram(const String& name); 01220 void setShadowReceiverFragmentProgramParameters(GpuProgramParametersSharedPtr params); 01221 01223 const String& getShadowReceiverVertexProgramName(void) const; 01225 GpuProgramParametersSharedPtr getShadowReceiverVertexProgramParameters(void) const; 01228 const GpuProgramPtr& getShadowReceiverVertexProgram(void) const; 01229 01231 const String& getShadowReceiverFragmentProgramName(void) const; 01233 GpuProgramParametersSharedPtr getShadowReceiverFragmentProgramParameters(void) const; 01236 const GpuProgramPtr& getShadowReceiverFragmentProgram(void) const; 01237 01254 void setFragmentProgram(const String& name, bool resetParams = true); 01259 void setFragmentProgramParameters(GpuProgramParametersSharedPtr params); 01261 const String& getFragmentProgramName(void) const; 01263 GpuProgramParametersSharedPtr getFragmentProgramParameters(void) const; 01265 const GpuProgramPtr& getFragmentProgram(void) const; 01266 01283 void setGeometryProgram(const String& name, bool resetParams = true); 01288 void setGeometryProgramParameters(GpuProgramParametersSharedPtr params); 01290 const String& getGeometryProgramName(void) const; 01292 GpuProgramParametersSharedPtr getGeometryProgramParameters(void) const; 01294 const GpuProgramPtr& getGeometryProgram(void) const; 01295 01307 Pass* _split(unsigned short numUnits); 01308 01310 void _notifyIndex(unsigned short index); 01311 01313 void _prepare(void); 01315 void _unprepare(void); 01317 void _load(void); 01319 void _unload(void); 01320 // Is this loaded? 01321 bool isLoaded(void) const; 01322 01329 uint32 getHash(void) const { return mHash; } 01331 void _dirtyHash(void); 01338 void _recalculateHash(void); 01340 void _notifyNeedsRecompile(void); 01341 01343 void _updateAutoParamsNoLights(const AutoParamDataSource* source) const; 01345 void _updateAutoParamsLightsOnly(const AutoParamDataSource* source) const; 01346 01353 unsigned short _getTextureUnitWithContentTypeIndex( 01354 TextureUnitState::ContentType contentType, unsigned short index) const; 01355 01364 void setTextureFiltering(TextureFilterOptions filterType); 01373 void setTextureAnisotropy(unsigned int maxAniso); 01385 void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; } 01386 01388 bool getNormaliseNormals(void) const {return mNormaliseNormals; } 01389 01393 static const PassSet& getDirtyHashList(void) 01394 { return msDirtyHashList; } 01397 static const PassSet& getPassGraveyard(void) 01398 { return msPassGraveyard; } 01406 static void clearDirtyHashList(void); 01407 01409 static void processPendingPassUpdates(void); 01410 01412 void queueForDeletion(void); 01413 01416 bool isAmbientOnly(void) const; 01417 01431 void setPassIterationCount(const size_t count) { mPassIterationCount = count; } 01432 01435 size_t getPassIterationCount(void) const { return mPassIterationCount; } 01436 01448 bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const; 01449 01470 void setLightScissoringEnabled(bool enabled) { mLightScissoring = enabled; } 01474 bool getLightScissoringEnabled() const { return mLightScissoring; } 01475 01499 void setLightClipPlanesEnabled(bool enabled) { mLightClipPlanes = enabled; } 01503 bool getLightClipPlanesEnabled() const { return mLightClipPlanes; } 01504 01526 void setIlluminationStage(IlluminationStage is) { mIlluminationStage = is; } 01528 IlluminationStage getIlluminationStage() const { return mIlluminationStage; } 01532 enum BuiltinHashFunction 01533 { 01535 MIN_TEXTURE_CHANGE, 01540 MIN_GPU_PROGRAM_CHANGE 01541 }; 01554 static void setHashFunction(BuiltinHashFunction builtin); 01555 01567 static void setHashFunction(HashFunc* hashFunc) { msHashFunc = hashFunc; } 01568 01571 static HashFunc* getHashFunction(void) { return msHashFunc; } 01572 01573 }; 01574 01584 struct IlluminationPass : public PassAlloc 01585 { 01586 IlluminationStage stage; 01588 Pass* pass; 01590 bool destroyOnShutdown; 01592 Pass* originalPass; 01593 01594 IlluminationPass() {} 01595 }; 01596 01597 typedef std::vector<IlluminationPass*> IlluminationPassList; 01598 01599 01600 } 01601 01602 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Tue Nov 4 11:02:31 2008