Merge pull request #4314 from MartijnKaijser/beta1
[vuplus_xbmc] / xbmc / rendering / dx / RenderSystemDX.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #ifndef RENDER_SYSTEM_DX_H
22 #define RENDER_SYSTEM_DX_H
23
24 #ifdef HAS_DX
25
26 #pragma once
27
28 #include <vector>
29 #include "rendering/RenderSystem.h"
30 #include "threads/CriticalSection.h"
31
32 enum PCI_Vendors
33 {
34   PCIV_ATI    = 0x1002,
35   PCIV_nVidia = 0x10DE,
36   PCIV_Intel  = 0x8086
37 };
38
39 class ID3DResource;
40
41 class CRenderSystemDX : public CRenderSystemBase
42 {
43 public:
44   CRenderSystemDX();
45   virtual ~CRenderSystemDX();
46
47   // CRenderBase
48   virtual bool InitRenderSystem();
49   virtual bool DestroyRenderSystem();
50   virtual bool ResetRenderSystem(int width, int height, bool fullScreen, float refreshRate);
51
52   virtual bool BeginRender();
53   virtual bool EndRender();
54   virtual bool PresentRender(const CDirtyRegionList &dirty);
55   virtual bool ClearBuffers(color_t color);
56   virtual bool IsExtSupported(const char* extension);
57   virtual bool IsSurfaceFormatOk(D3DFORMAT surfFormat, DWORD usage);
58   virtual bool IsTextureFormatOk(D3DFORMAT texFormat, DWORD usage);
59
60   virtual void SetVSync(bool vsync);
61
62   virtual void SetViewPort(CRect& viewPort);
63   virtual void GetViewPort(CRect& viewPort);
64   virtual void RestoreViewPort();
65
66   virtual void SetScissors(const CRect &rect);
67   virtual void ResetScissors();
68
69   virtual void CaptureStateBlock();
70   virtual void ApplyStateBlock();
71
72   virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight);
73
74   virtual void ApplyHardwareTransform(const TransformMatrix &matrix);
75   virtual void RestoreHardwareTransform();
76   virtual void SetStereoMode(RENDER_STEREO_MODE mode, RENDER_STEREO_VIEW view);
77   virtual bool SupportsStereo(RENDER_STEREO_MODE mode) const;
78   virtual bool TestRender();
79
80   virtual void Project(float &x, float &y, float &z);
81
82   void FlushGPU();
83
84   LPDIRECT3DDEVICE9 Get3DDevice() { return m_pD3DDevice; }
85   int GetBackbufferCount() const { return m_D3DPP.BackBufferCount; }
86
87   bool    UseD3D9Ex()       { return m_useD3D9Ex; }
88   DWORD   DefaultD3DUsage() { return m_defaultD3DUsage; }
89   D3DPOOL DefaultD3DPool()  { return m_defaultD3DPool; }
90   D3DADAPTER_IDENTIFIER9 GetAIdentifier() { return m_AIdentifier; }
91   bool    Interlaced()      { return m_interlaced; }
92
93   /*!
94    \brief Register as a dependent of the DirectX Render System
95    Resources should call this on construction if they're dependent on the Render System
96    for survival. Any resources that registers will get callbacks on loss and reset of
97    device, where resources that are in the D3DPOOL_DEFAULT pool should be handled.
98    In addition, callbacks for destruction and creation of the device are also called,
99    where any resources dependent on the DirectX device should be destroyed and recreated.
100    \sa Unregister, ID3DResource
101   */
102   void Register(ID3DResource *resource);
103
104   /*!
105    \brief Unregister as a dependent of the DirectX Render System
106    Resources should call this on destruction if they're a dependent on the Render System
107    \sa Register, ID3DResource
108   */
109   void Unregister(ID3DResource *resource);
110
111   static std::string GetErrorDescription(HRESULT hr);
112
113 protected:
114   bool CreateDevice();
115   void DeleteDevice();
116   void OnDeviceLost();
117   void OnDeviceReset();
118   bool PresentRenderImpl(const CDirtyRegionList &dirty);
119
120   void SetFocusWnd(HWND wnd) { m_hFocusWnd = wnd; }
121   void SetDeviceWnd(HWND wnd) { m_hDeviceWnd = wnd; }
122   void SetMonitor(HMONITOR monitor);
123   void SetRenderParams(unsigned int width, unsigned int height, bool fullScreen, float refreshRate);
124   void BuildPresentParameters();
125   virtual void UpdateMonitor() {};
126   BOOL IsDepthFormatOk(D3DFORMAT DepthFormat, D3DFORMAT RenderTargetFormat);
127   void OnMove();
128
129   LPDIRECT3D9                 m_pD3D;
130
131   // our adapter could change as we go
132   bool                        m_needNewDevice;
133   unsigned int                m_adapter;
134   LPDIRECT3DDEVICE9           m_pD3DDevice;
135   unsigned int                m_screenHeight;
136
137   D3DDEVTYPE                  m_devType;
138   D3DPRESENT_PARAMETERS       m_D3DPP;
139   D3DDISPLAYMODEEX            m_D3DDMEX;
140   HWND                        m_hFocusWnd;
141   HWND                        m_hDeviceWnd;
142   unsigned int                m_nBackBufferWidth;
143   unsigned int                m_nBackBufferHeight;
144   bool                        m_bFullScreenDevice;
145   float                       m_refreshRate;
146   bool                        m_interlaced;
147   HRESULT                     m_nDeviceStatus;
148   IDirect3DStateBlock9*       m_stateBlock;
149   int64_t                     m_systemFreq;
150   bool                        m_useD3D9Ex;
151   DWORD                       m_defaultD3DUsage;
152   D3DPOOL                     m_defaultD3DPool;
153   bool                        m_useWindowedDX;
154   D3DADAPTER_IDENTIFIER9      m_AIdentifier;
155
156   CCriticalSection            m_resourceSection;
157   std::vector<ID3DResource*>  m_resources;
158
159   bool                        m_inScene; ///< True if we're in a BeginScene()/EndScene() block
160
161   D3DVIEWPORT9                m_viewPort;
162   D3DXMATRIX                  m_projection;
163   D3DXMATRIX                  m_view;
164   D3DXMATRIX                  m_world;
165 };
166
167 #endif
168
169 #endif // RENDER_SYSTEM_DX