Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

codingfarm

DXGI - 어댑터 열거 본문

computer graphics/DXGI

DXGI - 어댑터 열거

scarecrow1992 2021. 4. 29. 23:24

Enumerating Adapters

docs.microsoft.com/en-us/windows/win32/direct3ddxgi/d3d10-graphics-programming-guide-dxgi

 

Adapter

  • 정의 : 컴퓨터의 HW와 SW이 기능을 추상화 한것
  • machine에는 수많은 adapter가 존재
  • 일부는 HW로, 일부는 SW로 구현
    • HW : 비디오 카드...
    • SW : Direct3D reference rasterizer
  • 역할 : graphic application에 의해 사용되는 기능을 구현

단일 컴퓨터, 2개의 어댑터(비디오카드), 3개의 출력 모니터가 있는 시스템

 

 

현재 시스템에 있는 어댑터와 출력장치에 대해 출력하는 코드

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
#include<iostream>
#include<dxgi.h>
#include<vector>
#include<wrl.h>
#include<dxgi1_4.h>
#include<string>
 
#pragma comment(lib, "dxgi.lib")
 
#define ReleaseCom(x) { if(x){ x->Release(); x = 0; } }
 
using namespace std;
 
void LogOutputDisplayModes(IDXGIOutput* output, DXGI_FORMAT format)
{
    UINT count = 0;
    UINT flags = 0;
 
    // Call with nullptr to get list count.
    output->GetDisplayModeList(format, flags, &count, nullptr);
 
    std::vector<DXGI_MODE_DESC> modeList(count);
    output->GetDisplayModeList(format, flags, &count, &modeList[0]);
 
    for (auto& x : modeList)
    {
        UINT n = x.RefreshRate.Numerator;
        UINT d = x.RefreshRate.Denominator;
        wstring text =
            L"Width = " + to_wstring(x.Width) + L" " +
            L"Height = " + to_wstring(x.Height) + L" " +
            L"Refresh = " + to_wstring(n) + L"/" + to_wstring(d) +
            L"\n";
 
        //::OutputDebugString(text.c_str());
        wprintf(text.c_str());
    }
    wprintf(L"\n");
}
 
 
// 주어진 한 어댑터에 연관된 모든 출려을 열거
void LogAdapterOutputs(IDXGIAdapter* adapter) {
    UINT i = 0;
    IDXGIOutput* output = nullptr;
 
 
    DXGI_ADAPTER_DESC adapterDesc;
    adapter->GetDesc(&adapterDesc);
    std::wstring text = L"***Adapter: ";
    text += adapterDesc.Description;
    text += L"\n";
    wprintf(text.c_str());
 
 
    while (adapter->EnumOutputs(i, &output) != DXGI_ERROR_NOT_FOUND) {
        text.clear();
 
        DXGI_OUTPUT_DESC desc;
        output->GetDesc(&desc);
 
        text += L"***Output: ";
        text += desc.DeviceName;
        text += L"\n";
        //OutputDebugString(text.c_str());
        wprintf(text.c_str());
 
        LogOutputDisplayModes(output, DXGI_FORMAT_B8G8R8A8_UNORM);
 
        ReleaseCom(output);
        ++i;
    }
}
 
 
void LogAdapters(void) {
    Microsoft::WRL::ComPtr<IDXGIFactory4> mdxgiFactory;
    CreateDXGIFactory1(IID_PPV_ARGS(&mdxgiFactory));
 
    UINT i = 0;
    IDXGIAdapter* adapter = nullptr;
    std::vector<IDXGIAdapter*> adapterList;
    while (mdxgiFactory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND)
    {
        /*
        DXGI_ADAPTER_DESC desc;
        adapter->GetDesc(&desc);
 
        std::wstring text = L"***Adapter: ";
        text += desc.Description;
        text += L"\n";
 
        //OutputDebugString(text.c_str());
        wprintf(L"%s", text.c_str());
        */
        adapterList.push_back(adapter);
 
        ++i;
    }
 
    for (size_t i = 0; i < adapterList.size(); ++i)
    {
        LogAdapterOutputs(adapterList[i]);
        ReleaseCom(adapterList[i]);
    }
}
 
 
int main(void) {
    LogAdapters();
 
    return 0;
}
cs

 

디스플레이 설정창에 나오는 선택가능한 해상도들과 거의 일치하는 모습을 볼 수 있다.

'computer graphics > DXGI' 카테고리의 다른 글

DXGI - 개요  (0) 2021.04.29
Comments