本文整理汇总了C++中IDXGIOutput::GetDisplayModeList方法的典型用法代码示例。如果您正苦于以下问题:C++ IDXGIOutput::GetDisplayModeList方法的具体用法?C++ IDXGIOutput::GetDisplayModeList怎么用?C++ IDXGIOutput::GetDisplayModeList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDXGIOutput
的用法示例。
在下文中一共展示了IDXGIOutput::GetDisplayModeList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
CD3DRenderer::CD3DRenderer(HWND& window)
{
m_hWnd = window;
if(FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&m_pdxgiFactory)))
g_pDebug->printError("Failed to create DXGI Factory.");
IDXGIAdapter1 * pAdapter;
for (UINT i = 0;
m_pdxgiFactory->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND;
++i)
m_vAdapters.push_back(pAdapter);
IDXGIOutput *pOutput;
m_vAdapters[m_uiCurrentAdapter]->EnumOutputs(0, &pOutput);
UINT modeCount;
pOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &modeCount, nullptr);
DXGI_MODE_DESC *descArr = new DXGI_MODE_DESC[modeCount];
pOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &modeCount, descArr);
for (UINT i = 0; i < modeCount; i++)
{
if (descArr[i].RefreshRate.Numerator / descArr[i].RefreshRate.Denominator <= 60)
m_vAdapterModes.push_back(descArr[i]);
}
pOutput->Release();
delete[] descArr;
}
示例2: modes
void D3D11Renderer::EnumerateDisplayModes()
{
IDXGIFactory1 *factory = 0;
if (CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)&factory) == S_OK)
{
IDXGIAdapter1 *adapter = 0;
for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++)
{
DXGI_ADAPTER_DESC1 ad;
adapter->GetDesc1(&ad);
char description[128];
size_t n;
wcstombs_s(&n, description, ad.Description, 128);
ATOM_LOG("-------------------------------------------------------------------------------\n");
ATOM_LOG("[info]: adapter[%d]: %s\n", i, description);
ATOM_LOG("[info]: - revision: %d\n", i, ad.Revision);
ATOM_LOG("[info]: - video memory: %d\n", i, ad.DedicatedVideoMemory / 1024 / 1024);
ATOM_LOG("[info]: - system memory: %d\n", i, ad.DedicatedSystemMemory / 1024 / 1024);
ATOM_LOG("[info]: - shared system memory: %d\n", i, ad.SharedSystemMemory / 1024 / 1024);
IDXGIOutput *output = 0;
for (UINT j = 0; adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND; j++)
{
UINT modesCount;
DXGI_FORMAT format = g_settings.format;
output->GetDisplayModeList(format, 0, &modesCount, 0);
DXGI_MODE_DESC *modeDescs = new DXGI_MODE_DESC[modesCount];
output->GetDisplayModeList(format, 0, &modesCount, modeDescs);
ATOM_LOG("[info]: - output %d display modes(%d)\n", j, modesCount);
for (UINT k = 0; k < modesCount; k++)
{
ATOM_LOG("[info]: -- mode[%d]: %d * %d", k, modeDescs[k].Width, modeDescs[k].Height);
ATOM_LOG(", refresh rate: %d/%d\n", modeDescs[i].RefreshRate.Numerator, modeDescs[i].RefreshRate.Denominator);
}
delete[] modeDescs;
memory::SafeRelease(&output);
}
memory::SafeRelease(&adapter);
}
}
memory::SafeRelease(&factory);
}
示例3: video_mode
// 枚举显示模式
/////////////////////////////////////////////////////////////////////////////////
void D3D12Adapter::Enumerate()
{
std::vector<DXGI_FORMAT> formats;
formats.push_back(DXGI_FORMAT_R8G8B8A8_UNORM);
formats.push_back(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
formats.push_back(DXGI_FORMAT_B8G8R8A8_UNORM);
formats.push_back(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
formats.push_back(DXGI_FORMAT_R10G10B10A2_UNORM);
UINT i = 0;
IDXGIOutput* output = nullptr;
while (adapter_->EnumOutputs(i, &output) != DXGI_ERROR_NOT_FOUND)
{
if (output != nullptr)
{
for (auto const & format : formats)
{
UINT num = 0;
output->GetDisplayModeList(format, DXGI_ENUM_MODES_SCALING, &num, 0);
if (num > 0)
{
std::vector<DXGI_MODE_DESC> mode_descs(num);
output->GetDisplayModeList(format, DXGI_ENUM_MODES_SCALING, &num, &mode_descs[0]);
for (auto const & mode_desc : mode_descs)
{
D3D12VideoMode const video_mode(mode_desc.Width, mode_desc.Height,
mode_desc.Format);
// 如果找到一个新模式, 加入模式列表
if (std::find(modes_.begin(), modes_.end(), video_mode) == modes_.end())
{
modes_.push_back(video_mode);
}
}
}
}
output->Release();
output = nullptr;
}
++ i;
}
std::sort(modes_.begin(), modes_.end());
}
示例4:
DXGI_RATIONAL D3D11Renderer::GetDefaultRefreshRate()
{
DXGI_RATIONAL refreshRate = {59, 1};
IDXGIFactory1 *factory = 0;
if (CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)&factory) == S_OK)
{
IDXGIAdapter1 *adapter = 0;
for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++)
{
DXGI_ADAPTER_DESC1 ad;
IDXGIOutput *output = 0;
adapter->GetDesc1(&ad);
for (UINT j = 0; adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND; j++)
{
UINT modesCount;
DXGI_FORMAT format = g_settings.format;
output->GetDisplayModeList(format, 0, &modesCount, 0);
DXGI_MODE_DESC *modeDescs = new DXGI_MODE_DESC[modesCount];
output->GetDisplayModeList(format, 0, &modesCount, modeDescs);
for (UINT k = 0; k < modesCount; k++)
{
if (modeDescs[k].Width == (UINT)g_settings.width &&
modeDescs[k].Height == (UINT)g_settings.height)
{
refreshRate = modeDescs[i].RefreshRate;
delete[] modeDescs;
memory::SafeRelease(&output);
memory::SafeRelease(&adapter);
memory::SafeRelease(&factory);
return refreshRate;
}
}
delete[] modeDescs;
memory::SafeRelease(&output);
}
memory::SafeRelease(&adapter);
}
}
memory::SafeRelease(&factory);
return refreshRate;
}
示例5: CreateDXGIFactory
bool DX11::CreateDevice(HWND a_hwnd)
{
HRESULT result;
// Create a DirectX graphics interface factory.
IDXGIFactory* factory;
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**) &factory);
if (FAILED(result))
{
LOG_ERROR("Could not create DXGI Factory.");
return false;
}
// Use the factory to create an adapter for the primary graphics interface (video card).
IDXGIAdapter* adapter;
result = factory->EnumAdapters(0, &adapter);
if (FAILED(result))
{
LOG_ERROR("Could not create graphics adapter.");
return false;
}
// Enumerate the primary adapter output (monitor).
IDXGIOutput* adapterOutput;
result = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(result))
{
LOG_ERROR("Could not create graphics adapter output.");
return false;
}
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
unsigned int displaymodes;
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &displaymodes, NULL);
if (FAILED(result))
{
LOG_ERROR("Could not create display mode list.");
return false;
}
// Create a list to hold all the possible display modes for this monitor/video card combination.
DXGI_MODE_DESC* displayModeList = new DXGI_MODE_DESC[displaymodes];
if (!displayModeList)
{
LOG_ERROR("Could not fill display mode list.");
return false;
}
// Now fill the display mode list structures.
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &displaymodes, displayModeList);
if (FAILED(result))
{
LOG_ERROR("Could not fill display mode list structures.");
return false;
}
// Now go through all the display modes and find the one that matches the screen width and height.
// When a match is found store the numerator and denominator of the refresh rate for that monitor.
unsigned int numerator;
unsigned int denominator;
for (unsigned int i = 0; i < displaymodes; i++)
{
if (displayModeList[i].Width == (unsigned int) m_width)
{
if (displayModeList[i].Height == (unsigned int) m_height)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
// Get the adapter (video card) description
DXGI_ADAPTER_DESC adapterDesc;
result = adapter->GetDesc(&adapterDesc);
if (FAILED(result))
{
LOG_ERROR("Could not get graphics device description.");
return false;
}
// Store the dedicated video card memory in megabytes.
m_vmemory = (int) (adapterDesc.DedicatedVideoMemory / 1024 / 1024);
// Convert the name of the video card to a character array and store it.
unsigned int stringLength;
int error = wcstombs_s(&stringLength, m_cardDesc, 128, adapterDesc.Description, 128);
if (error != 0)
{
LOG_ERROR("Could not get graphics device name.");
return false;
}
// Release the display mode list.
delete [] displayModeList;
displayModeList = 0;
// Release resources.
RELEASE(adapterOutput);
RELEASE(adapter);
//.........这里部分代码省略.........
示例6: EnableDrawing
void EnableDrawing (HGLRC *hRC) {
WindowResizedCallback = &WindowResized;
d3dmgr = new ContextManager();
int screenWidth = window_get_width(),
screenHeight = window_get_height();
screenWidth = screenWidth <= 0 ? 1 : screenWidth;
screenHeight = screenHeight <= 0 ? 1 : screenHeight;
bool vsync = false;
HWND hwnd = enigma::hWnd;
bool fullscreen = false;
HRESULT result;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, i, numerator, denominator, stringLength;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
int error;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
D3D_FEATURE_LEVEL featureLevel;
ID3D11Texture2D* backBufferPtr;
D3D11_TEXTURE2D_DESC depthBufferDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D11_RASTERIZER_DESC rasterDesc;
D3D11_VIEWPORT viewport;
float fieldOfView, screenAspect;
// Store the vsync setting.
m_vsync_enabled = vsync;
// Create a DirectX graphics interface factory.
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if(FAILED(result))
{
//return false;
}
// Use the factory to create an adapter for the primary graphics interface (video card).
result = factory->EnumAdapters(0, &adapter);
if(FAILED(result))
{
//return false;
}
// Enumerate the primary adapter output (monitor).
result = adapter->EnumOutputs(0, &adapterOutput);
if(FAILED(result))
{
//return false;
}
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if(FAILED(result))
{
//return false;
}
// Create a list to hold all the possible display modes for this monitor/video card combination.
displayModeList = new DXGI_MODE_DESC[numModes];
if(!displayModeList)
{
//return false;
}
// Now fill the display mode list structures.
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if(FAILED(result))
{
//return false;
}
// Now go through all the display modes and find the one that matches the screen width and height.
// When a match is found store the numerator and denominator of the refresh rate for that monitor.
for(i=0; i<numModes; i++)
{
if(displayModeList[i].Width == (unsigned int)screenWidth)
{
if(displayModeList[i].Height == (unsigned int)screenHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
// Get the adapter (video card) description.
result = adapter->GetDesc(&adapterDesc);
if(FAILED(result))
{
//return false;
}
// Store the dedicated video card memory in megabytes.
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
//.........这里部分代码省略.........
示例7: ZeroMemory
bool InitDirect3D(RENDERER_SETTINGS * pSetup)
{
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
DXGI_SWAP_CHAIN_DESC desc;
ZeroMemory(&desc, sizeof(DXGI_SWAP_CHAIN_DESC));
desc.BufferCount = 1;
desc.BufferDesc.Width = pSetup->nWidth;
desc.BufferDesc.Height = pSetup->nHeight;
desc.BufferDesc.Format = format;
if (pSetup->bVsync)
{
bVsync = true;
IDXGIFactory1 * pFactory = NULL;
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory);
if (pFactory)
{
IDXGIAdapter1 * pAdapter = NULL;
pFactory->EnumAdapters1( 0, &pAdapter );
if (pAdapter)
{
IDXGIOutput * pOutput = NULL;
pAdapter->EnumOutputs( 0, &pOutput );
if (pOutput)
{
unsigned int nModeCount = 0;
pOutput->GetDisplayModeList( format, DXGI_ENUM_MODES_INTERLACED | DXGI_ENUM_MODES_SCALING, &nModeCount, NULL);
DXGI_MODE_DESC * pModes = new DXGI_MODE_DESC[ nModeCount ];
pOutput->GetDisplayModeList( format, DXGI_ENUM_MODES_INTERLACED | DXGI_ENUM_MODES_SCALING, &nModeCount, pModes);
for (int i=0; i<nModeCount; i++)
{
if (pModes[i].Width == pSetup->nWidth && pModes[i].Height == pSetup->nHeight)
{
desc.BufferDesc = pModes[i];
break;
}
}
delete[] pModes;
pOutput->Release();
}
pAdapter->Release();
}
pFactory->Release();
}
}
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = hWnd;
desc.SampleDesc.Count = 1;
desc.Windowed = pSetup->windowMode != RENDERER_WINDOWMODE_FULLSCREEN;
DWORD deviceCreationFlags = 0;
#ifdef _DEBUG
//deviceCreationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
if (D3D11CreateDeviceAndSwapChain(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
deviceCreationFlags,
NULL,
NULL,
D3D11_SDK_VERSION,
&desc,
&pSwapChain,
&pDevice,
NULL,
&pContext) != S_OK)
{
printf("[Renderer] D3D11CreateDeviceAndSwapChain failed\n");
return false;
}
pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer);
pDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTarget);
pBackBuffer->Release();
pContext->OMSetRenderTargets(1, &pRenderTarget, NULL);
// create staging texture for frame grabbing
D3D11_TEXTURE2D_DESC description;
pBackBuffer->GetDesc( &description );
description.BindFlags = 0;
description.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
description.Usage = D3D11_USAGE_STAGING;
HRESULT hr = pDevice->CreateTexture2D( &description, NULL, &pFrameGrabTexture );
return true;
}
示例8: CreateDXGIFactory
bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen,
float screenDepth, float screenNear)
{
HRESULT result = E_FAIL;
// create DirectX graphics interface factory (need to generating other DXGI objects)
IDXGIFactory* factory = nullptr;
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result))
return false;
// create adapter
IDXGIAdapter* adapter = nullptr;
result = factory->EnumAdapters(0, &adapter);
if (FAILED(result))
return false;
// enumerate outputs
IDXGIOutput* adapterOutput = nullptr;
result = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(result))
return false;
// get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format
unsigned numModes = 0;
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED,
&numModes, NULL);
if (FAILED(result))
return false;
// create a list to hold all possible display modes
DXGI_MODE_DESC* displayModeList = new DXGI_MODE_DESC[numModes];
if (!displayModeList)
return false;
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED,
&numModes, displayModeList);
if (FAILED(result))
return false;
// go through all displays modes and find the one, that matches the screen width and height
unsigned numerator = 0, denominator = 0;
for (int i = 0; i < numModes; ++i)
{
if (displayModeList[i].Width == (unsigned)screenWidth)
{
if (displayModeList[i].Height == (unsigned)screenHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
// get the adapter description
DXGI_ADAPTER_DESC adapterDesc;
result = adapter->GetDesc(&adapterDesc);
if (FAILED(result))
return false;
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024); // store in megabytes
// convert the name of videocard to a character array and store it
unsigned stringLength = 0;
int error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
if (error)
return false;
// write video card data in text file
std::ofstream videocardFile;
videocardFile.open("VideoCardInfo.txt");
videocardFile << "Video Card: " << m_videoCardDescription << std::endl
<< "Video Card Memory: " << m_videoCardMemory << "Mb" << std::endl;
videocardFile.close();
// release the structures and interfaces used to get information
delete[] displayModeList;
displayModeList = nullptr;
adapterOutput->Release();
adapterOutput = nullptr;
adapter->Release();
adapter = nullptr;
factory->Release();
factory = nullptr;
// initialize the swap chain description
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
if (m_vsync_enabled)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
}
//.........这里部分代码省略.........
示例9: DXTInitDevice
HRESULT DXTInitDevice(const DXTRenderParams& params, const DXTWindow* window, IDXGISwapChain** swapChainOut,
ID3D11Device** deviceOut, ID3D11DeviceContext** deviceContextOut)
{
IDXGIFactory* factory;
HRESULT result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
IDXGIAdapter* adapter;
result = factory->EnumAdapters(0, &adapter);
IDXGIOutput* adapterOutput;
result = adapter->EnumOutputs(0, &adapterOutput);
UINT modeCount;
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED, &modeCount, nullptr);
DXGI_MODE_DESC* modeDescriptions = new DXGI_MODE_DESC[modeCount];
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED, &modeCount, modeDescriptions);
DXGI_MODE_DESC* descMatch = nullptr;
for (UINT i = 0; i < modeCount; ++i)
{
DXGI_MODE_DESC* desc = &modeDescriptions[i];
if (desc->Width == params.Extent.Width && desc->Height == params.Extent.Height)
{
OutputDebugString("Found compatible display mode!\n");
descMatch = desc;
break;
}
}
if (descMatch == nullptr)
{
OutputDebugString("No DXGI mode match found - using a default!\n");
descMatch = modeDescriptions;
}
DXGI_ADAPTER_DESC adapterDesc;
result = adapter->GetDesc(&adapterDesc);
adapterOutput->Release();
adapter->Release();
factory->Release();
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.Windowed = params.Windowed;
swapChainDesc.BufferCount = 2;
swapChainDesc.BufferDesc = *descMatch;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = window->GetWindowHandle();
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
delete[] modeDescriptions;
UINT deviceCreationFlags = 0;
#ifdef ENABLE_DIRECT3D_DEBUG
deviceCreationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
if (!params.Windowed)
swapChainDesc.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
OutputDebugString("Creating device and swap chain...\n");
D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
result = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
deviceCreationFlags, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc,
swapChainOut, deviceOut, nullptr, deviceContextOut);
if (FAILED(result))
{
OutputDebugString("Failed to create device and swap chain!\n");
return E_FAIL;
}
OutputDebugString("Device and swap chain created successfully!\n");
return S_OK;
}
示例10: InitFactory
bool InitFactory()
{
HRESULT result;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, i, numerator, denominator, stringLength;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
int error;
// Create a DirectX graphics interface factory.
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result))
{
return false;
}
// Use the factory to create an adapter for the primary graphics interface (video card).
result = factory->EnumAdapters(0, &adapter);
if (FAILED(result))
{
return false;
}
// Enumerate the primary adapter output (monitor).
result = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(result))
{
return false;
}
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if (FAILED(result))
{
return false;
}
// Create a list to hold all the possible display modes for this monitor/video card combination.
displayModeList = new DXGI_MODE_DESC[numModes];
if (!displayModeList)
{
return false;
}
// Now fill the display mode list structures.
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if (FAILED(result))
{
return false;
}
// Now go through all the display modes and find the one that matches the screen width and height.
// When a match is found store the numerator and denominator of the refresh rate for that monitor.
for (i = 0; i < numModes; i++)
{
if (displayModeList[i].Width == WIN_WIDTH)
{
if (displayModeList[i].Height == WIN_HEIGHT)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
// Get the adapter (video card) description.
result = adapter->GetDesc(&adapterDesc);
if (FAILED(result))
{
return false;
}
char m_videoCardDescription[128];
// Convert the name of the video card to a character array and store it.
error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
if (error != 0)
{
return false;
}
delete[] displayModeList;
displayModeList = 0;
// Release the adapter output.
adapterOutput->Release();
adapterOutput = 0;
// Release the adapter.
adapter->Release();
adapter = 0;
// Release the factory.
factory->Release();
factory = 0;
return true;
//.........这里部分代码省略.........
示例11: CollectAdapters
bool CDirectEngine::CollectAdapters(Vector2<unsigned int> aWindowSize, Vector2<int>& aNumDenumerator, IDXGIAdapter*& outAdapter)
{
HRESULT result = S_OK;
IDXGIFactory* factory;
DXGI_MODE_DESC* displayModeList = nullptr;
unsigned int numModes = 0;
unsigned int i = 0;
unsigned int denominator = 0;
unsigned int numerator = 0;
result = CreateDXGIFactory( __uuidof( IDXGIFactory ), (void**)&factory );
if( FAILED( result ) )
{
return false;
}
// Use the factory to create an adapter for the primary graphics interface (video card).
IDXGIAdapter* usingAdapter = nullptr;
int adapterIndex = 0;
std::vector<DXGI_ADAPTER_DESC> myAdapterDescs;
std::vector<IDXGIAdapter*> myAdapters;
while (factory->EnumAdapters(adapterIndex, &usingAdapter) != DXGI_ERROR_NOT_FOUND)
{
DXGI_ADAPTER_DESC adapterDesc;
usingAdapter->GetDesc(&adapterDesc);
myAdapterDescs.push_back( adapterDesc );
myAdapters.push_back(usingAdapter);
++adapterIndex;
}
if( adapterIndex == 0 )
{
return false;
}
INFO_PRINT( "%s", "Video card(s) detected: " );
for( DXGI_ADAPTER_DESC desc : myAdapterDescs )
{
int memory = (int)(desc.DedicatedVideoMemory / 1024 / 1024);
INFO_PRINT(" %ls%s%i%s", desc.Description, " Mem: ", memory, "Mb");
}
DXGI_ADAPTER_DESC usingAdapterDesc = myAdapterDescs[0];
usingAdapter = myAdapters[0];
INFO_PRINT("%s", "Detecting best card...");
const std::wstring nvidia = L"NVIDIA";
const std::wstring ati = L"ATI";
int memory = (int)(usingAdapterDesc.DedicatedVideoMemory / 1024 / 1024);
int mostMem = 0;
for (unsigned int i = 0; i < myAdapterDescs.size(); i++)
{
DXGI_ADAPTER_DESC desc = myAdapterDescs[i];
memory = (int)(desc.DedicatedVideoMemory / 1024 / 1024);
std::wstring name = desc.Description;
if (name.find(nvidia) != std::wstring::npos || name.find(ati) != std::wstring::npos)
{
if (memory > mostMem)
{
mostMem = memory;
usingAdapterDesc = desc;
usingAdapter = myAdapters[i];
}
}
}
INFO_PRINT("%s%ls%s%i", "Using graphic card: ", usingAdapterDesc.Description, " Dedicated Mem: ", mostMem);
// Enumerate the primary adapter output (monitor).
IDXGIOutput* pOutput = nullptr;
if (usingAdapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND)
{
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
result = pOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if (!FAILED(result))
{
// Create a list to hold all the possible display modes for this monitor/video card combination.
displayModeList = new DXGI_MODE_DESC[numModes];
if (displayModeList)
{
// Now fill the display mode list structures.
result = pOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if (!FAILED(result))
{
// Now go through all the display modes and find the one that matches the screen width and height.
// When a match is found store the numerator and denominator of the refresh rate for that monitor.
for (i = 0; i < numModes; i++)
{
if (displayModeList[i].Width == (unsigned int)aWindowSize.x)
{
if (displayModeList[i].Height == (unsigned int)aWindowSize.y)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
//.........这里部分代码省略.........
示例12: CreateDXGIFactory
bool graphicD3d::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear)
{
HRESULT hr;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
UINT nummodes, numerator, denominator;
DXGI_MODE_DESC* displayModelist;
DXGI_ADAPTER_DESC adapterDesc;
DXGI_SWAP_CHAIN_DESC swapchainDesc;
D3D11_TEXTURE2D_DESC depthBufferDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D11_RASTERIZER_DESC rasterDesc;
D3D11_VIEWPORT viewport;
// 수직동기화 설정 ( true / false )
m_vsync = vsync;
//DirectX Graphic Infrastructure 인터페이스 팩토리 만들기.
hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(hr))
return false;
//첫번째 그래픽 카드 어댑터 만들기.
hr = factory->EnumAdapters(0, &adapter);
if (FAILED(hr))
return false;
//첫번째 모니터의 어댑터 만들기.
hr = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(hr))
return false;
//DXGI_FORMAT_R8G8B8A8_UNORM 모니터 출력 포멧에 맞는 모드의 개수 구하기.
hr = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &nummodes, NULL);
if (FAILED(hr))
return false;
//사용 가능한 모든 모니터와 그래픽카드 조합을 저장할 리스트 생성.
displayModelist = new DXGI_MODE_DESC[nummodes];
if (!displayModelist)
return false;
//displayModelist 에 값들 채워넣기.
hr = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &nummodes, displayModelist);
if (FAILED(hr))
return false;
//그래픽 카드와 모니터의 화면 너비/높이 조합을 찾기 완료.
//모니터의 refresh rate 의 분모 와 분자 값을 저장.
for (int i = 0; i < nummodes; i++)
{
if (displayModelist[i].Width == (UINT)screenWidth &&
displayModelist[i].Height == (UINT)screenHeight)
{
numerator = displayModelist[i].RefreshRate.Numerator;
denominator = displayModelist[i].RefreshRate.Denominator;
}
}
/*
*/
//그래픽 카드 정보 가져오기.
hr = adapter->GetDesc(&adapterDesc);
if (FAILED(hr))
return false;
//그래픽 카드 메모리 크기 가져오기. ( MegaBytes )
m_videoMemory = UINT(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
//그래픽 카드 이름 가져오기.
lstrcpynW(m_videoDescription, adapterDesc.Description, 128);
/*
*/
// 원하는 정보 조회 끝나면, 해당 리소스들 해제
delete [] displayModelist;
displayModelist = nullptr;
//모니터 출력 어댑터 해제
adapterOutput->Release();
adapterOutput = nullptr;
//그래픽카드 어댑터 해제
adapter->Release();
adapter = nullptr;
//팩토리 해제
factory->Release();
factory = nullptr;
//.........这里部分代码省略.........
示例13: WINRT_AddDisplaysForOutput
static int
WINRT_AddDisplaysForOutput (_THIS, IDXGIAdapter1 * dxgiAdapter1, int outputIndex)
{
HRESULT hr;
IDXGIOutput * dxgiOutput = NULL;
DXGI_OUTPUT_DESC dxgiOutputDesc;
SDL_VideoDisplay display;
char * displayName = NULL;
UINT numModes;
DXGI_MODE_DESC * dxgiModes = NULL;
int functionResult = -1; /* -1 for failure, 0 for success */
DXGI_MODE_DESC modeToMatch, closestMatch;
SDL_zero(display);
hr = dxgiAdapter1->EnumOutputs(outputIndex, &dxgiOutput);
if (FAILED(hr)) {
if (hr != DXGI_ERROR_NOT_FOUND) {
WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIAdapter1::EnumOutputs failed", hr);
}
goto done;
}
hr = dxgiOutput->GetDesc(&dxgiOutputDesc);
if (FAILED(hr)) {
WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDesc failed", hr);
goto done;
}
SDL_zero(modeToMatch);
modeToMatch.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
modeToMatch.Width = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
modeToMatch.Height = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
hr = dxgiOutput->FindClosestMatchingMode(&modeToMatch, &closestMatch, NULL);
if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) {
/* DXGI_ERROR_NOT_CURRENTLY_AVAILABLE gets returned by IDXGIOutput::FindClosestMatchingMode
when running under the Windows Simulator, which uses Remote Desktop (formerly known as Terminal
Services) under the hood. According to the MSDN docs for the similar function,
IDXGIOutput::GetDisplayModeList, DXGI_ERROR_NOT_CURRENTLY_AVAILABLE is returned if and
when an app is run under a Terminal Services session, hence the assumption.
In this case, just add an SDL display mode, with approximated values.
*/
SDL_DisplayMode mode;
SDL_zero(mode);
display.name = "Windows Simulator / Terminal Services Display";
mode.w = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
mode.h = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
mode.refresh_rate = 0; /* Display mode is unknown, so just fill in zero, as specified by SDL's header files */
display.desktop_mode = mode;
display.current_mode = mode;
if ( ! SDL_AddDisplayMode(&display, &mode)) {
goto done;
}
} else if (FAILED(hr)) {
WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::FindClosestMatchingMode failed", hr);
goto done;
} else {
displayName = WIN_StringToUTF8(dxgiOutputDesc.DeviceName);
display.name = displayName;
WINRT_DXGIModeToSDLDisplayMode(&closestMatch, &display.desktop_mode);
display.current_mode = display.desktop_mode;
hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_B8G8R8A8_UNORM, 0, &numModes, NULL);
if (FAILED(hr)) {
if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) {
// TODO, WinRT: make sure display mode(s) are added when using Terminal Services / Windows Simulator
}
WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDisplayModeList [get mode list size] failed", hr);
goto done;
}
dxgiModes = (DXGI_MODE_DESC *)SDL_calloc(numModes, sizeof(DXGI_MODE_DESC));
if ( ! dxgiModes) {
SDL_OutOfMemory();
goto done;
}
hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_B8G8R8A8_UNORM, 0, &numModes, dxgiModes);
if (FAILED(hr)) {
WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDisplayModeList [get mode contents] failed", hr);
goto done;
}
for (UINT i = 0; i < numModes; ++i) {
SDL_DisplayMode sdlMode;
WINRT_DXGIModeToSDLDisplayMode(&dxgiModes[i], &sdlMode);
SDL_AddDisplayMode(&display, &sdlMode);
}
}
if (SDL_AddVideoDisplay(&display) < 0) {
goto done;
}
functionResult = 0; /* 0 for Success! */
done:
if (dxgiModes) {
SDL_free(dxgiModes);
//.........这里部分代码省略.........
示例14: CreateDXGIFactory
bool D3D::InitializeD3D(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen)
{
HRESULT result; //used to test things are created ok.
vsync;
//----------------------------------------------------------------------------------------------
// Fetch the numerator and denominator for refresh rate and video card description.
// Create DirectX Graphics Interface factory.
IDXGIFactory* factory;
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if(FAILED(result))
return false;
// Create adapter.
IDXGIAdapter* adapter;
result = factory->EnumAdapters(0, &adapter);
if(FAILED(result))
return false;
// Enumerate primary adapter output (monitor).
IDXGIOutput* adapterOutput;
result = adapter->EnumOutputs(0, &adapterOutput);
if(FAILED(result))
return false;
// Get the number of modes that fit the DXGI_R8G8B8A8_UNORM display format for adpater output.
unsigned int numModes;
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if(FAILED(result))
return false;
// Create a list to hold all possible display modes.
DXGI_MODE_DESC* displayModeList;
displayModeList = new DXGI_MODE_DESC[numModes];
if(!displayModeList)
return false;
// Fill list.
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if(FAILED(result))
return false;
// Loop through modes and find one that matches screen width and height, store numerator and
// denominator for corresponding refresh rate.
unsigned int numerator, denominator;
for(unsigned int i = 0; i < numModes; ++i)
{
if(displayModeList[i].Width == (unsigned int)screenWidth &&
displayModeList[i].Height == (unsigned int)screenHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
// Get adapter description.
DXGI_ADAPTER_DESC adapterDesc;
result = adapter->GetDesc(&adapterDesc);
if(FAILED(result))
return false;
// Store dedicated video card memory (in mb).
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
// Convert the name of the video card to char array and store.
unsigned int stringLength;
int error = wcstombs_s(&stringLength, m_videoCardDesc, 128, adapterDesc.Description, 128);
if(error != 0)
return false;
// Release unneeded memory.
delete[] displayModeList;
displayModeList = 0;
adapterOutput->Release();
adapterOutput = 0;
adapter->Release();
adapter = 0;
factory->Release();
factory = 0;
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
// Set up SwapChain description and create swap chain.
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
// Setup back buffer.
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
// Refresh Rate.
if(m_vsyncEnabled)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
//.........这里部分代码省略.........
示例15: app_display_querymodes
char* app_display_querymodes()
{
IDXGIFactory* factory;
if (FAILED(CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory)))
return NULL;
IDXGIAdapter* adapter;
uint adapter_id = 0;
DXGI_ADAPTER_DESC desc;
char gpu_desc[128];
size_t outsz;
/* start json data (adapter array) */
json_t jroot = json_create_arr();
/* read adapters */
while (factory->EnumAdapters(adapter_id, &adapter) != DXGI_ERROR_NOT_FOUND) {
adapter->GetDesc(&desc);
str_widetomb(gpu_desc, desc.Description, sizeof(gpu_desc));
json_t jadapter = json_create_obj();
json_additem_toarr(jroot, jadapter);
json_additem_toobj(jadapter, "name", json_create_str(gpu_desc));
json_additem_toobj(jadapter, "id", json_create_num((fl64)adapter_id));
/* enumerate monitors */
json_t joutputs = json_create_arr();
json_additem_toobj(jadapter, "outputs", joutputs);
IDXGIOutput* output;
uint output_id = 0;
while (adapter->EnumOutputs(output_id, &output) != DXGI_ERROR_NOT_FOUND) {
json_t joutput = json_create_obj();
json_additem_toarr(joutputs, joutput);
json_additem_toobj(joutput, "id", json_create_num((fl64)output_id));
/* enumerate modes */
json_t jmodes = json_create_arr();
json_additem_toobj(joutput, "monitors", jmodes);
uint mode_cnt;
HRESULT hr = output->GetDisplayModeList(DEFAULT_DISPLAY_FORMAT, 0, &mode_cnt, NULL);
if (SUCCEEDED(hr)) {
DXGI_MODE_DESC* modes = (DXGI_MODE_DESC*)ALLOC(sizeof(DXGI_MODE_DESC) * mode_cnt, 0);
ASSERT(modes);
output->GetDisplayModeList(DEFAULT_DISPLAY_FORMAT, 0, &mode_cnt, modes);
for (uint i = 0; i < mode_cnt; i++) {
if (modes[i].RefreshRate.Denominator != 1)
continue;
json_t jmode = json_create_obj();
json_additem_toobj(jmode, "width", json_create_num((fl64)modes[i].Width));
json_additem_toobj(jmode, "height", json_create_num((fl64)modes[i].Height));
json_additem_toobj(jmode, "refresh-rate",
json_create_num((fl64)modes[i].RefreshRate.Numerator));
json_additem_toarr(jmodes, jmode);
}
FREE(modes);
}
output_id ++;
}
adapter->Release();
adapter_id ++;
}
factory->Release();
char* r = json_savetobuffer(jroot, &outsz, FALSE);
json_destroy(jroot);
return r;
}