本文整理汇总了C++中IDXGIFactory::EnumAdapters方法的典型用法代码示例。如果您正苦于以下问题:C++ IDXGIFactory::EnumAdapters方法的具体用法?C++ IDXGIFactory::EnumAdapters怎么用?C++ IDXGIFactory::EnumAdapters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDXGIFactory
的用法示例。
在下文中一共展示了IDXGIFactory::EnumAdapters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: CreateDXGIFactory
bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hWnd, bool fullscreen, float screenDepth, float screenNear)
{
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;
_vsync_enabled = vsync;
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result))
{
return false;
}
result = factory->EnumAdapters(0, &adapter);
if (FAILED(result))
{
return false;
}
result = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(result))
{
return false;
}
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if (FAILED(result))
{
return false;
}
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;
}
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;
}
}
}
result = adapter->GetDesc(&adapterDesc);
if (FAILED(result))
{
return false;
}
_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
error = wcstombs_s(&stringLength, _videoCardDescription, 128, adapterDesc.Description, 128);
if (error != 0)
{
return false;
}
delete[] displayModeList;
displayModeList = NULL;
adapterOutput->Release();
adapterOutput = NULL;
adapter->Release();
adapter = NULL;
factory->Release();
factory = NULL;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 1;
//.........这里部分代码省略.........
示例3: 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;
}
//.........这里部分代码省略.........
示例4: initializeEngine
bool initializeEngine()
{
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;
g_swapChain = 0;
g_device = 0;
g_deviceContext = 0;
g_renderTargetView = 0;
g_depthStencilTexture = 0;
g_depthStencilState = 0;
g_depthStencilView = 0;
g_rasterState = 0;
// 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) g_screenWidth)
{
if (displayModeList[i].Height == (unsigned int) g_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.
g_videoCardMemory = (int) (adapterDesc.DedicatedVideoMemory / 1024 / 1024);
// Convert the name of the video card to a character array and store it.
error = wcstombs_s(&stringLength, g_videoCardDescription, 128, adapterDesc.Description, 128);
if (error != 0)
//.........这里部分代码省略.........
示例5: 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;
}
示例6: CreateTheDevice
bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
hWnd_ = wnd;
LoadD3D11Error result = LoadD3D11();
HRESULT hr = E_FAIL;
std::vector<std::string> adapterNames;
std::string chosenAdapterName;
if (result == LoadD3D11Error::SUCCESS) {
std::vector<IDXGIAdapter *> adapters;
int chosenAdapter = 0;
IDXGIFactory * pFactory = nullptr;
ptr_CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&pFactory);
IDXGIAdapter *pAdapter;
for (UINT i = 0; pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; i++) {
adapters.push_back(pAdapter);
DXGI_ADAPTER_DESC desc;
pAdapter->GetDesc(&desc);
std::string str = ConvertWStringToUTF8(desc.Description);
adapterNames.push_back(str);
if (str == g_Config.sD3D11Device) {
chosenAdapter = i;
}
}
chosenAdapterName = adapterNames[chosenAdapter];
hr = CreateTheDevice(adapters[chosenAdapter]);
for (int i = 0; i < (int)adapters.size(); i++) {
adapters[i]->Release();
}
}
if (FAILED(hr)) {
const char *defaultError = "Your GPU does not appear to support Direct3D 11.\n\nWould you like to try again using Direct3D 9 instead?";
I18NCategory *err = GetI18NCategory("Error");
std::wstring error;
if (result == LoadD3D11Error::FAIL_NO_COMPILER) {
error = ConvertUTF8ToWString(err->T("D3D11CompilerMissing", "D3DCompiler_47.dll not found. Please install. Or press Yes to try again using Direct3D9 instead."));
} else if (result == LoadD3D11Error::FAIL_NO_D3D11) {
error = ConvertUTF8ToWString(err->T("D3D11Missing", "Your operating system version does not include D3D11. Please run Windows Update.\n\nPress Yes to try again using Direct3D9 instead."));
}
error = ConvertUTF8ToWString(err->T("D3D11NotSupported", defaultError));
std::wstring title = ConvertUTF8ToWString(err->T("D3D11InitializationError", "Direct3D 11 initialization error"));
bool yes = IDYES == MessageBox(hWnd_, error.c_str(), title.c_str(), MB_ICONERROR | MB_YESNO);
if (yes) {
// Change the config to D3D9 and restart.
g_Config.iGPUBackend = (int)GPUBackend::DIRECT3D9;
g_Config.sFailedGPUBackends.clear();
g_Config.Save("save_d3d9_fallback");
W32Util::ExitAndRestart();
}
return false;
}
if (FAILED(device_->QueryInterface(__uuidof (ID3D11Device1), (void **)&device1_))) {
device1_ = nullptr;
}
if (FAILED(context_->QueryInterface(__uuidof (ID3D11DeviceContext1), (void **)&context1_))) {
context1_ = nullptr;
}
#ifdef _DEBUG
if (SUCCEEDED(device_->QueryInterface(__uuidof(ID3D11Debug), (void**)&d3dDebug_))) {
if (SUCCEEDED(d3dDebug_->QueryInterface(__uuidof(ID3D11InfoQueue), (void**)&d3dInfoQueue_))) {
d3dInfoQueue_->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
d3dInfoQueue_->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
d3dInfoQueue_->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true);
}
}
#endif
draw_ = Draw::T3DCreateD3D11Context(device_, context_, device1_, context1_, featureLevel_, hWnd_, adapterNames);
SetGPUBackend(GPUBackend::DIRECT3D11, chosenAdapterName);
bool success = draw_->CreatePresets(); // If we can run D3D11, there's a compiler installed. I think.
_assert_msg_(G3D, success, "Failed to compile preset shaders");
int width;
int height;
GetRes(hWnd_, width, height);
// Obtain DXGI factory from device (since we used nullptr for pAdapter above)
IDXGIFactory1* dxgiFactory = nullptr;
IDXGIDevice* dxgiDevice = nullptr;
IDXGIAdapter* adapter = nullptr;
hr = device_->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice));
if (SUCCEEDED(hr)) {
hr = dxgiDevice->GetAdapter(&adapter);
if (SUCCEEDED(hr)) {
hr = adapter->GetParent(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory));
DXGI_ADAPTER_DESC desc;
adapter->GetDesc(&desc);
adapter->Release();
}
dxgiDevice->Release();
//.........这里部分代码省略.........
示例7: 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;
//.........这里部分代码省略.........
示例8: CHECK
bool D3DRenderer::Initialize( int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenFar, float screenNear )
{
// Store the vsync setting.
m_vsync_enabled = vsync;
// Create a DirectX graphics interface factory.
IDXGIFactory* factory;
CHECK( CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory) );
// Use the factory to create an adapter for the primary graphics interface (video card).
IDXGIAdapter* adapter;
CHECK( factory->EnumAdapters( 0, &adapter ) );
// Enumerate the primary adapter output (monitor).
IDXGIOutput* adapterOutput;
CHECK( adapter->EnumOutputs( 0, &adapterOutput ) );
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
unsigned numModes;
CHECK( adapterOutput->GetDisplayModeList( DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, 0 ) );
// Create a list to hold all the possible display modes for this monitor/video card combination.
DXGI_MODE_DESC* displayModeList = new DXGI_MODE_DESC[numModes];
if(!displayModeList)
return false;
// Now fill the display mode list structures.
CHECK( adapterOutput->GetDisplayModeList( DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList ) );
// 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 numerator, denominator;
for( unsigned 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 (video card) description.
DXGI_ADAPTER_DESC adapterDesc;
CHECK( adapter->GetDesc(&adapterDesc) );
// Release the display mode list.
delete [] displayModeList;
displayModeList = 0;
// Release the adapter output.
ReleaseCOM(adapterOutput);
ReleaseCOM(adapter);
ReleaseCOM(factory);
DXGI_SWAP_CHAIN_DESC swapChainDesc;
// Initialize the swap chain description.
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
// Set to a single back buffer.
swapChainDesc.BufferCount = 1;
// Set the width and height of the back buffer.
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
// Set regular 32-bit surface for the back buffer.
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
// Set the refresh rate of the back buffer.
if(m_vsync_enabled)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
}
else
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}
// Set the usage of the back buffer.
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
// Set the handle for the window to render to.
swapChainDesc.OutputWindow = hwnd;
// Turn multi-sampling off.
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
// Set to full screen or windowed mode.
if(fullscreen)
swapChainDesc.Windowed = false;
else
swapChainDesc.Windowed = true;
//.........这里部分代码省略.........
示例9: CreateDXGIFactory
/*
* Initialize()
* brief: This function does all the set up needed for DirectX11.
* param screenWidth: The window width.
* param screenWidth: The window height.
* param vsync: Whether the vsync is activated or not.
* param hwnd: The window handler.
* param fullscreen: Whether if the fullscreen mode is activated or not.
* param screenDepth: The setting to know how far our 3D environment will render.
* param screenNear: The setting to know how near our 3D environment will render.
*/
bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen,
float screenFar, float screenNear)
{
//TODO: Split this function in smaller functions. Also, return an error message if failed the initialization to know the reason.
HRESULT hResult;
IDXGIFactory* dxgiFactory;
IDXGIAdapter* dxgiAdapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, numarator, denominator;
unsigned long long stringLength;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
int error;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
D3D_FEATURE_LEVEL featureLevel;
ID3D11Texture2D* backBufferPntr;
D3D11_TEXTURE2D_DESC depthBufferDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D11_RASTERIZER_DESC rasterizerDesc;
D3D11_VIEWPORT viewport;
float fieldOfView, screenAspect;
m_vSyncEnabled = vsync;
//Create DirectX graphics interface factory.
hResult = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&dxgiFactory);
if (FAILED(hResult))
{
return false;
}
//Use a factory to create an adapter for the primary graphics interface.
hResult = dxgiFactory->EnumAdapters(0, &dxgiAdapter);
if (FAILED(hResult))
{
return false;
}
//Enumerate the primary adapter output (monitor).
hResult = dxgiAdapter->EnumOutputs(0, &adapterOutput);
if (FAILED(hResult))
{
return false;
}
//Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
hResult = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if (FAILED(hResult))
{
return false;
}
//Create a list to hold all the possible display modes for this monitor/video card combinations.
displayModeList = new DXGI_MODE_DESC[numModes];
if (!displayModeList)
{
return false;
}
//Fill the display mode list structures.
hResult = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if (FAILED(hResult))
{
return false;
}
//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 (unsigned int i = 0; i < numModes; i++)
{
if (displayModeList[i].Width == (unsigned int)screenWidth)
{
if (displayModeList[i].Height == (unsigned int)screenHeight)
{
numarator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
//Get the adapter (video card) descriptor.
hResult = dxgiAdapter->GetDesc(&adapterDesc);
{
if (FAILED(hResult))
{
return false;
}
}
//.........这里部分代码省略.........
示例10: 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;
}
}
}
//.........这里部分代码省略.........
示例11: createDevice
//*************************************************************************************************
// Create the device
//*************************************************************************************************
SBOOL RenderContext::createDevice()
{
// Create the device and device context
UINT createDeviceFlags = 0;
#if defined(DEBUG) || defined(_DEBUG)
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
HRESULT hr = S_OK;
// Set the desired feature level
D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
D3D_FEATURE_LEVEL targetLevels[] =
{
D3D_FEATURE_LEVEL_11_0
};
SUINT numFeatureLevels = 1;
// Create a device factory so that we can find a DX11 compatible device
IDXGIFactory* factory = 0;
IDXGIAdapter* adapter = 0;
hr = CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory));
if(FAILED(hr))
{
MessageBox(0, "Failed to create IDXGIFactory.", 0, 0);
return false;
}
// Get selected device if it is part of the config
Configuration* config = ConfigurationManager::getSingletonPtr()->getConfiguration("Engine");
String configAdapter = config->retrieveValue("adapter");
// Iterate through adapters to find a compatible one
DXGI_ADAPTER_DESC adapterDesc;
for(SINT i = 0; factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i)
{
// Get the adapter description
adapter->GetDesc(&adapterDesc);
// See whether this adapter matches the one we selected
if(configAdapter == adapterDesc.Description)
{
// Use this adapter
break;
}
}
if(adapter)
{
// Create the device using the specified adapter
_d3dDriverType = D3D_DRIVER_TYPE_UNKNOWN;
hr = D3D11CreateDevice(
adapter, // Selected adapter
_d3dDriverType,
0,
createDeviceFlags, // Support debug mode
targetLevels, // Target feature levels
numFeatureLevels, // Number of supported feature levels
D3D11_SDK_VERSION,
&_d3dDevice,
&featureLevel,
&_d3dImmediateContext
);
}
else
{
_d3dDriverType = D3D_DRIVER_TYPE_HARDWARE;
hr = D3D11CreateDevice(
0,
_d3dDriverType,
0,
createDeviceFlags,
targetLevels,
numFeatureLevels,
D3D11_SDK_VERSION,
&_d3dDevice,
&featureLevel,
&_d3dImmediateContext
);
}
if(FAILED(hr))
{
MessageBox(0, "D3DCreateDevice Failed", 0, 0);
return false;
}
// Check for DX11 support
if(featureLevel != D3D_FEATURE_LEVEL_11_0)
{
MessageBox(0, "DirectX 11 is not supported on this device", 0, 0);
return false;
}
// Creation of device succeeded
return true;
}
示例12: Create
HRESULT Create(HWND wnd)
{
hWnd = wnd;
HRESULT hr;
RECT client;
GetClientRect(hWnd, &client);
xres = client.right - client.left;
yres = client.bottom - client.top;
hr = LoadDXGI();
if (SUCCEEDED(hr)) hr = LoadD3D();
if (SUCCEEDED(hr)) hr = LoadD3DCompiler();
if (FAILED(hr))
{
UnloadDXGI();
UnloadD3D();
UnloadD3DCompiler();
return hr;
}
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* output;
hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to create IDXGIFactory object"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
hr = factory->EnumAdapters(g_ActiveConfig.iAdapter, &adapter);
if (FAILED(hr))
{
// try using the first one
hr = factory->EnumAdapters(0, &adapter);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to enumerate adapters"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
}
// TODO: Make this configurable
hr = adapter->EnumOutputs(0, &output);
if (FAILED(hr))
{
// try using the first one
IDXGIAdapter* firstadapter;
hr = factory->EnumAdapters(0, &firstadapter);
if (!FAILED(hr))
hr = firstadapter->EnumOutputs(0, &output);
if (FAILED(hr)) MessageBox(wnd,
_T("Failed to enumerate outputs!\n")
_T("This usually happens when you've set your video adapter to the Nvidia GPU in an Optimus-equipped system.\n")
_T("Set Dolphin to use the high-performance graphics in Nvidia's drivers instead and leave Dolphin's video adapter set to the Intel GPU."),
_T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
SAFE_RELEASE(firstadapter);
}
// get supported AA modes
aa_modes = EnumAAModes(adapter);
if (g_Config.iMultisampleMode >= (int)aa_modes.size())
{
g_Config.iMultisampleMode = 0;
UpdateActiveConfig();
}
DXGI_SWAP_CHAIN_DESC swap_chain_desc;
memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
swap_chain_desc.BufferCount = 1;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.OutputWindow = wnd;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.Windowed = !g_Config.bFullscreen;
DXGI_OUTPUT_DESC out_desc;
memset(&out_desc, 0, sizeof(out_desc));
output->GetDesc(&out_desc);
DXGI_MODE_DESC mode_desc;
memset(&mode_desc, 0, sizeof(mode_desc));
mode_desc.Width = out_desc.DesktopCoordinates.right - out_desc.DesktopCoordinates.left;
mode_desc.Height = out_desc.DesktopCoordinates.bottom - out_desc.DesktopCoordinates.top;
mode_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
mode_desc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
hr = output->FindClosestMatchingMode(&mode_desc, &swap_chain_desc.BufferDesc, nullptr);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to find a supported video mode"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
if (swap_chain_desc.Windowed)
{
// forcing buffer resolution to xres and yres..
// this is not a problem as long as we're in windowed mode
swap_chain_desc.BufferDesc.Width = xres;
swap_chain_desc.BufferDesc.Height = yres;
}
#if defined(_DEBUG) || defined(DEBUGFAST)
// Creating debug devices can sometimes fail if the user doesn't have the correct
// version of the DirectX SDK. If it does, simply fallback to a non-debug device.
{
hr = PD3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_DEBUG,
supported_feature_levels, NUM_SUPPORTED_FEATURE_LEVELS,
D3D11_SDK_VERSION, &swap_chain_desc, &swapchain, &device,
&featlevel, &context);
}
//.........这里部分代码省略.........
示例13: 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;
//.........这里部分代码省略.........
示例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: GetSystemMetrics
bool CD3DGraphics11::Init(HWND hWnd, UINT clientWidth, UINT clientHeight )
{
cout << "CD3DGraphics11: Client Height " << clientHeight <<"\n";
cout << "CD3DGraphics11: Client Width " << clientWidth << "\n";
m_clientHeight = clientHeight;
m_clientWidth = clientWidth;
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
D3D_FEATURE_LEVEL featureLevel;
ID3D11Texture2D* pBackBuffer;
IDXGIFactory* pFactory;
IDXGIAdapter* pAdapter;
IDXGIOutput* pAdapterOutput;
D3D11_VIEWPORT viewport;
DXGI_MODE_DESC* pDisplayModeList;
DXGI_ADAPTER_DESC adapterDesc;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
D3D11_TEXTURE2D_DESC depthBufferDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDisabledDesc;
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D11_RASTERIZER_DESC rasterDesc;
D3D11_BLEND_DESC blendDesc;
UINT nAdapterModes = 0;
int RRNumerator = 0, RRDenominator = 1;
if(FAILED(CreateDXGIFactory(__uuidof(IDXGIFactory),(void**)&pFactory))){return false;}
if(FAILED(pFactory->EnumAdapters(0,&pAdapter))){return false;}
if(FAILED(pAdapter->EnumOutputs(0,&pAdapterOutput))){return false;}
if(FAILED(pAdapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED, &nAdapterModes, NULL))){return false;}
pDisplayModeList = new DXGI_MODE_DESC[nAdapterModes];
if(!pDisplayModeList){ return false; }
if(FAILED(pAdapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED, &nAdapterModes, pDisplayModeList ))){return false;}
if(m_vsync)
{
for(UINT i = 0; i < nAdapterModes; i++)
{
if( pDisplayModeList[i].Width == screenWidth &&
pDisplayModeList[i].Height == screenHeight )
{
RRNumerator = pDisplayModeList[i].RefreshRate.Numerator;
RRDenominator = pDisplayModeList[i].RefreshRate.Denominator;
break;
}
}
}
if(FAILED(pAdapter->GetDesc(&adapterDesc))){return false;}
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024 );
if(wcstombs_s(NULL, m_videoCardDesc,128,adapterDesc.Description,128) != 0){return false;}
MEMORY::DX::SafeRelease(pAdapterOutput);
MEMORY::DX::SafeRelease(pAdapter);
MEMORY::DX::SafeRelease(pFactory);
ZeroMemory(&swapChainDesc,sizeof(swapChainDesc));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.Flags = 0;
swapChainDesc.Windowed = true;
swapChainDesc.OutputWindow = hWnd;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.Height = clientHeight;
swapChainDesc.BufferDesc.Width = clientWidth;
swapChainDesc.BufferDesc.RefreshRate.Denominator = RRDenominator;
swapChainDesc.BufferDesc.RefreshRate.Numerator = RRNumerator;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
featureLevel = D3D_FEATURE_LEVEL_11_0;
UINT flags = 0;
#ifdef _DEBUG
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
if(FAILED(D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE,NULL, flags,&featureLevel,1,
D3D11_SDK_VERSION,&swapChainDesc,&m_pSwapChain,
&m_device.pDevice,NULL,&m_device.pDeviceContext))) {return false;}
if(FAILED(m_pSwapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),(void**)&pBackBuffer))){return false;}
if(FAILED(m_device.pDevice->CreateRenderTargetView(pBackBuffer, NULL, &m_pRenderTargetView))){return false;}
MEMORY::DX::SafeRelease(pBackBuffer);
ZeroMemory(&depthBufferDesc,sizeof(D3D11_TEXTURE2D_DESC));
depthBufferDesc.ArraySize = 1;
depthBufferDesc.MipLevels = 1;
//.........这里部分代码省略.........