/
RenderSystemDX.h
176 lines (159 loc) · 6.71 KB
/
RenderSystemDX.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#ifndef RENDER_SYSTEM_DX_H
#define RENDER_SYSTEM_DX_H
#ifdef HAS_DX
#pragma once
#include <vector>
#include "rendering/RenderSystem.h"
#include "guilib/GUIShaderDX.h"
#include "threads/CriticalSection.h"
enum PCI_Vendors
{
PCIV_ATI = 0x1002,
PCIV_nVidia = 0x10DE,
PCIV_Intel = 0x8086
};
class ID3DResource;
class CRenderSystemDX : public CRenderSystemBase
{
public:
CRenderSystemDX();
virtual ~CRenderSystemDX();
// CRenderBase
virtual bool InitRenderSystem();
virtual bool DestroyRenderSystem();
virtual bool ResetRenderSystem(int width, int height, bool fullScreen, float refreshRate);
virtual bool BeginRender();
virtual bool EndRender();
virtual bool ClearBuffers(color_t color);
virtual bool IsExtSupported(const char* extension);
virtual bool IsFormatSupport(DXGI_FORMAT format, unsigned int usage);
virtual void SetVSync(bool vsync);
virtual void SetViewPort(CRect& viewPort);
virtual void GetViewPort(CRect& viewPort);
virtual void RestoreViewPort();
virtual CRect ClipRectToScissorRect(const CRect &rect);
virtual bool ScissorsCanEffectClipping();
virtual void SetScissors(const CRect &rect);
virtual void ResetScissors();
virtual void CaptureStateBlock();
virtual void ApplyStateBlock();
virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor = 0.f);
virtual void ApplyHardwareTransform(const TransformMatrix &matrix);
virtual void RestoreHardwareTransform();
virtual void SetStereoMode(RENDER_STEREO_MODE mode, RENDER_STEREO_VIEW view);
virtual bool SupportsStereo(RENDER_STEREO_MODE mode) const;
virtual bool TestRender();
virtual void Project(float &x, float &y, float &z);
IDXGIOutput* GetCurrentOutput(void) { return m_pOutput; }
void GetDisplayMode(DXGI_MODE_DESC *mode, bool useCached = false);
void FinishCommandList(bool bExecute = true);
void FlushGPU();
ID3D11Device* Get3D11Device() { return m_pD3DDev; }
ID3D11DeviceContext* Get3D11Context() { return m_pContext; }
ID3D11DeviceContext* GetImmediateContext(){ return m_pImdContext; }
CGUIShaderDX* GetGUIShader() { return m_pGUIShader; }
unsigned GetFeatureLevel() { return m_featureLevel; }
D3D11_USAGE DefaultD3DUsage() { return m_defaultD3DUsage; }
DXGI_ADAPTER_DESC GetAIdentifier() { return m_adapterDesc; }
bool Interlaced() { return m_interlaced; }
int GetBackbufferCount() const { return 2; }
void SetAlphaBlendEnable(bool enable);
static std::string GetErrorDescription(HRESULT hr);
protected:
bool CreateDevice();
void DeleteDevice();
void OnDeviceLost();
void OnDeviceReset();
bool PresentRenderImpl(const CDirtyRegionList &dirty);
void SetFocusWnd(HWND wnd) { m_hFocusWnd = wnd; }
void SetDeviceWnd(HWND wnd) { m_hDeviceWnd = wnd; }
void SetMonitor(HMONITOR monitor);
void SetRenderParams(unsigned int width, unsigned int height, bool fullScreen, float refreshRate);
bool CreateWindowSizeDependentResources();
bool CreateStates();
bool InitGUIShader();
void OnMove();
void OnResize(unsigned int width, unsigned int height);
void SetFullScreenInternal();
void GetClosestDisplayModeToCurrent(IDXGIOutput* output, DXGI_MODE_DESC* outCurrentDisplayMode, bool useCached = false);
void CheckInterlasedStereoView(void);
void Register(ID3DResource *resource);
void Unregister(ID3DResource *resource);
virtual void ResolutionChanged() {};
virtual void UpdateMonitor() {};
// our adapter could change as we go
bool m_needNewDevice;
bool m_needNewViews;
bool m_resizeInProgress;
unsigned int m_screenHeight;
HWND m_hFocusWnd;
HWND m_hDeviceWnd;
unsigned int m_nBackBufferWidth;
unsigned int m_nBackBufferHeight;
bool m_bFullScreenDevice;
float m_refreshRate;
bool m_interlaced;
HRESULT m_nDeviceStatus;
int64_t m_systemFreq;
D3D11_USAGE m_defaultD3DUsage;
bool m_useWindowedDX;
CCriticalSection m_resourceSection;
std::vector<ID3DResource*> m_resources;
bool m_inScene; ///< True if we're in a BeginScene()/EndScene() block
D3D_DRIVER_TYPE m_driverType;
D3D_FEATURE_LEVEL m_featureLevel;
IDXGIFactory1* m_dxgiFactory;
ID3D11Device* m_pD3DDev;
IDXGIAdapter1* m_adapter;
int m_adapterIndex;
IDXGIOutput* m_pOutput;
ID3D11DeviceContext* m_pContext;
ID3D11DeviceContext* m_pImdContext;
IDXGISwapChain* m_pSwapChain;
IDXGISwapChain1* m_pSwapChain1;
ID3D11RenderTargetView* m_pRenderTargetView;
ID3D11DepthStencilState* m_depthStencilState;
ID3D11DepthStencilView* m_depthStencilView;
D3D11_VIEWPORT m_viewPort;
CRect m_scissor;
CGUIShaderDX* m_pGUIShader;
ID3D11BlendState* m_BlendEnableState;
ID3D11BlendState* m_BlendDisableState;
bool m_BlendEnabled;
ID3D11RasterizerState* m_RSScissorDisable;
ID3D11RasterizerState* m_RSScissorEnable;
bool m_ScissorsEnabled;
DXGI_ADAPTER_DESC m_adapterDesc;
// stereo interlaced/checkerboard intermediate target
ID3D11Texture2D* m_pTextureRight;
ID3D11RenderTargetView* m_pRenderTargetViewRight;
ID3D11ShaderResourceView* m_pShaderResourceViewRight;
bool m_bResizeRequred;
bool m_bHWStereoEnabled;
// improve get current mode
DXGI_MODE_DESC m_cachedMode;
#ifdef _DEBUG
ID3D11Debug* m_d3dDebug = NULL;
#endif
};
#endif
#endif // RENDER_SYSTEM_DX