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 (c) 2000-2005 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 __D3D9RENDERSYSTEM_H__ 00026 #define __D3D9RENDERSYSTEM_H__ 00027 00028 #include "OgreD3D9Prerequisites.h" 00029 #include "OgreString.h" 00030 #include "OgreStringConverter.h" 00031 #include "OgreRenderSystem.h" 00032 #include "OgreD3D9Mappings.h" 00033 00034 #include "OgreNoMemoryMacros.h" 00035 #include <d3d9.h> 00036 #include <d3dx9.h> 00037 #include <dxerr9.h> 00038 #include "OgreMemoryMacros.h" 00039 00040 namespace Ogre 00041 { 00042 #define MAX_LIGHTS 8 00043 00044 class D3D9DriverList; 00045 class D3D9Driver; 00046 00050 class D3D9RenderSystem : public RenderSystem 00051 { 00052 private: 00054 LPDIRECT3D9 mpD3D; 00056 LPDIRECT3DDEVICE9 mpD3DDevice; 00057 00058 // Stored options 00059 ConfigOptionMap mOptions; 00061 D3DMULTISAMPLE_TYPE mFSAAType; 00063 DWORD mFSAAQuality; 00064 00066 HINSTANCE mhInstance; 00067 00069 D3D9DriverList* mDriverList; 00071 D3D9Driver* mActiveD3DDriver; 00073 D3DCAPS9 mCaps; 00074 00076 struct sD3DTextureStageDesc 00077 { 00079 D3D9Mappings::eD3DTexType texType; 00081 size_t coordIndex; 00083 TexCoordCalcMethod autoTexCoordType; 00085 const Frustum *frustum; 00087 IDirect3DBaseTexture9 *pTex; 00088 } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS]; 00089 00090 // Array of up to 8 lights, indexed as per API 00091 // Note that a null value indeicates a free slot 00092 Light* mLights[MAX_LIGHTS]; 00093 00094 D3D9DriverList* getDirect3DDrivers(void); 00095 void refreshD3DSettings(void); 00096 void freeDevice(void); 00097 00098 inline bool compareDecls( D3DVERTEXELEMENT9* pDecl1, D3DVERTEXELEMENT9* pDecl2, size_t size ); 00099 00100 00101 void initInputDevices(void); 00102 void processInputDevices(void); 00103 void setD3D9Light( size_t index, Light* light ); 00104 00105 // state management methods, very primitive !!! 00106 HRESULT __SetRenderState(D3DRENDERSTATETYPE state, DWORD value); 00107 HRESULT __SetSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value); 00108 HRESULT __SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value); 00109 00110 HRESULT __SetFloatRenderState(D3DRENDERSTATETYPE state, Real value) 00111 { 00112 #if OGRE_DOUBLE_PRECISION == 1 00113 float temp = static_cast<float>(value); 00114 return __SetRenderState(state, *((LPDWORD)(&temp))); 00115 #else 00116 return __SetRenderState(state, *((LPDWORD)(&value))); 00117 #endif 00118 } 00119 00121 DWORD _getCurrentAnisotropy(size_t unit); 00123 bool _checkMultiSampleQuality(D3DMULTISAMPLE_TYPE type, DWORD *outQuality, D3DFORMAT format, UINT adapterNum, D3DDEVTYPE deviceType, BOOL fullScreen); 00125 void _setFSAA(D3DMULTISAMPLE_TYPE type, DWORD qualityLevel); 00126 00127 D3D9HardwareBufferManager* mHardwareBufferManager; 00128 D3D9GpuProgramManager* mGpuProgramManager; 00129 //D3D9HLSLProgramFactory* mHLSLProgramFactory; 00130 00131 size_t mLastVertexSourceCount; 00132 00133 00135 void initCapabilities(void); 00136 00137 void convertVertexShaderCaps(void); 00138 void convertPixelShaderCaps(void); 00139 00140 unsigned short mCurrentLights; 00142 Matrix4 mViewMatrix; 00143 00144 // What follows is a set of duplicated lists just to make it 00145 // easier to deal with lost devices 00146 00148 D3D9RenderWindow* mPrimaryWindow; 00149 00150 typedef std::vector<D3D9RenderWindow*> SecondaryWindowList; 00151 // List of additional windows after the first (swap chains) 00152 SecondaryWindowList mSecondaryWindows; 00153 00154 bool mDeviceLost; 00155 bool mBasicStatesInitialised; 00156 00157 public: 00158 // constructor 00159 D3D9RenderSystem( HINSTANCE hInstance ); 00160 // destructor 00161 ~D3D9RenderSystem(); 00162 00163 virtual void initConfigOptions(void); 00164 00165 // Overridden RenderSystem functions 00166 ConfigOptionMap& getConfigOptions(void); 00167 String validateConfigOptions(void); 00168 RenderWindow* initialise( bool autoCreateWindow, const String& windowTitle = "OGRE Render Window" ); 00170 RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 00171 bool fullScreen, const NameValuePairList *miscParams = 0); 00172 00174 RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height, 00175 TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8, 00176 const NameValuePairList *miscParams = 0 ); 00177 00178 String getErrorDescription( long errorNumber ) const; 00179 const String& getName(void) const; 00180 // Low-level overridden members 00181 void setConfigOption( const String &name, const String &value ); 00182 void reinitialise(); 00183 void shutdown(); 00184 void setAmbientLight( float r, float g, float b ); 00185 void setShadingType( ShadeOptions so ); 00186 void setLightingEnabled( bool enabled ); 00187 void destroyRenderTarget(const String& name); 00188 void convertColourValue( const ColourValue& colour, uint32* pDest ); 00189 void setStencilCheckEnabled(bool enabled); 00190 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00191 uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 00192 StencilOperation stencilFailOp = SOP_KEEP, 00193 StencilOperation depthFailOp = SOP_KEEP, 00194 StencilOperation passOp = SOP_KEEP, 00195 bool twoSidedOperation = false); 00196 void setNormaliseNormals(bool normalise); 00197 00198 // Low-level overridden members, mainly for internal use 00199 void _useLights(const LightList& lights, unsigned short limit); 00200 void _setWorldMatrix( const Matrix4 &m ); 00201 void _setViewMatrix( const Matrix4 &m ); 00202 void _setProjectionMatrix( const Matrix4 &m ); 00203 void _setSurfaceParams( const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular, const ColourValue &emissive, Real shininess, TrackVertexColourType tracking ); 00204 void _setTexture( size_t unit, bool enabled, const String &texname ); 00205 void _setTextureCoordSet( size_t unit, size_t index ); 00206 void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 00207 const Frustum* frustum = 0); 00208 void _setTextureBlendMode( size_t unit, const LayerBlendModeEx& bm ); 00209 void _setTextureAddressingMode( size_t unit, TextureUnitState::TextureAddressingMode tam ); 00210 void _setTextureMatrix( size_t unit, const Matrix4 &xform ); 00211 void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor ); 00212 void _setAlphaRejectSettings( CompareFunction func, unsigned char value ); 00213 void _setViewport( Viewport *vp ); 00214 void _beginFrame(void); 00215 void _endFrame(void); 00216 void _setCullingMode( CullingMode mode ); 00217 void _setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL ); 00218 void _setDepthBufferCheckEnabled( bool enabled = true ); 00219 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00220 void _setDepthBufferWriteEnabled(bool enabled = true); 00221 void _setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL ); 00222 void _setDepthBias(ushort bias); 00223 void _setFog( FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0 ); 00224 void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00225 Matrix4& dest, bool forGpuProgram = false); 00226 void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, Real nearPlane, 00227 Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00228 void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00229 Matrix4& dest, bool forGpuProgram = false); 00230 void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00231 bool forGpuProgram); 00232 void _setRasterisationMode(SceneDetailLevel level); 00233 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00234 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00235 void setVertexDeclaration(VertexDeclaration* decl); 00236 void setVertexBufferBinding(VertexBufferBinding* binding); 00237 void _render(const RenderOperation& op); 00238 void bindGpuProgram(GpuProgram* prg); 00239 void unbindGpuProgram(GpuProgramType gptype); 00240 void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params); 00244 void setClipPlanes(const PlaneList& clipPlanes); 00245 00246 void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600); 00247 void clearFrameBuffer(unsigned int buffers, 00248 const ColourValue& colour = ColourValue::Black, 00249 Real depth = 1.0f, unsigned short stencil = 0); 00250 void setClipPlane (ushort index, Real A, Real B, Real C, Real D); 00251 void enableClipPlane (ushort index, bool enable); 00252 HardwareOcclusionQuery* createHardwareOcclusionQuery(void); 00253 Real getHorizontalTexelOffset(void); 00254 Real getVerticalTexelOffset(void); 00255 Real getMinimumDepthInputValue(void); 00256 Real getMaximumDepthInputValue(void); 00257 00259 void restoreLostDevice(void); 00261 bool isDeviceLost(void); 00263 void _notifyDeviceLost(void); 00264 00265 00266 00267 }; 00268 } 00269 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:43 2006