Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# KeosD3D9RenderSystem.h

Go to the documentation of this file.

    00001 /*
    00002  * This source file is part of KEOS (Free 3D Engine)
    00003  * For the latest info, see http://www.keosengine.org/
    00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
    00005  *
    00006  * This program is free software; you can redistribute it and/or modify it under
    00007  * the terms of the GNU Lesser General Public License as published by the Free Software
    00008  * Foundation; either version 2 of the License, or (at your option) any later
    00009  * version.
    00010  *
    00011  * This program is distributed in the hope that it will be useful, but WITHOUT
    00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Lesser General Public License along with
    00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00018  * http://www.gnu.org/copyleft/lesser.txt.
    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     //-----------------------------------------------------------------------
    00036     class CD3D9RenderSystem : public IRenderSystem
    00037     {
    00038     public :
    00039
    00042         CD3D9RenderSystem();
    00043
    00046         ~CD3D9RenderSystem();
    00047
    00050         const String& GetName(void) const;
    00051
    00054         virtual IRenderWindow* Initialise(bool bAutoCreateWindow, const String& strWindowTitle = "KEOS Render Window");
    00055
    00058         virtual IRenderWindow* CreateRenderWindow(const String &strName, uint nWidth, uint nHeight, uint nColourDepth, bool bFullScreen);
    00059
    00062         virtual void Reinitialise(void);
    00063
    00066         virtual void Shutdown(void);
    00067
    00070         virtual void BeginScene(void) const;
    00071
    00074         virtual void EndScene(void) const;
    00075
    00078         virtual void PrintInfo(void) const;
    00079
    00082         virtual IBufferBase* _CreateVB(ulong nSize, ulong nStride, ulong nFlags) const;
    00083
    00086         virtual IBufferBase* _CreateIB(ulong nSize, ulong nStride, ulong nFlags) const;
    00087
    00090         virtual IDeclaration* CreateDeclaration(const TDeclarationElement* pElements, size_t nCount) const;
    00091
    00094         virtual void _SetVB(uint nStream, const IBufferBase* pBuffer, ulong nStride, ulong nMinVertex, ulong nMaxVertex);
    00095
    00098         virtual void _SetIB(const IBufferBase* pBuffer, ulong nStride);
    00099
    00102         virtual void SetDeclaration(const IDeclaration* pDeclaration);
    00103
    00106         virtual void DrawPrimitives(TPrimitiveType Type, ulong nFirstVertex, ulong nCount) const;
    00107
    00110         virtual void DrawIndexedPrimitives(TPrimitiveType Type, ulong nFirstIndex, ulong nCount) const;
    00111
    00114         virtual void PushMatrix(TMatrixType Type);
    00115
    00118         virtual void PopMatrix(TMatrixType Type);
    00119
    00122         virtual void LoadMatrix(TMatrixType Type, const CMatrix4& Matrix);
    00123
    00126         virtual void LoadMatrixMult(TMatrixType Type, const CMatrix4& Matrix);
    00127
    00130         virtual void GetMatrix(TMatrixType Type, CMatrix4& Matrix) const;
    00131
    00134         virtual ulong ConvertColor(const CColor& Color) const;
    00135
    00138         virtual ITextureBase* CreateTexture(const TVector2I& Size, TPixelFormat Format, ulong nFlags = 0) const;
    00139
    00142         virtual void SetTexture(uint nUnit, const ITextureBase* pTexture) const;
    00143
    00146         virtual void SetupAlphaBlending(TBlend Src, TBlend Dest) const;
    00147
    00150         virtual void SetupTextureUnit(uint nUnit, TTextureOp Op, TTextureArg Arg1, TTextureArg Arg2 = TXA_DIFFUSE, const CColor& Constant = 0x00) const;
    00151
    00154         virtual void Enable(TRenderParameter Param, bool bValue) const;
    00155
    00158         virtual IShaderBase* CreateShader(CGprogram Program, TShaderType Type) const;
    00159
    00162         virtual void SetVertexShader(const IShaderBase* pShader);
    00163
    00166         virtual void SetPixelShader(const IShaderBase* pShader);
    00167
    00170                 virtual void SetClearColor(const CColor& Color);
    00171
    00174                 void RestoreLostDevice(void);
    00175
    00178                 bool IsDeviceLost(void);
    00179
    00182                 void _NotifyDeviceLost(void);
    00183
    00184     private:
    00185
    00188         void InitCapabilities(void);
    00189
    00192         void SearchVertexShaderCaps(D3DCAPS9& Caps);
    00193
    00196         void SearchPixelShaderCaps(D3DCAPS9& Caps);
    00197
    00200         bool CheckFormat(D3DFORMAT Format, D3DRESOURCETYPE ResourceType, ulong nUsage = 0);
    00201
    00203         CD3D9* m_pD3D9;
    00204
    00206         ulong m_nMinVertex;
    00207
    00209                 ulong m_nVertexCount;
    00210
    00212                 std::vector<CMatrix4> m_Matrices[6];
    00213
    00215                 bool m_bDeviceLost;
    00216     };
    00217
    00220         class CD3D9
    00221         {
    00222         public:
    00223
    00225                 LPDIRECT3D9                     pD3D;
    00227                 LPDIRECT3DDEVICE9       pD3DDevice;
    00228
    00231                 CD3D9()
    00232                 {
    00233                         pD3D = NULL;
    00234                         pD3DDevice = NULL;
    00235                 }
    00236
    00239                 ~CD3D9()
    00240                 {
    00241                         if (pD3D) pD3D->Release();
    00242                         if (pD3DDevice) pD3DDevice->Release();
    00243                 }
    00244
    00247                 void ReleaseDevice(void)
    00248                 {
    00249                         if (pD3DDevice) pD3DDevice->Release();
    00250                         pD3DDevice = NULL;
    00251                 }
    00252         };
    00253
    00254 } // namespace Keos
    00255
    00256
    00257 #endif // KEOS_D3D9RENDERSYSTEM_H