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 #ifndef __D3D9RENDERSYSTEM_H__
00002 #define __D3D9RENDERSYSTEM_H__
00003 
00004 // Precompiler options
00005 #include "OgreD3D9Prerequisites.h"
00006 #include "OgreString.h"
00007 
00008 #include "OgreRenderSystem.h"
00009 
00010 // Include D3D files
00011 #include "OgreNoMemoryMacros.h"
00012 #include <d3d9.h>
00013 #include <d3dx9.h>
00014 #include <dxerr9.h>
00015 #include "OgreMemoryMacros.h"
00016 
00017 namespace Ogre 
00018 {
00019     class D3D9DriverList;
00020     class D3D9Driver;
00021 
00022     struct HardwareVertexBuffer
00023     {
00024         LPDIRECT3DVERTEXBUFFER9 buffer;
00025         UINT count;
00026     };
00027 
00028     struct HardwareIndexBuffer
00029     {
00030         LPDIRECT3DINDEXBUFFER9 buffer;
00031         UINT count;
00032     };
00033 
00037     class D3D9RenderSystem : public RenderSystem
00038     {
00039     private:
00040         // Direct3D rendering device
00041         // Only created after top-level window created
00042         LPDIRECT3D9         mpD3D;
00043         LPDIRECT3DDEVICE9   mpD3DDevice;
00044         
00045         //full-screen multisampling, anti aliasing quality
00046         DWORD mMultiSampleQuality;
00047         //external window handle ;)
00048         HWND mExternalHandle;
00049 
00050         // List of D3D drivers installed (video cards)
00051         // Enumerates itself
00052         D3D9DriverList* mDriverList;
00053         // Currently active driver
00054         D3D9Driver* mActiveD3DDriver;
00055 
00056         D3DCAPS9 mCaps;
00057 
00058         BYTE* mpRenderBuffer;
00059         DWORD mRenderBufferSize;
00060 
00061         // Vertex buffers.  Currently for rendering we need to place all the data
00062         // that we receive into one of the following vertex buffers (one for each 
00063         // component type).
00064         HardwareVertexBuffer mpXYZBuffer;
00065         HardwareVertexBuffer mpNormalBuffer;
00066         HardwareVertexBuffer mpDiffuseBuffer;
00067         HardwareVertexBuffer mpSpecularBuffer;
00068         HardwareVertexBuffer mpTextures[OGRE_MAX_TEXTURE_LAYERS][4]; // max 8 textures with max 4 units per texture
00069         UINT mStreamsInUse;
00070         HardwareIndexBuffer mpIndicies;
00071 
00072         // With a quick bit of adding up, I cannot see our vertex shader declaration being larger then 26 items
00073 #define D3D_MAX_DECLSIZE 26
00074         D3DVERTEXELEMENT9 mCurrentDecl[D3D_MAX_DECLSIZE];
00075         
00076         LPDIRECT3DVERTEXDECLARATION9 mpCurrentVertexDecl;
00077 
00078         // Array of up to 8 lights, indexed as per API
00079         // Note that a null value indeicates a free slot
00080 #define MAX_LIGHTS 8
00081         Light* mLights[MAX_LIGHTS];
00082 
00083         HINSTANCE mhInstance;
00084 
00085         D3D9DriverList* getDirect3DDrivers(void);
00086         void refreshD3DSettings(void);
00087 
00088         inline bool compareDecls( D3DVERTEXELEMENT9* pDecl1, D3DVERTEXELEMENT9* pDecl2, int size );
00089 
00090         // Matrix conversion
00091         D3DXMATRIX makeD3DXMatrix( const Matrix4& mat );
00092         Matrix4 convertD3DXMatrix( const D3DXMATRIX& mat );
00093 
00094         void initConfigOptions(void);
00095         void initInputDevices(void);
00096         void processInputDevices(void);
00097         void setD3D9Light( int index, Light* light );
00098         
00099 #ifdef _DEBUG
00100         void DumpBuffer( BYTE* pBuffer, DWORD vertexFormat, unsigned int numVertices, unsigned int stride );
00101 #endif
00102 
00103         D3DCMPFUNC convertCompareFunction(CompareFunction func);
00104         D3DSTENCILOP convertStencilOp(StencilOperation op);
00105 
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     public:
00111         // method for resizing/repositing the render window
00112         virtual ResizeRepositionWindow(HWND wich);
00113         // method for setting external window hwnd
00114         void SetExternalWindowHandle(HWND externalHandle){mExternalHandle = externalHandle;};
00115         // method for setting fullscreen multisampling quality
00116         // must be used before window creation
00117         void setFullScreenMultiSamplingPasses(DWORD numPasses);
00118 
00119         D3D9RenderSystem( HINSTANCE hInstance );
00120         ~D3D9RenderSystem();
00121 
00122         // ------------------------------------------
00123         // Overridden RenderSystem functions
00124         // ------------------------------------------
00125         const String& getName(void) const;
00126         ConfigOptionMap& getConfigOptions(void);
00127         void setConfigOption( const String &name, const String &value );
00128         String validateConfigOptions(void);
00129         RenderWindow* initialise( bool autoCreateWindow );
00130         void reinitialise();
00131         void shutdown();
00132         void startRendering();
00133         void setAmbientLight( float r, float g, float b );
00134         void setShadingType( ShadeOptions so );
00135         void setTextureFiltering( TextureFilterOptions fo );
00136         void setLightingEnabled( bool enabled );
00137         RenderWindow* createRenderWindow(const String &name, int width, int height, int colourDepth,
00138             bool fullScreen, int left = 0, int top = 0, bool depthBuffer = true,
00139             RenderWindow* parentWindowHandle = 0);
00140         RenderTexture * createRenderTexture( const String & name, int width, int height );
00141         void destroyRenderWindow( RenderWindow* pWin );
00142         String getErrorDescription( long errorNumber );
00143         void convertColourValue( const ColourValue& colour, unsigned long* pDest );
00144         // ------------------------------------------
00145         // Low-level overridden members
00146         // ------------------------------------------
00147         void _addLight( Light* lt );
00148         void _removeLight( Light* lt );
00149         void _modifyLight( Light* lt );
00150         void _removeAllLights(void);
00151         void _pushRenderState(void);
00152         void _popRenderState(void);
00153         void _setWorldMatrix( const Matrix4 &m );
00154         void _setViewMatrix( const Matrix4 &m );
00155         void _setProjectionMatrix( const Matrix4 &m );
00156         void _setSurfaceParams( const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular,
00157             const ColourValue &emissive, Real shininess );
00158         unsigned short _getNumTextureUnits(void);
00159         void _setTexture( int unit, bool enabled, const String &texname );
00160         void _setTextureCoordSet( int stage, int index );
00161         void _setTextureCoordCalculation( int stage, TexCoordCalcMethod m );
00162         void _setTextureBlendMode( int stage, const LayerBlendModeEx& bm );
00163         void _setTextureAddressingMode( int stage, Material::TextureLayer::TextureAddressingMode tam );
00164         void _setTextureMatrix( int stage, const Matrix4 &xform );
00165         void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor );
00166         void _setAlphaRejectSettings( CompareFunction func, unsigned char value );
00167         void _setViewport( Viewport *vp );
00168         void _beginFrame(void);
00169         void _render( RenderOperation &op );
00170         void _endFrame(void);
00171         void _setCullingMode( CullingMode mode );
00172         void _setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
00173         void _setDepthBufferCheckEnabled( bool enabled = true );
00174         void _setDepthBufferWriteEnabled(bool enabled = true);
00175         void _setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
00176         void _setMultiSampleAntiAlias( BOOL set );
00180         void _setDepthBias(ushort bias);
00181         void _setFog( FogMode mode = FOG_NONE, ColourValue colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0 );
00182         void _makeProjectionMatrix(Real fovy, Real aspect, Real nearPlane, Real farPlane, Matrix4& dest);
00183         void _setRasterisationMode(SceneDetailLevel level);
00187         void setStencilCheckEnabled(bool enabled);
00191         bool hasHardwareStencil(void);
00195         ushort getStencilBufferBitDepth(void);
00199         void setStencilBufferFunction(CompareFunction func);
00203         void setStencilBufferReferenceValue(ulong refValue);
00207         void setStencilBufferMask(ulong mask);
00211         void setStencilBufferFailOperation(StencilOperation op);
00215         void setStencilBufferDepthFailOperation(StencilOperation op);
00219         void setStencilBufferPassOperation(StencilOperation op);
00220     };
00221 }
00222 #endif

Copyright © 2002 by The OGRE Team