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