Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreD3D9RenderSystem.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://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 __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         bool mVSync;
00063         D3DMULTISAMPLE_TYPE mFSAAType;
00065         DWORD mFSAAQuality;
00066 
00068         HWND mExternalHandle;
00070         HINSTANCE mhInstance;
00071 
00073         D3D9DriverList* mDriverList;
00075         D3D9Driver* mActiveD3DDriver;
00077         D3DCAPS9 mCaps;
00078 
00080         struct sD3DTextureStageDesc
00081         {
00083             D3D9Mappings::eD3DTexType texType;
00085             size_t coordIndex;
00087             TexCoordCalcMethod autoTexCoordType;
00089             IDirect3DBaseTexture9 *pTex;
00090         } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS];
00091 
00092         // Array of up to 8 lights, indexed as per API
00093         // Note that a null value indeicates a free slot
00094         Light* mLights[MAX_LIGHTS];
00095 
00096         D3D9DriverList* getDirect3DDrivers(void);
00097         void refreshD3DSettings(void);
00098 
00099         inline bool compareDecls( D3DVERTEXELEMENT9* pDecl1, D3DVERTEXELEMENT9* pDecl2, size_t size );
00100 
00101 
00102         void initInputDevices(void);
00103         void processInputDevices(void);
00104         void setD3D9Light( size_t index, Light* light );
00105         
00106         // state management methods, very primitive !!!
00107         HRESULT __SetRenderState(D3DRENDERSTATETYPE state, DWORD value);
00108         HRESULT __SetSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value);
00109         HRESULT __SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
00110 
00112         DWORD _getCurrentAnisotropy(size_t unit);
00114         bool _checkMultiSampleQuality(D3DMULTISAMPLE_TYPE type, DWORD *outQuality, D3DFORMAT format, UINT adapterNum, D3DDEVTYPE deviceType, BOOL fullScreen);
00116         void _setFSAA(D3DMULTISAMPLE_TYPE type, DWORD qualityLevel);
00117         
00118         D3D9HardwareBufferManager* mHardwareBufferManager;
00119         D3D9GpuProgramManager* mGpuProgramManager;
00120         D3D9HLSLProgramFactory* mHLSLProgramFactory;
00121 
00122         size_t mLastVertexSourceCount;
00123 
00125         bool mForcedNormalisation;
00126 
00128         void initCapabilities(void);
00129 
00130         void convertVertexShaderCaps(void);
00131         void convertPixelShaderCaps(void);
00132 
00133         unsigned short mCurrentLights;
00134 
00135 
00136     public:
00137         // constructor
00138         D3D9RenderSystem( HINSTANCE hInstance );
00139         // destructor
00140         ~D3D9RenderSystem();
00141 
00142         virtual initConfigOptions(void);
00143         // method for resizing/repositing the render window
00144         virtual ResizeRepositionWindow(HWND wich);
00145         // method for setting external window hwnd
00146         void SetExternalWindowHandle(HWND externalHandle){mExternalHandle = externalHandle;};
00147 
00148         // Overridden RenderSystem functions
00149         ConfigOptionMap& getConfigOptions(void);
00150         String validateConfigOptions(void);
00151         RenderWindow* initialise( bool autoCreateWindow );
00152         RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, unsigned int colourDepth, bool fullScreen, int left = 0, int top = 0, bool depthBuffer = true, RenderWindow* parentWindowHandle = 0);
00153         RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height );
00154         String getErrorDescription( long errorNumber );
00155         const String& getName(void) const;
00156         // Low-level overridden members
00157         void setConfigOption( const String &name, const String &value );
00158         void reinitialise();
00159         void shutdown();
00160         void setAmbientLight( float r, float g, float b );
00161         void setShadingType( ShadeOptions so );
00162         void setLightingEnabled( bool enabled );
00163         void destroyRenderWindow( RenderWindow* pWin );
00164         void convertColourValue( const ColourValue& colour, unsigned long* pDest );
00165         void setStencilCheckEnabled(bool enabled);
00166         void setStencilBufferFunction(CompareFunction func);
00167         void setStencilBufferReferenceValue(ulong refValue);
00168         void setStencilBufferMask(ulong mask);
00169         void setStencilBufferFailOperation(StencilOperation op);
00170         void setStencilBufferDepthFailOperation(StencilOperation op);
00171         void setStencilBufferPassOperation(StencilOperation op);
00172         void setNormaliseNormals(bool normalise);
00173 
00174         // Low-level overridden members, mainly for internal use
00175         void _useLights(const LightList& lights, unsigned short limit);
00176         void _setWorldMatrix( const Matrix4 &m );
00177         void _setViewMatrix( const Matrix4 &m );
00178         void _setProjectionMatrix( const Matrix4 &m );
00179         void _setSurfaceParams( const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular, const ColourValue &emissive, Real shininess );
00180         void _setTexture( size_t unit, bool enabled, const String &texname );
00181         void _setTextureCoordSet( size_t unit, size_t index );
00182         void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m);
00183         void _setTextureBlendMode( size_t unit, const LayerBlendModeEx& bm );
00184         void _setTextureAddressingMode( size_t unit, TextureUnitState::TextureAddressingMode tam );
00185         void _setTextureMatrix( size_t unit, const Matrix4 &xform );
00186         void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor );
00187         void _setAlphaRejectSettings( CompareFunction func, unsigned char value );
00188         void _setViewport( Viewport *vp );
00189         void _beginFrame(void);
00190         void _endFrame(void);
00191         void _setCullingMode( CullingMode mode );
00192         void _setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
00193         void _setDepthBufferCheckEnabled( bool enabled = true );
00194         void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00195         void _setDepthBufferWriteEnabled(bool enabled = true);
00196         void _setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
00197         void _setDepthBias(ushort bias);
00198         void _setFog( FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0 );
00199         void _makeProjectionMatrix(Real fovy, Real aspect, Real nearPlane, Real farPlane, 
00200             Matrix4& dest, bool forGpuProgram = false);
00201         void _setRasterisationMode(SceneDetailLevel level);
00202         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00203         void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00204         void setVertexDeclaration(VertexDeclaration* decl);
00205         void setVertexBufferBinding(VertexBufferBinding* binding);
00206         void _render(const RenderOperation& op);
00207         void bindGpuProgram(GpuProgram* prg);
00208         void unbindGpuProgram(GpuProgramType gptype);
00209         void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params);
00210 
00211     };
00212 }
00213 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:08 2004