本文整理汇总了C++中IDXGIOutput类的典型用法代码示例。如果您正苦于以下问题:C++ IDXGIOutput类的具体用法?C++ IDXGIOutput怎么用?C++ IDXGIOutput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDXGIOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateDXGIFactory
bool D3D10Renderer::Initialize(int screenWidth, int screenHeight)
{
HRESULT result;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, i, numerator, denominator;
numModes = 0;
i = 0;
numerator = 0;
denominator = 0;
DXGI_MODE_DESC* displayModeList;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ID3D10Texture2D* backBufferPtr;
D3D10_TEXTURE2D_DESC depthBufferDesc;
D3D10_DEPTH_STENCIL_DESC depthStencilDesc;
D3D10_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D10_VIEWPORT viewport;
float fieldOfView, screenAspect;
D3D10_RASTERIZER_DESC rasterDesc;
m_vsync_enabled = true;
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;
}
}
}
delete[] displayModeList;
displayModeList = 0;
adapterOutput->Release();
adapterOutput = 0;
adapter->Release();
adapter = 0;
factory->Release();
factory = 0;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
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;
}
else
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = m_hwnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = true;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.Flags = 0;
result = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION,
&swapChainDesc, &m_swapChain, &m_device);
if(FAILED(result))
{
return false;
}
//.........这里部分代码省略.........
示例2: GetDisplayDevices
void GetDisplayDevices(DeviceOutputs &deviceList)
{
HRESULT err;
deviceList.ClearData();
#ifdef USE_DXGI1_2
REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1);
#else
REFIIF iidVal = __uuidof(IDXGIFactory1);
#endif
IDXGIFactory1 *factory;
if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory)))
{
UINT i=0;
IDXGIAdapter1 *giAdapter;
while(factory->EnumAdapters1(i++, &giAdapter) == S_OK)
{
//Log(TEXT("------------------------------------------"));
DXGI_ADAPTER_DESC adapterDesc;
if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc)))
{
if (adapterDesc.DedicatedVideoMemory != 0) {
DeviceOutputData &deviceData = *deviceList.devices.CreateNew();
deviceData.strDevice = adapterDesc.Description;
UINT j=0;
IDXGIOutput *giOutput;
while(giAdapter->EnumOutputs(j++, &giOutput) == S_OK)
{
DXGI_OUTPUT_DESC outputDesc;
if(SUCCEEDED(giOutput->GetDesc(&outputDesc)))
{
if(outputDesc.AttachedToDesktop)
{
deviceData.monitorNameList << outputDesc.DeviceName;
MonitorInfo &monitorInfo = *deviceData.monitors.CreateNew();
monitorInfo.hMonitor = outputDesc.Monitor;
mcpy(&monitorInfo.rect, &outputDesc.DesktopCoordinates, sizeof(RECT));
switch (outputDesc.Rotation) {
case DXGI_MODE_ROTATION_ROTATE90:
monitorInfo.rotationDegrees = 90.0f;
break;
case DXGI_MODE_ROTATION_ROTATE180:
monitorInfo.rotationDegrees = 180.0f;
break;
case DXGI_MODE_ROTATION_ROTATE270:
monitorInfo.rotationDegrees = 270.0f;
}
}
}
giOutput->Release();
}
}
}
else
AppWarning(TEXT("Could not query adapter %u"), i);
giAdapter->Release();
}
factory->Release();
}
}
示例3: settings
///
///The screenWidth and screenHeight variables that are given to this function are the width and
///height of the window we created in the SystemClass. Direct3D will use these to initialize and
///use the same window dimensions. The hwnd variable is a handle to the window. Direct3D will
///need this handle to access the window previously created. The fullscreen variable is whether
///we are running in windowed mode or fullscreen. Direct3D needs this as well for creating the
///window with the correct settings. The screenDepth and screenNear variables are the depth
///settings for our 3D environment that will be rendered in the window. The vsync variable
///indicates if we want Direct3D to render according to the users monitor refresh rate or to
///just go as fast as possible.
///
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;
// Store the vsync setting.
m_vsync_enabled = vsync;
/*
Before we can initialize Direct3D we have to get the refresh rate from the video
card/monitor. Each computer may be slightly different so we will need to query
for that information. We query for the numerator and denominator values and then
pass them to DirectX during the setup and it will calculate the proper refresh rate.
If we don't do this and just set the refresh rate to a default value which may not
exist on all computers then DirectX will respond by performing a blit instead of a
buffer flip which will degrade performance and give us annoying errors in the debug
output.
*/
// 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;
}
//.........这里部分代码省略.........
示例4: 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;
ID3D10Texture2D* backBufferPtr;
D3D10_TEXTURE2D_DESC depthBufferDesc;
D3D10_DEPTH_STENCIL_DESC depthStencilDesc;
D3D10_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D10_VIEWPORT viewport;
float fieldOfView, screenAspect;
D3D10_RASTERIZER_DESC rasterDesc;
// Store the vsync setting.
m_vsync_enabled = vsync;
//z 2015-07-28 15:23 Creates a DXGI 1.0 factory that you can use to generate other DXGI objects.
// Create a DirectX graphics interface factory.
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if(FAILED(result))
{
return false;
}
//z 2015-07-28 15:23 Enumerates the adapters (video cards).
// Use the factory to create an adapter for the primary graphics interface (video card).
/*
When you create a factory, the factory enumerates the set of adapters that are available in the system. Therefore, if you change the adapters in a system, you must destroy and recreate the IDXGIFactory object. The number of adapters in a system changes when you add or remove a display card, or dock or undock a laptop.
When the EnumAdapters method succeeds and fills the ppAdapter parameter with the address of the pointer to the adapter interface, EnumAdapters increments the adapter interface's reference count. When you finish using the adapter interface, call the Release method to decrement the reference count before you destroy the pointer.
EnumAdapters first returns the adapter with the output on which the desktop primary is displayed. This adapter corresponds with an index of zero. EnumAdapters next returns other adapters with outputs. EnumAdapters finally returns adapters without outputs.
*/
//z 枚举 adapter 的例子
/*
UINT i = 0;
IDXGIAdapter * pAdapter;
std::vector <IDXGIAdapter*> vAdapters;
while(pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND)
{
vAdapters.push_back(pAdapter);
++i;
}*/
result = factory->EnumAdapters(0, &adapter);
if(FAILED(result))
{
return false;
}
//z 2015-07-28 15:29 Enumerate adapter (video card) outputs.
// Enumerating Outputs. Here is an example of how to use EnumOutputs to enumerate all the outputs on an adapter:
/* //z
UINT i = 0;
IDXGIOutput * pOutput;
std::vector<IDXGIOutput*> vOutputs;
while(pAdapter->EnumOutputs(i, &pOutput) != DXGI_ERROR_NOT_FOUND)
{
vOutputs.push_back(pOutput);
++i;
}
*/
// Enumerate the primary adapter output (monitor).
result = adapter->EnumOutputs(0, &adapterOutput);
if(FAILED(result))
{
return false;
}
//z 2015-07-28 15:31 Gets the display modes that match the requested format and other input options.
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
/*
pNumModes [in, out]
Type: UINT*
Set pDesc to NULL so that pNumModes returns the number of display modes that match the format and the options. Otherwise, pNumModes returns the number of display modes returned in pDesc.
As shown, this API is designed to be called twice. First to get the number of modes available, and second to return a description of the modes.
//z 2015-07-28 15:34 例子
UINT num = 0;
DXGI_FORMAT format = DXGI_FORMAT_R32G32B32A32_FLOAT;
UINT flags = DXGI_ENUM_MODES_INTERLACED;
pOutput->GetDisplayModeList( format, flags, &num, 0);
...
DXGI_MODE_DESC * pDescs = new DXGI_MODE_DESC[num];
pOutput->GetDisplayModeList( format, flags, &num, pDescs);
*/
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
//.........这里部分代码省略.........
示例5: CreateDXGIFactory
bool DX11Render::Initialize(int screenWidth, int screenHeight, bool fullscreen, HWND hwnd)
{
HRESULT result;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, 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;
m_vsync_enabled = VSYNC_ENABLED;
//Dx Graphics interface factory
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if(FAILED(result))
return false;
//Factory is used to create adapter
result = factory->EnumAdapters(0, &adapter);
if(FAILED(result))
return false;
//Enumerate the adapter output (monitor)
result = adapter->EnumOutputs(0, &adapterOutput);
if(FAILED(result))
return false;
//Get # modes that fit format
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if(FAILED(result))
return false;
//create list for display modes
displayModeList = new DXGI_MODE_DESC[numModes];
if(!displayModeList)
return false;
//fill mode list
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if(FAILED(result))
return false;
//go through list and find one that matches current monitor settings
for(unsigned int 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 adapter desc.
result = adapter->GetDesc(&adapterDesc);
if(FAILED(result))
return false;
//Get MB of video card
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
//Convert Video Card desc to char array
error = wcstombs_s(&stringLength, m_videoCardDescription, 128,
adapterDesc.Description, 128);
if(error != 0)
return false;
//release video card data
delete [] displayModeList;
displayModeList = 0; //Not needed, will go out of scope right after?
adapterOutput->Release();
adapterOutput = 0; //Not needed, will go out of scope right after?
adapter->Release();
adapter = 0; //Not needed, will go out of scope right after?
factory->Release();
factory = 0; //Not needed, will go out of scope right after?
//init swap chain
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
//.........这里部分代码省略.........
示例6: 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;
D3D11_BLEND_DESC blendStateDescription;
m_vsync_enabled = vsync; //Store the vsync setting
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); //creating a directx graphics interface factory, sends in the GUID of "IDXGIFactory" and a reference to our factory which is a pointer to an IDXGIFactory, but type casted as a pointer to a void pointer
if(FAILED(result))
{
return false;
}
result = factory->EnumAdapters(0, &adapter); //put an adapter for our video card into "adapter"
if(FAILED(result))
{
return false;
}
result = adapter->EnumOutputs(0, &adapterOutput); //enumerate the primary adapter output (monitor).
if(FAILED(result))
{
return false;
}
result = adapterOutput->GetDisplayModeList( //get the number of modes that fit this display format for the monitor
DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_INTERLACED,
&numModes,
NULL
);
if(FAILED(result))
{
return false;
}
displayModeList = new DXGI_MODE_DESC[numModes]; //create an array of DXGI_MODE_DESC with the length of the number of compatible modes available
if(!displayModeList)
{
return false;
}
result = adapterOutput->GetDisplayModeList( //now actually fill that displayModeList with all those display modes
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;
}
}
}
result = adapter->GetDesc(&adapterDesc); //get the video card description
if(FAILED(result))
{
return false;
}
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024); //get the amount of video memory in bytes, devide by 1024 twice to get in megabytes
error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128); //convert the name of the video card to a character array and store it
//.........这里部分代码省略.........
示例7: 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;
unsigned long long 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;
m_vsync_enabled = vsync;
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
//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_R8G8BA8_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 video/monitor card combination
displayModeList = new DXGI_MODE_DESC[numModes];
if (!displayModeList)
{
return false;
}
//fill the display mode list
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if (FAILED(result))
{
return false;
}
//go through all display modes and find the one that matches width and height
for (int 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 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);
//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;
}
//.........这里部分代码省略.........
示例8: GetClientRect
bool xGL2RenderApi::__createD10Device()
{
HRESULT hr = S_OK;;
UINT width = m_Width;
UINT height = m_Height;
if(width == 0 || height == 0)
{
RECT rc;
GetClientRect( m_hMainWnd, &rc );
width = rc.right - rc.left;
height = rc.bottom - rc.top;
m_Width = width;
m_Height = height;
}
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= GL2_CREATE_DEVICE_DEBUG;
#endif
GL2_DRIVER_TYPE driverTypes[] =
{
GL2_DRIVER_TYPE_HARDWARE,
GL2_DRIVER_TYPE_REFERENCE,
GL2_DRIVER_TYPE_REFERENCE,
GL2_DRIVER_TYPE_REFERENCE,
GL2_DRIVER_TYPE_REFERENCE,
GL2_DRIVER_TYPE_REFERENCE,
};
HMODULE hDriverModule[]=
{
NULL,
LoadLibraryA( "GL2WARP_beta.DLL" ),
LoadLibraryW( _XEVOL_ABSPATH_(L"GL2WARP_beta.DLL") ),
LoadLibraryA( "GL2WARP.DLL" ),
LoadLibraryW( _XEVOL_ABSPATH_(L"GL2WARP.DLL" ) ),
NULL,
};
UINT numDriverTypes = sizeof(driverTypes) / sizeof(driverTypes[0]);
m_Width = width;
m_Height = height;
ZeroMemory( &m_swapChainDesc, sizeof(m_swapChainDesc) );
m_swapChainDesc.BufferCount = 1;
m_swapChainDesc.BufferDesc.Width = width;
m_swapChainDesc.BufferDesc.Height = height;
m_swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
m_swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
m_swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
m_swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
m_swapChainDesc.OutputWindow = m_hMainWnd;
m_swapChainDesc.SampleDesc.Count = 1;
m_swapChainDesc.SampleDesc.Quality = 0;
m_swapChainDesc.Windowed = TRUE;
//Find all Adapter
IDXGIAdapter * pAdapter;
std::vector<IDXGIAdapter*> vAdapters;
IDXGIFactory* pDXGIFactory = NULL;
hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pDXGIFactory) );
while(pDXGIFactory->EnumAdapters(vAdapters.size(), &pAdapter) != DXGI_ERROR_NOT_FOUND)
{
vAdapters.push_back(pAdapter);
}
for(int i = 0 ; i < vAdapters.size() ; i ++)
{
IDXGIAdapter* pAdapter = vAdapters[i];
DXGI_ADAPTER_DESC desc;
pAdapter->GetDesc(&desc);
std::vector<IDXGIOutput*> vOutputers;
IDXGIOutput* pOutputer = NULL;
while(pAdapter->EnumOutputs(vOutputers.size(), &pOutputer) != DXGI_ERROR_NOT_FOUND)
{
vOutputers.push_back(pOutputer);
DXGI_OUTPUT_DESC odesc;
pOutputer->GetDesc(&odesc);
continue;
}
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
m_driverType = driverTypes[driverTypeIndex];
HMODULE hModule = hDriverModule[driverTypeIndex];
hr = GL2CreateDeviceAndSwapChain( pAdapter, m_driverType, hModule , createDeviceFlags, GL2_SDK_VERSION, &m_swapChainDesc, &m_pSwapChain, &m_pGL2Device );
if( SUCCEEDED( hr ) )
break;
}
if(m_pGL2Device && m_pSwapChain)
{
break;
}
}
//.........这里部分代码省略.........
示例9: CreateDXGIFactory
bool D3DClass::Initilize(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;
unsigned long long 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;
m_vsync_enabled = vsync;
//Create DirectX Factory
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result))
{
return false;
}
//use factory to create adapter
result = factory->EnumAdapters(0, &adapter);
if (FAILED(result))
{
return false;
}
//enumerate adapter output (monitor)
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;
}
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
unsigned int charSize = 128;
//error = wcstombs_s(&stringLength, m_videoCardDescription, charSize, adapterDesc.Description, charSize);
//error = wcstombs(m_videoCardDescription, adapterDesc.Description, 128); // check to see if this works
// THIS IS EXPERIMENTAL! FIND A BETTER WAY OR FULLY TEST THIS!
for (int d = 0; d < 128; d++)
{
m_videoCardDescription[d] = adapterDesc.Description[d];
}
if (!m_videoCardDescription)
{
return false;
}
delete[] displayModeList;
//.........这里部分代码省略.........
示例10: 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);
//.........这里部分代码省略.........
示例11: if
///////////////////////////////////////////////////////////////
// Public Functions
///////////////////////////////////////////////////////////////
bool DX11System::Initialize(UINT screenWidth, UINT screenHeight, HWND hWnd)
{
LogManager::GetInstance().Trace("DX11System initializing...");
HRESULT result;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
UINT numModes=0,
i=0,
numerator=0,
denominator=0,
stringLength=0;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
int error=0;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
D3D_FEATURE_LEVEL featureLevel;
ID3D11Texture2D* backBufferPtr;
D3D11_TEXTURE2D_DESC depthBufferDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilState;
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D11_RASTERIZER_DESC rasterDesc;
D3D11_VIEWPORT viewport;
float fieldOfView=0.f, screenAspect=0.f;
D3D11_BLEND_DESC blendStateDesc;
m_vsync = Settings::GetInstance().GetVSync();
//Create a DirectX Graphics Interface (DXGI) factory
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if(FAILED(result))
{
LogManager::GetInstance().Error("DX11System::Initialize DXGIFactory could not be created");
return false;
}
//Create an adapter for the primary video card
result = factory->EnumAdapters(0, &adapter);
if(FAILED(result))
{
LogManager::GetInstance().Error("DX11System::Initialize could not create the primary display adapter");
return false;
}
//Enumerate the primary adapter output
result = adapter->EnumOutputs(0, &adapterOutput);
if(FAILED(result))
{
LogManager::GetInstance().Error("DX11System::Initialize could not enumerate the primary adapter outputs");
return false;
}
//Get the number of modes supported in this format
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, nullptr);
if(FAILED(result))
{
LogManager::GetInstance().Error("DX11System::Initialize could not get the number of supported display modes");
return false;
}
//Create a list to hold all the possible display modes that fit for this video card / monitor
displayModeList = new DXGI_MODE_DESC[numModes];
if(!displayModeList)
{
LogManager::GetInstance().Error("DX11System::Initialize displayModeList could not be initialized");
return false;
}
//fill the list
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if(FAILED(result))
{
LogManager::GetInstance().Error("DX11System::Initialize could not fill the displayModeList");
return false;
}
//Go through every possible mode that fit our window
//Set the refresh rate accordingly
for(i = 0; i < numModes; i++)
{
if(displayModeList[i].Width == (UINT)screenWidth)
{
if(displayModeList[i].Height == (UINT)screenHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
//Get the video card description
result = adapter->GetDesc(&adapterDesc);
if(FAILED(result))
{
LogManager::GetInstance().Error("DX11System::Initialize could not obtain the video card description");
//.........这里部分代码省略.........
示例12: wireframe_enabled_
D3D::D3D(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear) :
wireframe_enabled_(false)
{
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, i, numerator, denominator, stringLength;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
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;
float fieldOfView, screenAspect;
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
D3D11_BLEND_DESC blendStateDescription;
// Store the vsync setting.
m_vsync_enabled = vsync;
// Create a DirectX graphics interface factory.
CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
// Use the factory to create an adapter for the primary graphics interface (video card).
factory->EnumAdapters(0, &adapter);
// Enumerate the primary adapter output (monitor).
adapter->EnumOutputs(0, &adapterOutput);
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
// Create a list to hold all the possible display modes for this monitor/video card combination.
displayModeList = new DXGI_MODE_DESC[numModes];
// Now fill the display mode list structures.
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.
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.
adapter->GetDesc(&adapterDesc);
// Store the dedicated video card memory in megabytes.
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
// Convert the name of the video card to a character array and store it.
wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
// Release the display mode list.
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;
// 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
//.........这里部分代码省略.........
示例13: WinMain
//.........这里部分代码省略.........
-0.5f, +0.5f, +0.5f, 0, 0, 1, 1,
-0.5f, +0.5f, -0.5f, 0, 0, 1, 1,
-0.5f, -0.5f, +0.5f, 0, 0, 1, 1,
// ld
-0.5f, -0.5f, +0.5f, 0, 0, 1, 1,
-0.5f, +0.5f, -0.5f, 0, 0, 1, 1,
-0.5f, -0.5f, -0.5f, 0, 0, 1, 1,
// ru
+0.5f, +0.5f, -0.5f, 0, 0, 1, 1,
+0.5f, +0.5f, +0.5f, 0, 0, 1, 1,
+0.5f, -0.5f, -0.5f, 0, 0, 1, 1,
// rd
+0.5f, -0.5f, -0.5f, 0, 0, 1, 1,
+0.5f, +0.5f, +0.5f, 0, 0, 1, 1,
+0.5f, -0.5f, +0.5f, 0, 0, 1, 1,
};
auto vertex_buffer = new VertexBuffer(device, vertexes, sizeof(vertexes), sizeof(float) * 7);
// ビューポート設定
D3D11_VIEWPORT view_port;
view_port.Width = static_cast<float>(1440);
view_port.Height = static_cast<float>(900);
view_port.MinDepth = 0.f;
view_port.MaxDepth = 1.f;
view_port.TopLeftX = 0.f;
view_port.TopLeftY = 0.f;
context->RSSetViewports(1, &view_port);
auto adapter = my_dxgi->GetAdapter();
IDXGIOutput* output;
adapter->EnumOutputs(0, &output);
//left_swap_chain->ResizeBuffer(output);
//left_swap_chain->SetOutput(output, true);
//left_swap_chain->ResizeBuffer(output, true);
output->Release();
struct ConstantBuffer {
Matrix world;
Matrix view;
Matrix projection;
};
ConstantBuffer constant_buffer_data;
D3D11_BUFFER_DESC constant_buffer_desc = { 0 };
constant_buffer_desc.ByteWidth = sizeof(constant_buffer_data);
constant_buffer_desc.Usage = D3D11_USAGE_DEFAULT;
constant_buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constant_buffer_desc.CPUAccessFlags = 0;
constant_buffer_desc.MiscFlags = 0;
constant_buffer_desc.StructureByteStride = sizeof(float);
ID3D11Buffer* constant_buffer;
HRESULT ret;
ret = device->CreateBuffer(&constant_buffer_desc, nullptr, &constant_buffer);
_ASSERT_EXPR(SUCCEEDED(ret), L"コンスタントバッファ作成失敗");
float ff = 0;
FrameKeeper fk(60, [&]{
left_swap_chain->Clear(context);
left_swap_chain->SetRenderTarget(context);
示例14: 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;
// Store the vsync setting.
m_vsync_enabled = vsync;
// Create a DX graphics interface factory
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result))
{
return false;
}
// Adapter for the primary graphics interface (video card)
result = factory->EnumAdapters(0, &adapter);
if (FAILED(result))
{
return false;
}
// 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
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;
}
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
if (error != 0)
{
return false;
}
// Release the display mode list.
delete[] displayModeList;
displayModeList = 0;
//.........这里部分代码省略.........
示例15: FullSetup
bool StereoRenderer::FullSetup(int screenWidth, int screenHeight, 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;
// 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;
}
// Release the display mode list.
delete [] displayModeList;
displayModeList = 0;
// Release the adapter output.
adapterOutput->Release();
adapterOutput = 0;
// Release the adapter.
adapter->Release();
adapter = 0;
// Release the factory.
factory->Release();
//.........这里部分代码省略.........