00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 00006 00007 Copyright © 2000-2002 The OGRE Team 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 */ 00025 #ifndef _Material_H__ 00026 #define _Material_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 00030 #include "OgreColourValue.h" 00031 #include "OgreException.h" 00032 #include "OgreTextureManager.h" 00033 #include "OgreBlendMode.h" 00034 #include "OgreRoot.h" 00035 #include "OgreSceneManagerEnumerator.h" 00036 #include "OgreCommon.h" 00037 #include "OgreMatrix4.h" 00038 00039 00040 namespace Ogre { 00041 00070 class _OgreExport Material : public Resource 00071 { 00072 friend class SceneManager; 00073 friend class MaterialManager; 00074 public: 00075 00078 class _OgreExport TextureLayer 00079 { 00080 friend class RenderSystem; 00081 public: 00084 enum TextureEffectType 00085 { 00087 ET_BUMP_MAP, 00089 ET_ENVIRONMENT_MAP, 00091 ET_SCROLL, 00093 ET_ROTATE, 00095 ET_TRANSFORM 00096 00097 }; 00098 00101 enum EnvMapType 00102 { 00104 ENV_PLANAR, 00106 ENV_CURVED 00107 }; 00108 00111 enum TextureTransformType 00112 { 00113 TT_TRANSLATE_U, 00114 TT_TRANSLATE_V, 00115 TT_SCALE_U, 00116 TT_SCALE_V, 00117 TT_ROTATE 00118 }; 00119 00122 enum TextureAddressingMode 00123 { 00125 TAM_WRAP, 00127 TAM_MIRROR, 00129 TAM_CLAMP 00130 }; 00131 00134 enum TextureCubeFace 00135 { 00136 CUBE_FRONT = 0, 00137 CUBE_BACK = 1, 00138 CUBE_LEFT = 2, 00139 CUBE_RIGHT = 3, 00140 CUBE_UP = 4, 00141 CUBE_DOWN = 5 00142 }; 00143 00146 struct TextureEffect { 00147 TextureEffectType type; 00148 int subtype; 00149 Real arg1, arg2; 00150 WaveformType waveType; 00151 Real base; 00152 Real frequency; 00153 Real phase; 00154 Real amplitude; 00155 Controller* controller; 00156 }; 00157 00158 00161 TextureLayer(bool deferLoad = false); 00162 00163 TextureLayer( const TextureLayer& oth ); 00164 00165 TextureLayer & operator = ( const TextureLayer& oth ); 00166 00169 ~TextureLayer(); 00170 00179 explicit TextureLayer( const String& texName, int texCoordSet = 0, bool deferLoad = false ); 00180 00183 void setDeferredLoad( bool defer ); 00184 00191 const String& getTextureName(void) const; 00192 00196 void setTextureName( const String& name ); 00197 00242 void setCubicTextureName( const String& name, bool forUVW = false ); 00243 00288 void setCubicTextureName( const String* const names, bool forUVW = false ); 00289 00308 void setAnimatedTextureName( const String& name, int numFrames, Real duration = 0 ); 00309 00329 void setAnimatedTextureName( const String* const names, int numFrames, Real duration = 0 ); 00330 00333 std::pair< uint, uint > getTextureDimensions( int frame = 0 ) const; 00334 00340 void setCurrentFrame( int frameNumber ); 00341 00344 int getCurrentFrame(void) const; 00345 00348 const String& getFrameTextureName(int frameNumber) const; 00349 00352 int getNumFrames(void) const; 00353 00356 bool isCubic(void) const; 00357 00360 bool is3D(void) const; 00361 00364 int getTextureCoordSet(void) const; 00365 00371 void setTextureCoordSet(int set); 00372 00386 void setTextureTransform(const Matrix4& xform); 00387 00393 const Matrix4& getTextureTransform(void); 00394 00405 void setTextureScroll(Real u, Real v); 00406 00410 void setTextureUScroll(Real value); 00411 00414 void setTextureVScroll(Real value); 00415 00418 void setTextureUScale(Real value); 00419 00422 void setTextureVScale(Real value); 00423 00435 void setTextureScale(Real uScale, Real vScale); 00436 00444 void setTextureRotate(Real degrees); 00445 00450 TextureAddressingMode getTextureAddressingMode(void) const; 00451 00456 void setTextureAddressingMode( TextureAddressingMode tam); 00457 00520 void setColourOperationEx( 00521 LayerBlendOperationEx op, 00522 LayerBlendSource source1 = LBS_TEXTURE, 00523 LayerBlendSource source2 = LBS_CURRENT, 00524 00525 const ColourValue& arg1 = ColourValue::White, 00526 const ColourValue& arg2 = ColourValue::White, 00527 00528 Real manualBlend = 0.0); 00529 00546 void setColourOperation( const LayerBlendOperation op); 00547 00564 void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor); 00565 00568 LayerBlendModeEx getColourBlendMode(void) const; 00569 00572 LayerBlendModeEx getAlphaBlendMode(void) const; 00573 00576 SceneBlendFactor getColourBlendFallbackSrc(void) const; 00577 00580 SceneBlendFactor getColourBlendFallbackDest(void) const; 00581 00605 void setAlphaOperation(LayerBlendOperationEx op, 00606 LayerBlendSource source1 = LBS_TEXTURE, 00607 LayerBlendSource source2 = LBS_CURRENT, 00608 Real arg1 = 1.0, 00609 Real arg2 = 1.0, 00610 Real manualBlend = 0.0); 00611 00621 void addEffect(TextureEffect& effect); 00622 00648 void setEnvironmentMap(bool enable, bool planar = false); 00649 00658 void setScrollAnimation(Real uSpeed, Real vSpeed); 00659 00666 void setRotateAnimation(Real speed); 00667 00685 void setTransformAnimation( const TextureTransformType ttype, 00686 const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 ); 00687 00696 void setAlphaRejectSettings( const CompareFunction func, unsigned char value ); 00697 00700 CompareFunction getAlphaRejectFunction(void) const; 00701 00704 unsigned char getAlphaRejectValue(void) const; 00705 00708 void removeAllEffects(void); 00709 00715 void removeEffect( const TextureEffectType type ); 00716 00722 bool isBlank(void) const; 00723 00726 void setBlank(void); 00727 00730 void _load(void); 00731 00732 protected: 00733 // State 00734 #define MAX_FRAMES 32 00735 00737 int mNumFrames; 00739 int mCurrentFrame; 00740 // String mFrames[MAX_FRAMES] is at the end of the class 00741 00743 Real mAnimDuration; 00744 Controller* mAnimController; 00745 bool mCubic; 00746 00747 int textureCoordSetIndex; 00748 TextureAddressingMode mAddressMode; 00749 00750 LayerBlendModeEx colourBlendMode; 00751 SceneBlendFactor colourBlendFallbackSrc; 00752 SceneBlendFactor colourBlendFallbackDest; 00753 00754 LayerBlendModeEx alphaBlendMode; 00755 bool mIsBlank; 00756 bool mDeferLoad; 00757 00758 bool mRecalcTexMatrix; 00759 Real mUMod, mVMod; 00760 Real mUScale, mVScale; 00761 Real mRotate; 00762 Matrix4 mTexModMatrix; 00763 CompareFunction mAlphaRejectFunc; 00764 unsigned char mAlphaRejectVal; 00765 00766 // Animation, will be set up as Controllers 00767 Real mUScrollAnim, mVScrollAnim; 00768 Real mRotateAnim; 00769 00770 00771 //----------------------------------------------------------------------------- 00772 // Complex members (those that can't be copied using memcpy) are at the end to 00773 // allow for fast copying of the basic members. 00774 // 00775 String mFrames[MAX_FRAMES]; // Names of frames 00776 00777 typedef std::multimap<TextureEffectType, TextureEffect> EffectMap; 00778 EffectMap mEffects; 00779 //----------------------------------------------------------------------------- 00780 00781 00782 00785 void recalcTextureMatrix(void); 00786 00789 void createAnimController(void); 00790 00793 void createEffectController(TextureEffect& effect); 00794 00795 00796 }; 00797 00798 //----------------------------------------------------------------------------- 00799 // Add only basic data types here (ie those that can be memcpy()'d) 00800 // 00801 protected: 00802 //------------------------------------------------------------------------- 00803 // Colour properties 00804 ColourValue mAmbient; 00805 ColourValue mDiffuse; 00806 ColourValue mSpecular; 00807 ColourValue mEmissive; 00808 Real mShininess; 00809 //------------------------------------------------------------------------- 00810 00812 static Material* mDefaultSettings; 00813 00819 int mHandle; 00820 00821 //------------------------------------------------------------------------- 00822 // Blending factors 00823 SceneBlendFactor mSourceBlendFactor; 00824 SceneBlendFactor mDestBlendFactor; 00825 //------------------------------------------------------------------------- 00826 00827 //------------------------------------------------------------------------- 00828 // Depth buffer settings 00829 bool mDepthCheck; 00830 bool mDepthWrite; 00831 CompareFunction mDepthFunc; 00832 ushort mDepthBias; 00833 00834 //------------------------------------------------------------------------- 00835 00836 //------------------------------------------------------------------------- 00837 // Culling mode 00838 CullingMode mCullMode; 00839 ManualCullingMode mManualCullMode; 00840 //------------------------------------------------------------------------- 00841 00843 bool mLightingEnabled; 00844 00846 ShadeOptions mShadeOptions; 00847 00849 TextureFilterOptions mTextureFiltering; 00850 00851 //------------------------------------------------------------------------- 00852 // Fog 00853 bool mFogOverride; 00854 FogMode mFogMode; 00855 ColourValue mFogColour; 00856 Real mFogStart; 00857 Real mFogEnd; 00858 Real mFogDensity; 00859 //------------------------------------------------------------------------- 00860 00861 00865 bool mDeferLoad; 00866 00868 int mNumTextureLayers; 00869 //----------------------------------------------------------------------------- 00870 00871 //----------------------------------------------------------------------------- 00872 // Add only complex data types here (ie the ones that can't be memcpy()'d 00873 // 00874 protected: 00875 TextureLayer mTextureLayers[OGRE_MAX_TEXTURE_LAYERS]; 00876 //----------------------------------------------------------------------------- 00877 00878 //----------------------------------------------------------------------------- 00879 // Add protected member functions here 00880 // 00881 protected: 00884 void applyDefaults(void); 00885 00887 void assignNextHandle(void); 00888 //----------------------------------------------------------------------------- 00889 00890 public: 00891 00901 Material( const String& name, bool deferLoad = false ); 00902 00905 Material(); 00906 00909 Material& operator=( const Material& rhs ); 00910 00913 const String& getName(void) const; 00914 00920 int getHandle(void) const; 00921 00932 void setAmbient(Real red, Real green, Real blue); 00933 00945 void setAmbient(const ColourValue& ambient); 00946 00956 void setDiffuse(Real red, Real green, Real blue); 00957 00967 void setDiffuse(const ColourValue& diffuse); 00968 00980 void setSpecular(Real red, Real green, Real blue); 00981 00993 void setSpecular(const ColourValue& specular); 00994 00997 void setShininess(Real val); 00998 01005 void setSelfIllumination(Real red, Real green, Real blue); 01006 01013 void setSelfIllumination(const ColourValue& selfIllum); 01014 01017 const ColourValue& getAmbient(void) const; 01018 01021 const ColourValue& getDiffuse(void) const; 01022 01025 const ColourValue& getSpecular(void) const; 01026 01029 const ColourValue& getSelfIllumination(void) const; 01030 01033 Real getShininess(void) const; 01034 01048 TextureLayer* addTextureLayer( const String& textureName, int texCoordSet = 0); 01049 01052 TextureLayer* getTextureLayer(int index) const; 01053 01056 void removeTextureLayer(); 01057 01060 void removeAllTextureLayers(void); 01061 01064 int getNumTextureLayers(void) const 01065 { 01066 return mNumTextureLayers; 01067 } 01068 01082 void setSceneBlending( const SceneBlendType sbt ); 01083 01104 void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor); 01105 01108 SceneBlendFactor getSourceBlendFactor() const; 01109 01112 SceneBlendFactor getDestBlendFactor() const; 01113 01116 bool isTransparent(void) const; 01117 01129 void setDepthCheckEnabled(bool enabled); 01130 01135 bool getDepthCheckEnabled(void) const; 01136 01147 void setDepthWriteEnabled(bool enabled); 01148 01153 bool getDepthWriteEnabled(void) const; 01154 01162 void setDepthFunction( CompareFunction func ); 01167 CompareFunction getDepthFunction(void) const; 01168 01182 void setCullingMode( CullingMode mode ); 01183 01186 CullingMode getCullingMode(void) const; 01187 01201 void setManualCullingMode( ManualCullingMode mode ); 01202 01207 ManualCullingMode getManualCullingMode(void) const; 01208 01217 void setLightingEnabled(bool enabled); 01218 01221 bool getLightingEnabled(void) const; 01222 01227 void setShadingMode( ShadeOptions mode ); 01228 01231 ShadeOptions getShadingMode(void) const; 01232 01239 void setTextureFiltering( TextureFilterOptions mode ); 01240 01243 TextureFilterOptions getTextureFiltering(void) const; 01244 01274 void setFog( 01275 bool overrideScene, 01276 FogMode mode = FOG_NONE, 01277 const ColourValue& colour = ColourValue::White, 01278 Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 ); 01279 01282 bool getFogOverride(void) const; 01283 01288 FogMode getFogMode(void) const; 01289 01292 const ColourValue& getFogColour(void) const; 01293 01298 Real getFogStart(void) const; 01299 01304 Real getFogEnd(void) const; 01305 01310 Real getFogDensity(void) const; 01311 01320 void load(void); 01321 01326 void unload(void); 01327 01332 bool _compareSurfaceParams( const Material& cmp ) const; 01333 01336 Material* clone(const String& newName); 01337 01342 void copyDetailsTo(Material* mat); 01343 01356 void setDepthBias(ushort bias); 01357 01359 ushort getDepthBias(void); 01360 }; 01361 01362 } //namespace 01363 01364 #endif
Copyright © 2002 by The OGRE Team