-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphicsengine.cpp
More file actions
73 lines (58 loc) · 1.71 KB
/
graphicsengine.cpp
File metadata and controls
73 lines (58 loc) · 1.71 KB
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
#include "graphicsengine.hpp"
#include "swapchain.hpp"
#include "devicecontext.hpp"
bool GraphicsEngine::init()
{
D3D_DRIVER_TYPE driver_types[] = {
D3D_DRIVER_TYPE_HARDWARE, // GPU
D3D_DRIVER_TYPE_WARP, // CPU
D3D_DRIVER_TYPE_REFERENCE
};
UINT num_driver_types = ARRAYSIZE(driver_types);
D3D_FEATURE_LEVEL feature_level[] = {
D3D_FEATURE_LEVEL_12_0,
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
HRESULT res;
ID3D11DeviceContext* imm_context;
for (UINT driver_type_index = 0; driver_type_index < num_driver_types; driver_type_index++)
{
res = D3D11CreateDevice(nullptr, driver_types[driver_type_index], nullptr, 0, feature_level, num_driver_types, D3D11_SDK_VERSION, &m_d3d_device, &m_d3d_feature_level, &imm_context);
if (SUCCEEDED(res))
break;
}
m_imm_device_context = new DeviceContext(imm_context);
if (FAILED(res))
return false;
m_d3d_device->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&m_dxgi_device));
m_dxgi_device->GetParent(__uuidof(IDXGIAdapter), reinterpret_cast<void**>(&m_dxgi_adapter));
m_dxgi_adapter->GetParent(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&m_dxgi_factory));
return true;
}
bool GraphicsEngine::release()
{
m_dxgi_device->Release();
m_dxgi_adapter->Release();
m_dxgi_factory->Release();
m_imm_device_context->release();
m_d3d_device->Release();
return true;
}
GraphicsEngine* GraphicsEngine::get()
{
static GraphicsEngine engine;
return &engine;
}
SwapChain* GraphicsEngine::createSwapChain()
{
return new SwapChain;
}
DeviceContext* GraphicsEngine::getImmediateDeviceContext()
{
return this->m_imm_device_context;
}