forked from tomazos/QtDirectX11WidgetDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphicsInfrastructure.cpp
76 lines (65 loc) · 1.89 KB
/
GraphicsInfrastructure.cpp
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
// (C) 2011, Andrew Tomazos <andrew@tomazos.com>.
#include "GraphicsInfrastructure.h"
#include "Adapter.h"
#include "Device.h"
#include "SwapChain.h"
PGraphicsInfrastructure
GraphicsInfrastructure::create(Log* pLog)
{
bool bOk;
PGraphicsInfrastructure p(new GraphicsInfrastructure(bOk, pLog));
if (bOk)
return p;
else
return PGraphicsInfrastructure(0);
}
GraphicsInfrastructure::GraphicsInfrastructure(bool& bOk, Log* pLog)
: LogWriter(pLog)
, m_pFactory(0)
{
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**) &m_pFactory);
bOk = SUCCEEDED(hr);
if (!bOk)
INFO(WinUtils::stringify(hr));
}
GraphicsInfrastructure::~GraphicsInfrastructure()
{
if (m_pFactory)
m_pFactory->Release();
}
PAdapter
GraphicsInfrastructure::getDefaultAdapter()
{
IDXGIAdapter1* pAdapter(0);
HRESULT hr = m_pFactory->EnumAdapters1(0, &pAdapter);
if (FAILED(hr))
{
INFO(WinUtils::stringify(hr));
return PAdapter(0);
}
return PAdapter(new Adapter(m_pLog, pAdapter));
}
PSwapChain GraphicsInfrastructure::createSwapChain(PDevice pDevice, HWND hwnd)
{
DXGI_SWAP_CHAIN_DESC desc;
ZeroMemory( &desc, sizeof( desc ) );
desc.BufferDesc.Width = 0;
desc.BufferDesc.Height = 0;
desc.BufferDesc.RefreshRate.Numerator = 60;
desc.BufferDesc.RefreshRate.Denominator = 1;
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.BufferCount = 1;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = hwnd;
desc.SampleDesc.Count = 8;
desc.SampleDesc.Quality = 0;
desc.Windowed = TRUE;
IDXGISwapChain* pSwapChain(0);
HRESULT hr = m_pFactory->CreateSwapChain(pDevice->m_pDevice, &desc, &pSwapChain);
if (FAILED(hr))
{
INFO(WinUtils::stringify(hr));
return PSwapChain(0);
}
return PSwapChain(new SwapChain(m_pLog, pSwapChain));
}