00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KEOS_D3D9RENDERSYSTEM_H
00022 #define KEOS_D3D9RENDERSYSTEM_H
00023
00024 #include "KeosD3D9Prerequisites.h"
00025 #include "KeosRenderSystem.h"
00026 #include "KeosRenderWindow.h"
00027
00028 class CD3D9;
00029
00030 namespace Keos
00031 {
00032
00038 class CD3D9RenderSystem : public IRenderSystem
00039 {
00040 public :
00041
00044 CD3D9RenderSystem();
00045
00048 ~CD3D9RenderSystem();
00049
00052 const String& GetName(void) const;
00053
00056 virtual IRenderWindow* Initialise(bool bAutoCreateWindow, const String& strWindowTitle = "KEOS Render Window");
00057
00060 virtual IRenderWindow* CreateRenderWindow(const String &strName, uint nWidth, uint nHeight, uint nColourDepth, bool bFullScreen);
00061
00064 virtual void Reinitialise(void);
00065
00068 virtual void Shutdown(void);
00069
00072 virtual void BeginScene(void) const;
00073
00076 virtual void EndScene(void) const;
00077
00080 virtual void PrintInfo(void) const;
00081
00084 virtual IBufferBase* _CreateVB(ulong nSize, ulong nStride, ulong nFlags) const;
00085
00088 virtual IBufferBase* _CreateIB(ulong nSize, ulong nStride, ulong nFlags) const;
00089
00092 virtual IDeclaration* CreateDeclaration(const TDeclarationElement* pElements, size_t nCount) const;
00093
00096 virtual void _SetVB(uint nStream, const IBufferBase* pBuffer, ulong nStride, ulong nMinVertex, ulong nMaxVertex);
00097
00100 virtual void _SetIB(const IBufferBase* pBuffer, ulong nStride);
00101
00104 virtual void SetDeclaration(const IDeclaration* pDeclaration);
00105
00108 virtual void DrawPrimitives(TPrimitiveType Type, ulong nFirstVertex, ulong nCount) const;
00109
00112 virtual void DrawIndexedPrimitives(TPrimitiveType Type, ulong nFirstIndex, ulong nCount) const;
00113
00116 virtual void PushMatrix(TMatrixType Type);
00117
00120 virtual void PopMatrix(TMatrixType Type);
00121
00124 virtual void LoadMatrix(TMatrixType Type, const CMatrix4& Matrix);
00125
00128 virtual void LoadMatrixMult(TMatrixType Type, const CMatrix4& Matrix);
00129
00132 virtual void GetMatrix(TMatrixType Type, CMatrix4& Matrix) const;
00133
00136 virtual ulong ConvertColor(const CColor& Color) const;
00137
00140 virtual ITextureBase* CreateTexture(const TVector2I& Size, TPixelFormat Format, ulong nFlags = 0) const;
00141
00144 virtual void SetTexture(uint nUnit, const ITextureBase* pTexture) const;
00145
00148 virtual void SetupAlphaBlending(TBlend Src, TBlend Dest) const;
00149
00152 virtual void SetupTextureUnit(uint nUnit, TTextureOp Op, TTextureArg Arg1, TTextureArg Arg2 = TXA_DIFFUSE, const CColor& Constant = 0x00) const;
00153
00156 virtual void Enable(TRenderParameter Param, bool bValue) const;
00157
00160 virtual IShaderBase* CreateShader(CGprogram Program, TShaderType Type) const;
00161
00164 virtual void SetVertexShader(const IShaderBase* pShader);
00165
00168 virtual void SetPixelShader(const IShaderBase* pShader);
00169
00172 virtual void SetClearColor(const CColor& Color);
00173
00176 virtual void SetLight(uint nIndex, CLight* pLight);
00177
00180 virtual void SetFillMode(TFillMode Mode);
00181
00184 void RestoreLostDevice(void);
00185
00188 bool IsDeviceLost(void);
00189
00192 void _NotifyDeviceLost(void);
00193
00194
00195 private:
00196
00199 void InitCapabilities(void);
00200
00203 void SearchVertexShaderCaps(D3DCAPS9& Caps);
00204
00207 void SearchPixelShaderCaps(D3DCAPS9& Caps);
00208
00211 bool CheckFormat(D3DFORMAT Format, D3DRESOURCETYPE ResourceType, ulong nUsage = 0);
00212
00214 CD3D9* m_pD3D9;
00215
00217 ulong m_nMinVertex;
00218
00220 ulong m_nVertexCount;
00221
00223 std::vector<CMatrix4> m_Matrices[6];
00224
00226 bool m_bDeviceLost;
00227 };
00228
00231 class CD3D9
00232 {
00233 public:
00234
00236 LPDIRECT3D9 pD3D;
00238 LPDIRECT3DDEVICE9 pD3DDevice;
00239
00242 CD3D9()
00243 {
00244 pD3D = NULL;
00245 pD3DDevice = NULL;
00246 }
00247
00250 ~CD3D9()
00251 {
00252 if (pD3D) pD3D->Release();
00253 if (pD3DDevice) pD3DDevice->Release();
00254 }
00255
00258 void ReleaseDevice(void)
00259 {
00260 if (pD3DDevice) pD3DDevice->Release();
00261 pD3DDevice = NULL;
00262 }
00263 };
00264
00265 }
00266
00267
00268 #endif // KEOS_D3D9RENDERSYSTEM_H