MCPcopy Create free account
hub / github.com/Liniyous/ElaWidgetTools / initialize

Method initialize

ElaWidgetTools/DeveloperComponents/ElaDxgi.cpp:22–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22bool ElaDxgi::initialize(int dxID, int outputID)
23{
24 _pIsInitSuccess = false;
25 _pDxDeviceID = dxID;
26 _pOutputDeviceID = outputID;
27 releaseInterface();
28 ID3D11Device* d3dDevice = nullptr;
29 ID3D11DeviceContext* d3dContext = nullptr;
30 D3D_FEATURE_LEVEL feat = D3D_FEATURE_LEVEL_11_0;
31 HRESULT hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0,
32 D3D11_SDK_VERSION, &d3dDevice, &feat, &d3dContext);
33 if (FAILED(hr))
34 {
35 _pLastError = "Failed to D3D11CreateDevice ErrorCode = " + QString::number(uint(hr), 16);
36 qDebug() << _pLastError;
37 if (d3dDevice)
38 {
39 d3dDevice->Release();
40 }
41 if (d3dContext)
42 {
43 d3dContext->Release();
44 }
45 return false;
46 }
47
48 IDXGIFactory* dxgiFactory = nullptr;
49 CreateDXGIFactory(__uuidof(dxgiFactory), reinterpret_cast<void**>(&dxgiFactory));
50 IDXGIAdapter* dxgiAdapter = nullptr;
51 QVector<IDXGIAdapter*> dxgiAdapterVector;
52 for (uint i = 0; dxgiFactory->EnumAdapters(i, &dxgiAdapter) != DXGI_ERROR_NOT_FOUND; ++i)
53 {
54 dxgiAdapterVector.append(dxgiAdapter);
55 }
56 dxgiFactory->Release();
57 dxgiAdapter = nullptr;
58 _pDxDeviceList.clear();
59 for (int i = 0; i < dxgiAdapterVector.count(); i++)
60 {
61 IDXGIAdapter* adapt = dxgiAdapterVector.at(i);
62 DXGI_ADAPTER_DESC desc;
63 adapt->GetDesc(&desc);
64 _pDxDeviceList.append(QString::fromWCharArray(desc.Description));
65 }
66 if (dxID >= 0 && dxID < dxgiAdapterVector.count())
67 {
68 dxgiAdapter = dxgiAdapterVector.at(dxID);
69 }
70
71 if (!dxgiAdapter)
72 {
73 _pLastError = "Failed to found gpu";
74 qDebug() << _pLastError;
75 d3dDevice->Release();
76 d3dContext->Release();
77 for (auto adapter: dxgiAdapterVector)
78 {
79 adapter->Release();

Callers 3

ElaDxgiManagerMethod · 0.80
setDxDeviceIDMethod · 0.80
setOutputDeviceIDMethod · 0.80

Calls 1

countMethod · 0.80

Tested by

no test coverage detected