本文整理汇总了C++中IDXGIFactory1::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ IDXGIFactory1::Release方法的具体用法?C++ IDXGIFactory1::Release怎么用?C++ IDXGIFactory1::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDXGIFactory1
的用法示例。
在下文中一共展示了IDXGIFactory1::Release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool CDuplicateOutputDx11::GetSpecificAdapter(int idAdapter, IDXGIAdapter** pAdapter)
{
HRESULT err = S_OK;
if (!pAdapter)
{
return false;
}
REFIID iidVal = __uuidof(IDXGIFactory1);
UINT adapterID = 0; // adapter index
IDXGIFactory1* pFactory = NULL;
if (FAILED(err = CreateDXGIFactory1(iidVal, (void**)&pFactory)))
{
return false;
}
UINT i = 0;
UINT adapterDeviceID = idAdapter; // if device id equal zero, use the first device
DXGI_ADAPTER_DESC dxgiDesc;
IDXGIAdapter1 *giAdapter = NULL;
if (pFactory->EnumAdapters1(i, &giAdapter) != S_OK)
{
return false;
}
if (pFactory)pFactory->Release();
*pAdapter = giAdapter;
return true;
}
示例2: init
void DesktopDuplication::init()
{
IDXGIFactory1* dxgiFactory = nullptr;
CHECKED(hr, CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory)));
IDXGIAdapter1* dxgiAdapter = nullptr;
CHECKED(hr, dxgiFactory->EnumAdapters1(adapter, &dxgiAdapter));
dxgiFactory->Release();
CHECKED(hr, D3D11CreateDevice(dxgiAdapter,
D3D_DRIVER_TYPE_UNKNOWN,
NULL,
NULL,
NULL,
NULL,
D3D11_SDK_VERSION,
&d3dDevice,
NULL,
&d3dContext));
IDXGIOutput* dxgiOutput = nullptr;
CHECKED(hr, dxgiAdapter->EnumOutputs(output, &dxgiOutput));
dxgiAdapter->Release();
IDXGIOutput1* dxgiOutput1 = nullptr;
CHECKED(hr, dxgiOutput->QueryInterface(__uuidof(dxgiOutput1), reinterpret_cast<void**>(&dxgiOutput1)));
dxgiOutput->Release();
IDXGIDevice* dxgiDevice = nullptr;
CHECKED(hr, d3dDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice)));
CHECKED(hr, dxgiOutput1->DuplicateOutput(dxgiDevice, &outputDuplication));
dxgiOutput1->Release();
dxgiDevice->Release();
}
示例3: 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));
}
}
giOutput->Release();
}
}
}
else
AppWarning(TEXT("Could not query adapter %u"), i);
giAdapter->Release();
}
factory->Release();
}
}
示例4: PrepareDXGI
/// This function is called by the Mumble client in Mumble's scope
/// mainly to extract the offsets of various functions in the IDXGISwapChain
/// and IDXGIObject interfaces that need to be hooked in target
/// applications. The data is stored in the dxgi shared memory structure.
extern "C" __declspec(dllexport) void __cdecl PrepareDXGI() {
if (! dxgi)
return;
ods("DXGI: Preparing static data for DXGI Injection");
dxgi->wcFileName[0] = 0;
dxgi->offsetPresent = 0;
dxgi->offsetResize = 0;
// Make sure this is Vista or greater as quite a number of <=WinXP users have fake DX10 libs installed
OSVERSIONINFOEXW ovi;
memset(&ovi, 0, sizeof(ovi));
ovi.dwOSVersionInfoSize = sizeof(ovi);
GetVersionExW(reinterpret_cast<OSVERSIONINFOW *>(&ovi));
if (ovi.dwMajorVersion < 6 || (ovi.dwMajorVersion == 6 && ovi.dwBuildNumber < 6001)) {
ods("DXGI: No DXGI pre-Vista - skipping prepare");
return;
}
HMODULE hDXGI = LoadLibrary("DXGI.DLL");
if (hDXGI != NULL) {
GetModuleFileNameW(hDXGI, dxgi->wcFileName, ARRAY_NUM_ELEMENTS(dxgi->wcFileName));
CreateDXGIFactory1Type pCreateDXGIFactory1 = reinterpret_cast<CreateDXGIFactory1Type>(GetProcAddress(hDXGI, "CreateDXGIFactory1"));
ods("DXGI: Got CreateDXGIFactory1 at %p", pCreateDXGIFactory1);
if (pCreateDXGIFactory1) {
IDXGIFactory1 * pFactory;
HRESULT hr = pCreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&pFactory));
if (FAILED(hr))
ods("DXGI: Call to pCreateDXGIFactory1 failed!");
if (pFactory) {
IDXGIAdapter1 *pAdapter = NULL;
pFactory->EnumAdapters1(0, &pAdapter);
/// Offsets have to be identified and initialized only once.
bool initializeDXGIData = !dxgi->offsetPresent && !dxgi->offsetResize;
PrepareDXGI10(pAdapter, initializeDXGIData);
initializeDXGIData = !dxgi->offsetPresent && !dxgi->offsetResize;
PrepareDXGI11(pAdapter, initializeDXGIData);
pFactory->Release();
} else {
FreeLibrary(hDXGI);
}
} else {
FreeLibrary(hDXGI);
}
} else {
FreeLibrary(hDXGI);
}
}
示例5: LogVideoCardStats
void LogVideoCardStats()
{
HRESULT err;
#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)
{
DXGI_ADAPTER_DESC adapterDesc;
if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc)))
{
if (!(adapterDesc.VendorId == 0x1414 && adapterDesc.DeviceId == 0x8c)) { // Ignore Microsoft Basic Render Driver
Log(TEXT("------------------------------------------"));
Log(TEXT("Adapter %u"), i);
Log(TEXT(" Video Adapter: %s"), adapterDesc.Description);
Log(TEXT(" Video Adapter Dedicated Video Memory: %u"), adapterDesc.DedicatedVideoMemory);
Log(TEXT(" Video Adapter Shared System Memory: %u"), adapterDesc.SharedSystemMemory);
UINT j = 0;
IDXGIOutput *output;
while(SUCCEEDED(giAdapter->EnumOutputs(j++, &output)))
{
DXGI_OUTPUT_DESC desc;
if(SUCCEEDED(output->GetDesc(&desc)))
Log(TEXT(" Video Adapter Output %u: pos={%d, %d}, size={%d, %d}, attached=%s"), j,
desc.DesktopCoordinates.left, desc.DesktopCoordinates.top,
desc.DesktopCoordinates.right-desc.DesktopCoordinates.left, desc.DesktopCoordinates.bottom-desc.DesktopCoordinates.top,
desc.AttachedToDesktop ? L"true" : L"false");
output->Release();
}
}
}
else
AppWarning(TEXT("Could not query adapter %u"), i);
giAdapter->Release();
}
factory->Release();
}
}
示例6: init
void RenderContext::init(s32 width, s32 height, s32 refresh_rate, PlatformWindow *window) {
pp = (PlatformPacket *)malloc(sizeof(PlatformPacket));
memset(pp, 0, sizeof(PlatformPacket));
DXGI_MODE_DESC buffer_desc = {0};
buffer_desc.Width = width;
buffer_desc.Height = height;
buffer_desc.RefreshRate.Numerator = refresh_rate;
buffer_desc.RefreshRate.Denominator = 1;
buffer_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
buffer_desc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
buffer_desc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED ;
SDL_SysWMinfo win32_info = {0};
SDL_GetWindowWMInfo((SDL_Window *)window->handle, &win32_info);
DXGI_SWAP_CHAIN_DESC swap_chain_desc = {0};
swap_chain_desc.BufferDesc = buffer_desc;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.BufferCount = 1; // NOTE(nathan): double buffering
swap_chain_desc.OutputWindow = win32_info.info.win.window;
swap_chain_desc.Windowed = true;
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swap_chain_desc.Flags = D3D11_CREATE_DEVICE_DEBUG; // NOTE(nathan): possible DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH
HRESULT error = D3D11CreateDeviceAndSwapChain(0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, 0, 0, D3D11_SDK_VERSION,
&swap_chain_desc, &pp->swap_chain, &pp->device, 0, &pp->device_context);
// NOTE(nathan): disable alt-enter fullscreen
IDXGIFactory1 *factory = 0;
if(SUCCEEDED(pp->swap_chain->GetParent(__uuidof(IDXGIFactory1), (void **)&factory))) {
factory->MakeWindowAssociation(win32_info.info.win.window, DXGI_MWA_NO_ALT_ENTER|DXGI_MWA_NO_PRINT_SCREEN );
factory->Release();
}
resizeBuffer(width, height);
error = pp->device->QueryInterface(IID_PPV_ARGS(&pp->debug_interface));
}
示例7: EnumerateDisplayAdapters
bool RenderCore::EnumerateDisplayAdapters(std::vector<IDXGIAdapter1 *> *dxgiAdapters)
{
IDXGIAdapter1 *pAdapter;
IDXGIFactory1 *pFactory = nullptr;
HRESULT hr;
hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory);
if (FAILED(hr)) {
return false;
}
for (UINT i = 0; pFactory->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i) {
dxgiAdapters->push_back(pAdapter);
//m_VideoAdapterList.push_back(pAdapter);
}
if (pFactory) {
pFactory->Release();
}
return true;
};
示例8: LogVideoCardStats
void LogVideoCardStats()
{
HRESULT err;
#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)
{
DXGI_ADAPTER_DESC adapterDesc;
if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc)))
{
if (adapterDesc.DedicatedVideoMemory > 0) {
Log(TEXT("------------------------------------------"));
Log(TEXT("Adapter %u"), i);
Log(TEXT(" Video Adapter: %s"), adapterDesc.Description);
Log(TEXT(" Video Adapter Dedicated Video Memory: %u"), adapterDesc.DedicatedVideoMemory);
Log(TEXT(" Video Adapter Shared System Memory: %u"), adapterDesc.SharedSystemMemory);
}
}
else
AppWarning(TEXT("Could not query adapter %u"), i);
giAdapter->Release();
}
factory->Release();
}
}
示例9: descriptionw
bool DeviceDirect3D::getAdapterHandle(std::vector<IDXGIAdapter1*>* adapters)
{
HRESULT hr;
//Create DXGI factory
IDXGIFactory1* dxgiFactory;
hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&dxgiFactory));
if(FAILED(hr))
{
LOGERROR(hr, "CreateDXGIFactory1");
return false;
}
//Get all the adapters
UINT i = 0;
IDXGIAdapter1* pAdapter = nullptr;
while(dxgiFactory->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND)
{
adapters->push_back(pAdapter);
DXGI_ADAPTER_DESC1 desc;
pAdapter->GetDesc1(&desc);
std::wstring descriptionw(desc.Description);
std::string description(descriptionw.begin(), descriptionw.end());
Logger() << "Adapter found: (" << i << ") " << description;
++i;
}
dxgiFactory->Release();
if(adapters->empty())
{
LOGFUNCERROR("Your graphics card does not appear to support DirectX 10 or later");
return false;
}
return true;
}
示例10: InitDevice
//--------------------------------------------------------------------------------------
// Create Direct3D device and swap chain
//--------------------------------------------------------------------------------------
HRESULT InitDevice()
{
HRESULT hr = S_OK;
RECT rc;
GetClientRect( g_hWnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if ( hr == E_INVALIDARG )
{
// DirectX 11.0 platforms will not recognize D3D_FEATURE_LEVEL_11_1 so we need to retry without it
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, &featureLevels[1], numFeatureLevels - 1,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
}
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
return hr;
// Obtain DXGI factory from device (since we used nullptr for pAdapter above)
IDXGIFactory1* dxgiFactory = nullptr;
{
IDXGIDevice* dxgiDevice = nullptr;
hr = g_pd3dDevice->QueryInterface( __uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice) );
if (SUCCEEDED(hr))
{
IDXGIAdapter* adapter = nullptr;
hr = dxgiDevice->GetAdapter(&adapter);
if (SUCCEEDED(hr))
{
hr = adapter->GetParent( __uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory) );
adapter->Release();
}
dxgiDevice->Release();
}
}
if (FAILED(hr))
return hr;
// Create swap chain
IDXGIFactory2* dxgiFactory2 = nullptr;
hr = dxgiFactory->QueryInterface( __uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory2) );
if ( dxgiFactory2 )
{
// DirectX 11.1 or later
hr = g_pd3dDevice->QueryInterface( __uuidof(ID3D11Device1), reinterpret_cast<void**>(&g_pd3dDevice1) );
if (SUCCEEDED(hr))
{
(void) g_pImmediateContext->QueryInterface( __uuidof(ID3D11DeviceContext1), reinterpret_cast<void**>(&g_pImmediateContext1) );
}
DXGI_SWAP_CHAIN_DESC1 sd = {};
sd.Width = width;
sd.Height = height;
sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
hr = dxgiFactory2->CreateSwapChainForHwnd( g_pd3dDevice, g_hWnd, &sd, nullptr, nullptr, &g_pSwapChain1 );
if (SUCCEEDED(hr))
{
hr = g_pSwapChain1->QueryInterface( __uuidof(IDXGISwapChain), reinterpret_cast<void**>(&g_pSwapChain) );
}
//.........这里部分代码省略.........
示例11: OSGetVersion
D3D10System::D3D10System()
{
HRESULT err;
#ifdef USE_DXGI1_2
REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1);
#else
REFIID iidVal = __uuidof(IDXGIFactory1);
#endif
UINT adapterID = GlobalConfig->GetInt(TEXT("Video"), TEXT("Adapter"), 0);
IDXGIFactory1 *factory;
if(FAILED(err = CreateDXGIFactory1(iidVal, (void**)&factory)))
CrashError(TEXT("Could not create DXGI factory"));
IDXGIAdapter1 *adapter;
if(FAILED(err = factory->EnumAdapters1(adapterID, &adapter)))
CrashError(TEXT("Could not get DXGI adapter"));
//------------------------------------------------------------------
DXGI_SWAP_CHAIN_DESC swapDesc;
zero(&swapDesc, sizeof(swapDesc));
swapDesc.BufferCount = 2;
swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
swapDesc.BufferDesc.Width = App->renderFrameWidth;
swapDesc.BufferDesc.Height = App->renderFrameHeight;
swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapDesc.Flags = 0;
swapDesc.OutputWindow = hwndRenderFrame;
swapDesc.SampleDesc.Count = 1;
swapDesc.Windowed = TRUE;
bDisableCompatibilityMode = 1;//AppConfig->GetInt(TEXT("Video"), TEXT("DisableD3DCompatibilityMode"), 1) != 0;
UINT createFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT;
if(GlobalConfig->GetInt(TEXT("General"), TEXT("UseDebugD3D")))
createFlags |= D3D10_CREATE_DEVICE_DEBUG;
D3D10_FEATURE_LEVEL1 level = bDisableCompatibilityMode ? D3D10_FEATURE_LEVEL_10_1 : D3D10_FEATURE_LEVEL_9_3;
//D3D10_CREATE_DEVICE_DEBUG
//D3D11_DRIVER_TYPE_REFERENCE, D3D11_DRIVER_TYPE_HARDWARE
err = D3D10CreateDeviceAndSwapChain1(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, createFlags, level, D3D10_1_SDK_VERSION, &swapDesc, &swap, &d3d);
if(FAILED(err))
{
bDisableCompatibilityMode = !bDisableCompatibilityMode;
level = bDisableCompatibilityMode ? D3D10_FEATURE_LEVEL_10_1 : D3D10_FEATURE_LEVEL_9_3;
err = D3D10CreateDeviceAndSwapChain1(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, createFlags, level, D3D10_1_SDK_VERSION, &swapDesc, &swap, &d3d);
}
if(FAILED(err))
CrashError(TEXT("Could not create D3D10 device and swap chain. This error can happen for one of the following reasons:\r\n\r\n1.) Your GPU is not supported (DirectX 10 support is required - many integrated laptop GPUs do not support DX10)\r\n2.) You're running Windows Vista without the \"Platform Update\"\r\n3.) Your video card drivers are out of date"));
adapter->Release();
factory->Release();
//------------------------------------------------------------------
Log(TEXT("Loading up D3D10..."));
D3D10_DEPTH_STENCIL_DESC depthDesc;
zero(&depthDesc, sizeof(depthDesc));
depthDesc.DepthEnable = FALSE;
err = d3d->CreateDepthStencilState(&depthDesc, &depthState);
if(FAILED(err))
CrashError(TEXT("Unable to create depth state"));
d3d->OMSetDepthStencilState(depthState, 0);
//------------------------------------------------------------------
D3D10_RASTERIZER_DESC rasterizerDesc;
zero(&rasterizerDesc, sizeof(rasterizerDesc));
rasterizerDesc.FillMode = D3D10_FILL_SOLID;
rasterizerDesc.CullMode = D3D10_CULL_NONE;
rasterizerDesc.FrontCounterClockwise = FALSE;
rasterizerDesc.DepthClipEnable = TRUE;
err = d3d->CreateRasterizerState(&rasterizerDesc, &rasterizerState);
if(FAILED(err))
CrashError(TEXT("Unable to create rasterizer state"));
d3d->RSSetState(rasterizerState);
//------------------------------------------------------------------
rasterizerDesc.ScissorEnable = TRUE;
err = d3d->CreateRasterizerState(&rasterizerDesc, &scissorState);
if(FAILED(err))
CrashError(TEXT("Unable to create scissor state"));
//------------------------------------------------------------------
ID3D10Texture2D *backBuffer = NULL;
err = swap->GetBuffer(0, IID_ID3D10Texture2D, (void**)&backBuffer);
if(FAILED(err))
//.........这里部分代码省略.........
示例12: main
int main() {
printf("\n\ntest_win_api_directx_research\n\n");
/* Retrieve a IDXGIFactory that can enumerate the adapters. */
IDXGIFactory1* factory = NULL;
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&factory));
if (S_OK != hr) {
printf("Error: failed to retrieve the IDXGIFactory.\n");
exit(EXIT_FAILURE);
}
/* Enumerate the adapters.*/
UINT i = 0;
IDXGIAdapter1* adapter = NULL;
std::vector<IDXGIAdapter1*> adapters; /* Needs to be Released(). */
while (DXGI_ERROR_NOT_FOUND != factory->EnumAdapters1(i, &adapter)) {
adapters.push_back(adapter);
++i;
}
/* Get some info about the adapters (GPUs). */
for (size_t i = 0; i < adapters.size(); ++i) {
DXGI_ADAPTER_DESC1 desc;
adapter = adapters[i];
hr = adapter->GetDesc1(&desc);
if (S_OK != hr) {
printf("Error: failed to get a description for the adapter: %lu\n", i);
continue;
}
wprintf(L"Adapter: %lu, description: %s\n", i, desc.Description);
}
/* Check what devices/monitors are attached to the adapters. */
UINT dx = 0;
IDXGIOutput* output = NULL;
std::vector<IDXGIOutput*> outputs; /* Needs to be Released(). */
for (size_t i = 0; i < adapters.size(); ++i) {
dx = 0;
adapter = adapters[i];
while (DXGI_ERROR_NOT_FOUND != adapter->EnumOutputs(dx, &output)) {
printf("Found monitor %d on adapter: %lu\n", dx, i);
outputs.push_back(output);
++dx;
}
}
if (0 >= outputs.size()) {
printf("Error: no outputs found (%lu).\n", outputs.size());
exit(EXIT_FAILURE);
}
/* Print some info about the monitors. */
for (size_t i = 0; i < outputs.size(); ++i) {
DXGI_OUTPUT_DESC desc;
output = outputs[i];
hr = output->GetDesc(&desc);
if (S_OK != hr) {
printf("Error: failed to retrieve a DXGI_OUTPUT_DESC for output %lu.\n", i);
continue;
}
wprintf(L"Monitor: %s, attached to desktop: %c\n", desc.DeviceName, (desc.AttachedToDesktop) ? 'y' : 'n');
}
/*
To get access to a OutputDuplication interface we need to have a
Direct3D device which handles the actuall rendering and "gpu"
stuff. According to a gamedev stackexchange it seems we can create
one w/o a HWND.
*/
ID3D11Device* d3d_device = NULL; /* Needs to be released. */
ID3D11DeviceContext* d3d_context = NULL; /* Needs to be released. */
IDXGIAdapter1* d3d_adapter = NULL;
D3D_FEATURE_LEVEL d3d_feature_level; /* The selected feature level (D3D version), selected from the Feature Levels array, which is NULL here; when it's NULL the default list is used see: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476082%28v=vs.85%29.aspx ) */
{ /* Start creating a D3D11 device */
#if 1
/*
NOTE: Apparently the D3D11CreateDevice function returns E_INVALIDARG, when
you pass a pointer to an adapter for the first parameter and use the
D3D_DRIVER_TYPE_HARDWARE. When you want to pass a valid pointer for the
adapter, you need to set the DriverType parameter (2nd) to
D3D_DRIVER_TYPE_UNKNOWN.
@todo figure out what would be the best solution; easiest to use is
//.........这里部分代码省略.........
示例13: init
bool RenderSystem::init(void* windowHandle, const InitParams& params)
{
IDXGIFactory1* factory = 0;
IDXGIOutput* output = 0;
DXGI_MODE_DESC modeDesc;
::ZeroMemory(&modeDesc, sizeof(DXGI_MODE_DESC));
modeDesc.Format = params.srgbTarget ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM;
modeDesc.Width = params.width;
modeDesc.Height = params.height;
if (SUCCEEDED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory)))
{
IDXGIAdapter1* adapter = 0;
for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i)
{
if (adapter->CheckInterfaceSupport(__uuidof(ID3D11Device), NULL))
break;
adapter->Release();
}
D3D_FEATURE_LEVEL supportedFeatureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
};
UINT flags = 0;
#if defined (_DEBUG)
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif // _DEBUG
if (adapter)
{
if (SUCCEEDED(D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, supportedFeatureLevels, _countof(supportedFeatureLevels),
D3D11_SDK_VERSION, &m_device, NULL, &m_renderContext)))
{
for (UINT i = 0; adapter->EnumOutputs(i, &output) != DXGI_ERROR_NOT_FOUND; ++i)
{
if (SUCCEEDED(output->FindClosestMatchingMode(&modeDesc, &modeDesc, m_device)))
{
// additional checks??
break;
}
output->Release();
output = 0;
}
/*if (output)
output->Release();*/
}
adapter->Release();
}
if (m_device)
{
DXGI_SWAP_CHAIN_DESC sd;
::ZeroMemory(&sd, sizeof(DXGI_SWAP_CHAIN_DESC));
sd.BufferCount = 1;
sd.BufferDesc = modeDesc;
sd.BufferUsage = D3D11_BIND_RENDER_TARGET;
sd.Flags = 0;
sd.OutputWindow = (HWND)windowHandle;
sd.SampleDesc.Quality = 0;
sd.SampleDesc.Count = 1;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Windowed = TRUE;
if (params.msaaSamples > 0)
{
UINT numLevels = 0;
if (SUCCEEDED(m_device->CheckMultisampleQualityLevels(modeDesc.Format, params.msaaSamples, &numLevels)) && numLevels > 0)
{
sd.SampleDesc.Quality = numLevels-1;
sd.SampleDesc.Count = params.msaaSamples;
}
else
{
printf("multisample quality not supported");
}
}
VALIDATE(factory->CreateSwapChain(m_device, &sd, &m_swapChain));
}
if (params.fullscreen)
{
m_isFullScreen = SUCCEEDED(m_swapChain->SetFullscreenState(TRUE, output));
}
// setup debug queue
factory->MakeWindowAssociation((HWND)windowHandle, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES);
if (output)
output->Release();
//.........这里部分代码省略.........
示例14: InitDevice
//--------------------------------------------------------------------------------------
// Create Direct3D device and swap chain
//--------------------------------------------------------------------------------------
HRESULT InitDevice()
{
HRESULT hr = S_OK;
RECT rc;
GetClientRect( g_hWnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if ( hr == E_INVALIDARG )
{
// DirectX 11.0 platforms will not recognize D3D_FEATURE_LEVEL_11_1 so we need to retry without it
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, &featureLevels[1], numFeatureLevels - 1,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
}
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
return hr;
// Obtain DXGI factory from device (since we used nullptr for pAdapter above)
IDXGIFactory1* dxgiFactory = nullptr;
{
IDXGIDevice* dxgiDevice = nullptr;
hr = g_pd3dDevice->QueryInterface( __uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice) );
if (SUCCEEDED(hr))
{
IDXGIAdapter* adapter = nullptr;
hr = dxgiDevice->GetAdapter(&adapter);
if (SUCCEEDED(hr))
{
hr = adapter->GetParent( __uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory) );
adapter->Release();
}
dxgiDevice->Release();
}
}
if (FAILED(hr))
return hr;
// Create swap chain
IDXGIFactory2* dxgiFactory2 = nullptr;
hr = dxgiFactory->QueryInterface( __uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory2) );
if ( dxgiFactory2 )
{
// DirectX 11.1 or later
hr = g_pd3dDevice->QueryInterface( __uuidof(ID3D11Device1), reinterpret_cast<void**>(&g_pd3dDevice1) );
if (SUCCEEDED(hr))
{
(void) g_pImmediateContext->QueryInterface( __uuidof(ID3D11DeviceContext1), reinterpret_cast<void**>(&g_pImmediateContext1) );
}
DXGI_SWAP_CHAIN_DESC1 sd;
ZeroMemory(&sd, sizeof(sd));
sd.Width = width;
sd.Height = height;
sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
hr = dxgiFactory2->CreateSwapChainForHwnd( g_pd3dDevice, g_hWnd, &sd, nullptr, nullptr, &g_pSwapChain1 );
if (SUCCEEDED(hr))
{
hr = g_pSwapChain1->QueryInterface( __uuidof(IDXGISwapChain), reinterpret_cast<void**>(&g_pSwapChain) );
}
//.........这里部分代码省略.........
示例15: DoD3D11Hook
bool DoD3D11Hook(ID3D11Device *device)
{
HRESULT hErr;
bD3D101Hooked = true;
HMODULE hD3D10_1 = LoadLibrary(TEXT("d3d10_1.dll"));
if(!hD3D10_1)
{
RUNONCE logOutput << "DoD3D11Hook: could not load d3d10.1" << endl;
return false;
}
HMODULE hDXGI = GetModuleHandle(TEXT("dxgi.dll"));
if(!hDXGI)
{
RUNONCE logOutput << "DoD3D11Hook: could not load dxgi" << endl;
return false;
}
CREATEDXGIFACTORY1PROC createDXGIFactory1 = (CREATEDXGIFACTORY1PROC)GetProcAddress(hDXGI, "CreateDXGIFactory1");
if(!createDXGIFactory1)
{
RUNONCE logOutput << "DoD3D11Hook: could not get address of CreateDXGIFactory1" << endl;
return false;
}
PFN_D3D10_CREATE_DEVICE1 d3d10CreateDevice1 = (PFN_D3D10_CREATE_DEVICE1)GetProcAddress(hD3D10_1, "D3D10CreateDevice1");
if(!d3d10CreateDevice1)
{
RUNONCE logOutput << "DoD3D11Hook: could not get address of D3D10CreateDevice1" << endl;
return false;
}
IDXGIFactory1 *factory;
if(FAILED(hErr = (*createDXGIFactory1)(__uuidof(IDXGIFactory1), (void**)&factory)))
{
RUNONCE logOutput << "DoD3D11Hook: CreateDXGIFactory1 failed, result = " << UINT(hErr) << endl;
return false;
}
IDXGIAdapter1 *adapter;
if(FAILED(hErr = factory->EnumAdapters1(0, &adapter)))
{
RUNONCE logOutput << "DoD3D11Hook: factory->EnumAdapters1 failed, result = " << UINT(hErr) << endl;
factory->Release();
return false;
}
if(FAILED(hErr = (*d3d10CreateDevice1)(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_10_1, D3D10_1_SDK_VERSION, &shareDevice)))
{
if(FAILED(hErr = (*d3d10CreateDevice1)(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_9_3, D3D10_1_SDK_VERSION, &shareDevice)))
{
RUNONCE logOutput << "DoD3D11Hook: device creation failed, result = " << UINT(hErr) << endl;
adapter->Release();
factory->Release();
return false;
}
}
adapter->Release();
factory->Release();
//------------------------------------------------
D3D11_TEXTURE2D_DESC texGameDesc;
ZeroMemory(&texGameDesc, sizeof(texGameDesc));
texGameDesc.Width = d3d11CaptureInfo.cx;
texGameDesc.Height = d3d11CaptureInfo.cy;
texGameDesc.MipLevels = 1;
texGameDesc.ArraySize = 1;
texGameDesc.Format = dxgiFormat;
texGameDesc.SampleDesc.Count = 1;
texGameDesc.BindFlags = D3D11_BIND_RENDER_TARGET|D3D11_BIND_SHADER_RESOURCE;
texGameDesc.Usage = D3D11_USAGE_DEFAULT;
texGameDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
ID3D11Texture2D *d3d11Tex;
if(FAILED(hErr = device->CreateTexture2D(&texGameDesc, NULL, &d3d11Tex)))
{
RUNONCE logOutput << "DoD3D11Hook: creation of intermediary texture failed, result = " << UINT(hErr) << endl;
return false;
}
if(FAILED(hErr = d3d11Tex->QueryInterface(__uuidof(ID3D11Resource), (void**)©TextureGame)))
{
RUNONCE logOutput << "DoD3D11Hook: d3d11Tex->QueryInterface(ID3D11Resource) failed, result = " << UINT(hErr) << endl;
d3d11Tex->Release();
return false;
}
IDXGIResource *res;
if(FAILED(hErr = d3d11Tex->QueryInterface(IID_IDXGIResource, (void**)&res)))
{
RUNONCE logOutput << "DoD3D11Hook: d3d11Tex->QueryInterface(IID_IDXGIResource) failed, result = " << UINT(hErr) << endl;
d3d11Tex->Release();
return false;
}
HANDLE handle;
if(FAILED(hErr = res->GetSharedHandle(&handle)))
//.........这里部分代码省略.........