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 __D3DRENDERSYSTEM_H__ 00026 #define __D3DRENDERSYSTEM_H__ 00027 00028 // Precompiler options 00029 #include "OgreD3D7Prerequisites.h" 00030 #include "OgreString.h" 00031 00032 00033 00034 #include "OgreRenderSystem.h" 00035 #include "OgreD3D7HardwareBufferManager.h" 00036 00037 namespace Ogre { 00038 00039 class DDDriverList; 00040 class DDDriver; 00041 00045 class D3DRenderSystem : public RenderSystem 00046 { 00047 private: 00048 // Direct3D rendering device 00049 // Only created after top-level window created 00050 LPDIRECT3DDEVICE7 mlpD3DDevice; 00051 D3DDEVICEDESC7 mD3DDeviceDesc; 00052 00053 // List of DD drivers installed (video cards) 00054 // Enumerates itself 00055 DDDriverList* mDriverList; 00056 // Currently active driver 00057 DDDriver* mActiveDDDriver; 00058 00059 00060 HINSTANCE mhInstance; 00061 00062 00063 00064 // Stored options 00065 ConfigOptionMap mOptions; 00066 00067 // Private utilities 00068 DDDriverList* getDirectDrawDrivers(void); 00069 void refreshDDSettings(void); 00070 00072 enum eD3DTexType 00073 { 00075 D3D_TEX_TYPE_NORMAL, 00077 D3D_TEX_TYPE_CUBE, 00079 D3D_TEX_TYPE_VOLUME 00080 }; 00081 00083 eD3DTexType _ogreTexTypeToD3DTexType(TextureType ogreTexType) 00084 { 00085 eD3DTexType ret; 00086 switch (ogreTexType) 00087 { 00088 case TEX_TYPE_1D : 00089 case TEX_TYPE_2D : 00090 ret = D3D_TEX_TYPE_NORMAL; 00091 break; 00092 case TEX_TYPE_CUBE_MAP : 00093 ret = D3D_TEX_TYPE_CUBE; 00094 break; 00095 default : 00096 Except( Exception::ERR_INVALIDPARAMS, "Invalid tex.type", "D3D9RenderSystem::_ogreTexTypeToD3DTexType" ); 00097 break; 00098 } 00099 return ret; 00100 } 00101 00103 struct sD3DTextureStageDesc 00104 { 00106 eD3DTexType texType; 00108 size_t coordIndex; 00110 TexCoordCalcMethod autoTexCoordType; 00112 LPDIRECTDRAWSURFACE7 pTex; 00113 } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS]; 00114 00115 00116 // Matrix conversion 00117 D3DMATRIX makeD3DMatrix(const Matrix4& mat); 00118 Matrix4 convertD3DMatrix(const D3DMATRIX& mat); 00119 00120 void initConfigOptions(void); 00121 void initInputDevices(void); 00122 void processInputDevices(void); 00123 void setD3DLight(size_t index, Light* light); 00124 00125 D3DCMPFUNC convertCompareFunction(CompareFunction func); 00126 D3DSTENCILOP convertStencilOp(StencilOperation op); 00127 00128 // state management methods, very primitive !!! 00129 HRESULT __SetRenderState(D3DRENDERSTATETYPE state, DWORD value); 00130 HRESULT __SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value); 00131 00132 00133 D3DTEXTURESTAGESTATETYPE _getFilterCode(FilterType ft); 00134 DWORD _getFilter(FilterType ft, FilterOptions fo); 00135 DWORD _getCurrentAnisotropy(size_t unit); 00136 00137 HardwareBufferManager* mHardwareBufferManager; 00138 GpuProgramManager* mGpuProgramManager; 00139 00140 bool mForcedNormalisation; 00141 00142 unsigned short mCurrentLights; 00143 00144 00145 public: 00146 // Default constructor / destructor 00147 D3DRenderSystem(HINSTANCE hInstance); 00148 ~D3DRenderSystem(); 00149 00150 00151 00152 // ---------------------------------- 00153 // Overridden RenderSystem functions 00154 // ---------------------------------- 00158 const String& getName(void) const; 00162 ConfigOptionMap& getConfigOptions(void); 00166 void setConfigOption(const String &name, const String &value); 00170 String validateConfigOptions(void); 00174 RenderWindow* initialise(bool autoCreateWindow); 00178 void reinitialise(void); // Used if settings changed mid-rendering 00182 void shutdown(void); 00183 00187 void setAmbientLight(float r, float g, float b); 00191 void setShadingType(ShadeOptions so); 00195 void setLightingEnabled(bool enabled); 00199 RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, unsigned int colourDepth, 00200 bool fullScreen, int left = 0, int top = 0, bool depthBuffer = true, 00201 RenderWindow* parentWindowHandle = 0); 00202 00203 RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height ); 00204 00208 void destroyRenderWindow(RenderWindow* pWin); 00209 00213 String getErrorDescription(long errorNumber); 00214 00218 void convertColourValue(const ColourValue& colour, unsigned long* pDest); 00219 00220 // ----------------------------- 00221 // Low-level overridden members 00222 // ----------------------------- 00226 void _useLights(const LightList& lights, unsigned short limit); 00230 void _setWorldMatrix(const Matrix4 &m); 00234 void _setViewMatrix(const Matrix4 &m); 00238 void _setProjectionMatrix(const Matrix4 &m); 00242 void _setSurfaceParams(const ColourValue &ambient, 00243 const ColourValue &diffuse, const ColourValue &specular, 00244 const ColourValue &emissive, Real shininess); 00248 void _setTexture(size_t unit, bool enabled, const String &texname); 00252 void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm); 00256 void _setTextureAddressingMode(size_t unit, TextureUnitState::TextureAddressingMode tam); 00260 void _setTextureMatrix(size_t unit, const Matrix4& xform); 00264 void _setTextureCoordSet( size_t unit, size_t index ); 00268 void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m); 00272 void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor); 00276 void _setAlphaRejectSettings(CompareFunction func, unsigned char value); 00280 void _setViewport(Viewport *vp); 00284 void _beginFrame(void); 00288 void _render(const RenderOperation& op); 00292 void _endFrame(void); 00296 void _setCullingMode(CullingMode mode); 00300 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00304 void _setDepthBufferCheckEnabled(bool enabled = true); 00308 void _setDepthBufferWriteEnabled(bool enabled = true); 00312 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00316 void _setDepthBias(ushort bias); 00322 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) {} 00323 00327 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00331 void _makeProjectionMatrix(Real fovy, Real aspect, Real nearPlane, 00332 Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00336 void _setRasterisationMode(SceneDetailLevel level); 00340 void setStencilCheckEnabled(bool enabled); 00344 void setStencilBufferFunction(CompareFunction func); 00348 void setStencilBufferReferenceValue(ulong refValue); 00352 void setStencilBufferMask(ulong mask); 00356 void setStencilBufferFailOperation(StencilOperation op); 00360 void setStencilBufferDepthFailOperation(StencilOperation op); 00364 void setStencilBufferPassOperation(StencilOperation op); 00368 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00372 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00376 void setVertexDeclaration(VertexDeclaration* decl); 00380 void setVertexBufferBinding(VertexBufferBinding* binding); 00384 void setNormaliseNormals(bool normalise); 00388 void bindGpuProgram(GpuProgram* prg) { /* do nothing */} 00392 void unbindGpuProgram(GpuProgramType gptype){ /* do nothing */} 00396 void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) { /* do nothing */} 00397 00398 // ---------------------------------- 00399 // End Overridden members 00400 // ---------------------------------- 00401 }; 00402 } 00403 #endif 00404
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:06 2004