2 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
21 #ifndef RENDER_SYSTEM_DX_H
22 #define RENDER_SYSTEM_DX_H
29 #include "rendering/RenderSystem.h"
30 #include "threads/CriticalSection.h"
41 class CRenderSystemDX : public CRenderSystemBase
45 virtual ~CRenderSystemDX();
48 virtual bool InitRenderSystem();
49 virtual bool DestroyRenderSystem();
50 virtual bool ResetRenderSystem(int width, int height, bool fullScreen, float refreshRate);
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);
60 virtual void SetVSync(bool vsync);
62 virtual void SetViewPort(CRect& viewPort);
63 virtual void GetViewPort(CRect& viewPort);
64 virtual void RestoreViewPort();
66 virtual void SetScissors(const CRect &rect);
67 virtual void ResetScissors();
69 virtual void CaptureStateBlock();
70 virtual void ApplyStateBlock();
72 virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight);
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();
80 virtual void Project(float &x, float &y, float &z);
84 LPDIRECT3DDEVICE9 Get3DDevice() { return m_pD3DDevice; }
85 int GetBackbufferCount() const { return m_D3DPP.BackBufferCount; }
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; }
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
102 void Register(ID3DResource *resource);
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
109 void Unregister(ID3DResource *resource);
111 static std::string GetErrorDescription(HRESULT hr);
117 void OnDeviceReset();
118 bool PresentRenderImpl(const CDirtyRegionList &dirty);
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);
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;
137 D3DDEVTYPE m_devType;
138 D3DPRESENT_PARAMETERS m_D3DPP;
139 D3DDISPLAYMODEEX m_D3DDMEX;
142 unsigned int m_nBackBufferWidth;
143 unsigned int m_nBackBufferHeight;
144 bool m_bFullScreenDevice;
147 HRESULT m_nDeviceStatus;
148 IDirect3DStateBlock9* m_stateBlock;
149 int64_t m_systemFreq;
151 DWORD m_defaultD3DUsage;
152 D3DPOOL m_defaultD3DPool;
153 bool m_useWindowedDX;
154 D3DADAPTER_IDENTIFIER9 m_AIdentifier;
156 CCriticalSection m_resourceSection;
157 std::vector<ID3DResource*> m_resources;
159 bool m_inScene; ///< True if we're in a BeginScene()/EndScene() block
161 D3DVIEWPORT9 m_viewPort;
162 D3DXMATRIX m_projection;
169 #endif // RENDER_SYSTEM_DX