Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/xiaoyafang123/article/details/89498662
DirectX 10 and DirectX 11 graphics using the infrastructure available on the (DXGI) enumeration of computer graphics adapter. You usually need to enumerate adapter for the following reasons:
- How many graphics adapter installed on your computer to determine
- Help you choose which adapter to use to create the Direct3D device
- To retrieve an object that can be used to retrieve IDXGIAdapter device functions
Enumeration adapter
- Creating IDXGIFactory object by calling CreateDXGIFactory function. The following code example demonstrates how to initialize IDXGIFactory object.
IDXGIFactory * pFactory = NULL; CreateDXGIFactory(__uuidof(IDXGIFactory) ,(void**)&pFactory)
- Enumerate each adapter by calling IDXGIFactory :: enumadapter method. Adapter parameter allows you to specify zero-based index number to enumerate the adapter. If the specified index is not available at the adapter, the method returns DXGI_ERROR_NOT_FOUND. The following code example demonstrates how to enumerate the adapter on the computer.
The following code example demonstrates how to enumerate all the adapters on the computer.for (UINT i = 0; pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i) { ... }
std::vector <IDXGIAdapter*> EnumerateAdapters(void) { IDXGIAdapter * pAdapter; std::vector <IDXGIAdapter*> vAdapters; IDXGIFactory* pFactory = NULL; // Create a DXGIFactory object. if(FAILED(CreateDXGIFactory(__uuidof(IDXGIFactory) ,(void**)&pFactory))) { return vAdapters; } for ( UINT i = 0; pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i ) { vAdapters.push_back(pAdapter); } if(pFactory) { pFactory->Release(); } return vAdapters; }