当前位置: 首页>>代码示例>>C++>>正文


C++ IDXGIAdapter1类代码示例

本文整理汇总了C++中IDXGIAdapter1的典型用法代码示例。如果您正苦于以下问题:C++ IDXGIAdapter1类的具体用法?C++ IDXGIAdapter1怎么用?C++ IDXGIAdapter1使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IDXGIAdapter1类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetHardwareAdapter

	// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
	// If no such adapter can be found, *ppAdapter will be set to nullptr.
	void Renderer::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
	{
		IDXGIAdapter1* pAdapter = nullptr;
		*ppAdapter = nullptr;

		for(UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
		{
			DXGI_ADAPTER_DESC1 desc;
			pAdapter->GetDesc1(&desc);

			if(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
			{
				// Don't select the Basic Render Driver adapter.
				// If you want a software adapter, pass in "/warp" on the command line.
				continue;
			}

			// Check to see if the adapter supports Direct3D 12, but don't create the
			// actual device yet.
			if(SUCCEEDED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_12_1, _uuidof(ID3D12Device), nullptr)))
			{
				break;
			}
		}

		*ppAdapter = pAdapter;
	}
开发者ID:Slin,项目名称:leapBoxing,代码行数:29,代码来源:LBRenderer.cpp

示例2: CHECKED

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();
}
开发者ID:filinger,项目名称:blitzle,代码行数:35,代码来源:DesktopDuplication.cpp

示例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();
    }
}
开发者ID:Soopah,项目名称:OBS,代码行数:59,代码来源:D3D10System.cpp

示例4: 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();
    }
}
开发者ID:neilzar,项目名称:OBS,代码行数:51,代码来源:D3D10System.cpp

示例5: modes

	void	D3D11Renderer::EnumerateDisplayModes()
	{
		IDXGIFactory1	*factory = 0;

		if (CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)&factory) == S_OK)
		{
			IDXGIAdapter1	*adapter = 0;
			for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++)
			{
				DXGI_ADAPTER_DESC1 ad;
				adapter->GetDesc1(&ad);

				char description[128];
				size_t n;
				wcstombs_s(&n, description, ad.Description, 128);

				ATOM_LOG("-------------------------------------------------------------------------------\n");
				ATOM_LOG("[info]: adapter[%d]: %s\n", i, description);
				ATOM_LOG("[info]: - revision: %d\n", i, ad.Revision);
				ATOM_LOG("[info]: - video memory: %d\n", i, ad.DedicatedVideoMemory / 1024 / 1024);
				ATOM_LOG("[info]: - system memory: %d\n", i, ad.DedicatedSystemMemory / 1024 / 1024);
				ATOM_LOG("[info]: - shared system memory: %d\n", i, ad.SharedSystemMemory / 1024 / 1024);

				IDXGIOutput	*output = 0;
				for (UINT j = 0; adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND; j++)
				{
					UINT			modesCount;
					DXGI_FORMAT		format = g_settings.format;

					output->GetDisplayModeList(format, 0, &modesCount, 0);
					DXGI_MODE_DESC	*modeDescs = new DXGI_MODE_DESC[modesCount];
					output->GetDisplayModeList(format, 0, &modesCount, modeDescs);

					ATOM_LOG("[info]: - output %d display modes(%d)\n", j, modesCount);
					for (UINT k = 0; k < modesCount; k++)
					{
						ATOM_LOG("[info]: -- mode[%d]: %d * %d", k, modeDescs[k].Width, modeDescs[k].Height);
						ATOM_LOG(", refresh rate: %d/%d\n", modeDescs[i].RefreshRate.Numerator, modeDescs[i].RefreshRate.Denominator);
					}
					delete[] modeDescs;
					memory::SafeRelease(&output);
				}
				memory::SafeRelease(&adapter);
			}
		}
		memory::SafeRelease(&factory);
	}
开发者ID:dotminic,项目名称:code,代码行数:47,代码来源:D3D11Renderer.cpp

示例6:

	DXGI_RATIONAL	D3D11Renderer::GetDefaultRefreshRate()
	{
		DXGI_RATIONAL	refreshRate = {59, 1};
		IDXGIFactory1	*factory = 0;

		if (CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)&factory) == S_OK)
		{
			IDXGIAdapter1	*adapter = 0;
			for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++)
			{
				DXGI_ADAPTER_DESC1 ad;
				IDXGIOutput	*output = 0;

				adapter->GetDesc1(&ad);
				for (UINT j = 0; adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND; j++)
				{
					UINT			modesCount;
					DXGI_FORMAT		format = g_settings.format;

					output->GetDisplayModeList(format, 0, &modesCount, 0);
					DXGI_MODE_DESC	*modeDescs = new DXGI_MODE_DESC[modesCount];
					output->GetDisplayModeList(format, 0, &modesCount, modeDescs);
					for (UINT k = 0; k < modesCount; k++)
					{
						if (modeDescs[k].Width == (UINT)g_settings.width &&
							modeDescs[k].Height == (UINT)g_settings.height)
						{
							refreshRate = modeDescs[i].RefreshRate;
							delete[] modeDescs;
							memory::SafeRelease(&output);
							memory::SafeRelease(&adapter);
							memory::SafeRelease(&factory);
							return refreshRate;
						}
					}
					delete[] modeDescs;
					memory::SafeRelease(&output);
				}
				memory::SafeRelease(&adapter);
			}
		}
		memory::SafeRelease(&factory);
		return refreshRate;
	}
开发者ID:dotminic,项目名称:code,代码行数:44,代码来源:D3D11Renderer.cpp

示例7: FindAdapter

bool CRenderer::FindAdapter(IDXGIFactory1** factory, IDXGIAdapter1** adapter)
{
	HRESULT hr = S_OK;
	IDXGIAdapter1 * pCurrentAdapter = nullptr;
	DXGI_ADAPTER_DESC1 Bestdesc;
	if (!factory) {
		Log("Cannot send in a NULL factory");
		return false;
	}
	if (!adapter) {
		Log("Cannot send in a NULL adapter");
		return false;
	}

	// Create a factory to enumerate all of the hardware in the system.
	DXCall(hr = CreateDXGIFactory1(__uuidof(IDXGIFactory), reinterpret_cast<void**>(factory)));

#pragma warning(suppress: 6102)
	if (!*factory) {
		Log("Could not create the factory");
		return false;
	}
	unsigned int index = 0;
	while (DXGI_ERROR_NOT_FOUND != (*factory)->EnumAdapters1(index++, &pCurrentAdapter)) {
		DXGI_ADAPTER_DESC1 desc;
		ZeroMemory(&desc, sizeof(desc));
		DXCall(pCurrentAdapter->GetDesc1(&desc));
		if (nullptr == *adapter) {
			*adapter = pCurrentAdapter;
			Bestdesc = desc;
		}
		else if (Bestdesc.DedicatedSystemMemory < desc.DedicatedSystemMemory) {
			(*adapter)->Release();
			*adapter = pCurrentAdapter;
			Bestdesc = desc;
		}
		else {
			pCurrentAdapter->Release();
		}
	}
	return true;
}
开发者ID:JPStank,项目名称:ParticleEditor,代码行数:42,代码来源:Renderer.cpp

示例8: wcscmp

	//-----------------------------------------------------------------------
	BOOL D3D11DriverList::enumerate(IDXGIFactory1*	pDXGIFactory)
	{
		LogManager::getSingleton().logMessage( "D3D11: Driver Detection Starts" );
		// Create the DXGI Factory

		for( UINT iAdapter=0; ; iAdapter++ )
		{
			IDXGIAdapter1*					pDXGIAdapter;
			HRESULT hr = pDXGIFactory->EnumAdapters1( iAdapter, &pDXGIAdapter );
			if( DXGI_ERROR_NOT_FOUND == hr )
			{
				hr = S_OK;
				break;
			}
			if( FAILED(hr) )
			{
				delete pDXGIAdapter;
				return false;
			}

			// we don't want NVIDIA PerfHUD in the list - so - here we filter it out
			DXGI_ADAPTER_DESC1 adaptDesc;
			if ( SUCCEEDED( pDXGIAdapter->GetDesc1( &adaptDesc ) ) )
			{
				const bool isPerfHUD = wcscmp( adaptDesc.Description, L"NVIDIA PerfHUD" ) == 0;

				if (isPerfHUD)
				{
					continue;
				}
			}

			D3D11Device dev;
			mDriverList.push_back(new D3D11Driver( dev,  iAdapter,pDXGIAdapter) );

		}

		LogManager::getSingleton().logMessage( "D3D11: Driver Detection Ends" );

		return TRUE;
	}
开发者ID:MrLobo,项目名称:El-Rayo-de-Zeus,代码行数:42,代码来源:OgreD3D11DriverList.cpp

示例9: CreateDXGIFactory1

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;
}
开发者ID:MadrMan,项目名称:gpgpuraytrace,代码行数:38,代码来源:DeviceDirect3D.cpp

示例10: 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();
    }
}
开发者ID:Soopah,项目名称:OBS,代码行数:38,代码来源:D3D10System.cpp

示例11: EnumAllDeviceAdapter

void EnumAllDeviceAdapter(rhi::IDeviceAdapter ** & adapterList, uint32 * num)
{
	PtrGIFactory factory;
	HRESULT hr = ::CreateDXGIFactory1(IID_PPV_ARGS(factory.GetAddressOf()));
	K3D_ASSERT(hr == S_OK, "create dx factory failed.");
	vector<IDXGIAdapter1*> adapters;
	IDXGIAdapter1* pAdapter = nullptr;
	for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != factory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex) {
		DXGI_ADAPTER_DESC1 desc;
		pAdapter->GetDesc1(&desc);
		if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
			continue;
		}
		if (SUCCEEDED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device), nullptr))) {
			adapters.push_back(pAdapter);
		}
	}

	*num = (uint32)adapters.size();
	if (adapters.empty())
	{
		return;
	}

	adapterList = new rhi::IDeviceAdapter*[adapters.size()];
	for (uint32 index = 0; index < adapters.size(); index++)
	{
		DXGI_ADAPTER_DESC1 desc;
		adapters[index]->GetDesc1(&desc);
		GpuVendor vendor = MapIdToVendor(desc.VendorId);
		char VendorName[256] = { 0 };
		StringUtil::WCharToChar(desc.Description, VendorName, 256);
		DX12LOG(Info, "Device", "Vendor is %s, Id is %d.", VendorName, desc.VendorId);
		adapterList[index] = new DeviceAdapter(adapters[index], vendor);
	}
};
开发者ID:aonorin,项目名称:kaleido3d,代码行数:36,代码来源:D3D12Device.cpp

示例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 
//.........这里部分代码省略.........
开发者ID:OriginalQverty,项目名称:screen_capture,代码行数:101,代码来源:test_win_api_directx_research.cpp

示例13: ZeroMemory

bool D3DApp::InitializeD3D()
{
	// describe our SwapChain Buffer
	DXGI_MODE_DESC mode_desc;
	ZeroMemory(&mode_desc, sizeof(DXGI_MODE_DESC));
	mode_desc.Width = m_width;
	mode_desc.Height = m_height;
	mode_desc.RefreshRate.Numerator = 60;
	mode_desc.RefreshRate.Denominator = 1;
	mode_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	mode_desc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	mode_desc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

	// describe our SwapChain
	DXGI_SWAP_CHAIN_DESC swapchain_desc; 
	ZeroMemory(&swapchain_desc, sizeof(DXGI_SWAP_CHAIN_DESC));
	swapchain_desc.BufferDesc = mode_desc;
	swapchain_desc.SampleDesc.Count = 1;
	swapchain_desc.SampleDesc.Quality = 0;
	swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapchain_desc.BufferCount = 1;
	swapchain_desc.OutputWindow = m_hwnd; 
	swapchain_desc.Windowed = TRUE;
	swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

	// create DXGI factory to enumerate adapters
	IDXGIFactory1 *dxgi_factory;
	HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&dxgi_factory);	

	// use the first adapter	
	IDXGIAdapter1 *adapter;
	hr = dxgi_factory->EnumAdapters1(0, &adapter);
	dxgi_factory->Release();

	// create our Direct3D 11 Device and SwapChain
	hr = D3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, D3D11_CREATE_DEVICE_BGRA_SUPPORT,
		NULL, NULL,	D3D11_SDK_VERSION, &swapchain_desc, &m_swap_chain, &m_d3d11_device, NULL, &m_d3d11_device_context);

	// initialize Direct2D, Direct3D 10.1, DirectWrite
	InitializeDWrite(adapter);

	// release the Adapter interface
	adapter->Release();

	// create our BackBuffer and Render Target
	hr = m_swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&m_back_buffer);
	hr = m_d3d11_device->CreateRenderTargetView(m_back_buffer, NULL, &m_back_buffer_rtv);

	// describe our Depth/Stencil Buffer
	D3D11_TEXTURE2D_DESC depthstencil_desc;
	depthstencil_desc.Width     = m_width;
	depthstencil_desc.Height    = m_height;
	depthstencil_desc.MipLevels = 1;
	depthstencil_desc.ArraySize = 1;
	depthstencil_desc.Format    = DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthstencil_desc.SampleDesc.Count   = 1;
	depthstencil_desc.SampleDesc.Quality = 0;
	depthstencil_desc.Usage          = D3D11_USAGE_DEFAULT;
	depthstencil_desc.BindFlags      = D3D11_BIND_DEPTH_STENCIL;
	depthstencil_desc.CPUAccessFlags = 0; 
	depthstencil_desc.MiscFlags      = 0;

	// create the Depth/Stencil View
	m_d3d11_device->CreateTexture2D(&depthstencil_desc, NULL, &m_depthstencil_buffer);
	m_d3d11_device->CreateDepthStencilView(m_depthstencil_buffer, NULL, &m_depthstencil_view);
	
	// set render target views and depth stencil view
	m_d3d11_device_context->OMSetRenderTargets(1, &m_back_buffer_rtv, m_depthstencil_view);

	// create a shader resource review from the texture D2D will render to
	hr = m_d3d11_device->CreateShaderResourceView(m_shared_texture, NULL, &m_d2d_texture);

	// create off-screen textures
	CD3D11_TEXTURE2D_DESC offscreen_tex_desc(DXGI_FORMAT_R16G16B16A16_FLOAT, m_width, m_height);
	offscreen_tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
	offscreen_tex_desc.MipLevels = 1;
	for (int i = 0; i != ARRAYSIZE(m_offscreen_textures); ++i)
	{
		m_d3d11_device->CreateTexture2D(&offscreen_tex_desc, NULL, &m_offscreen_textures[i]);
		m_d3d11_device->CreateShaderResourceView(m_offscreen_textures[i], NULL, &m_offscreen_srvs[i]);
		m_d3d11_device->CreateRenderTargetView(m_offscreen_textures[i], NULL, &m_offscreen_rtvs[i]);
	}

	// create a constant buffer
	D3D11_BUFFER_DESC buffer_desc;
	ZeroMemory(&buffer_desc, sizeof(D3D11_BUFFER_DESC));
	buffer_desc.Usage	  = D3D11_USAGE_DYNAMIC;
	buffer_desc.ByteWidth = sizeof(ShaderParameters);
	buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	buffer_desc.MiscFlags = 0;
	hr = m_d3d11_device->CreateBuffer(&buffer_desc, NULL, &m_parameter_buffer);

	buffer_desc.ByteWidth = sizeof(float4);
	hr = m_d3d11_device->CreateBuffer(&buffer_desc, NULL, &m_jitter_buffer);
	hr = m_d3d11_device->CreateBuffer(&buffer_desc, NULL, &m_interleave_buffer);

	// create a texture from file
	D3DX11CreateShaderResourceViewFromFile(m_d3d11_device, TEXT("media/tex.bmp"), NULL, NULL, &m_custom_texture, &hr);

//.........这里部分代码省略.........
开发者ID:atyuwen,项目名称:hlsl_live_coding,代码行数:101,代码来源:d3d_app.cpp

示例14: Close

bool DXGI1Device::Init(const mfxU32 adapterNum)
{
    // release the object before initialization
    Close();

    // load up the library if it is not loaded
    if (NULL == m_hModule)
    {
        LoadDLLModule(L"dxgi.dll");
    }

    if (m_hModule)
    {
        DXGICreateFactoryFunc pFunc;
        IDXGIFactory1 *pFactory;
        IDXGIAdapter1 *pAdapter;
        DXGI_ADAPTER_DESC1 desc;
        mfxU32 curAdapter, maxAdapters;
        HRESULT hRes;

        // load address of procedure to create DXGI 1.1 factory
        pFunc = (DXGICreateFactoryFunc) GetProcAddress(m_hModule, "CreateDXGIFactory1");
        if (NULL == pFunc)
        {
            return false;
        }

        // create the factory
#if _MSC_VER >= 1400
        hRes = pFunc(__uuidof(IDXGIFactory1), (void**) (&pFactory));
#else
        hRes = pFunc(IID_IDXGIFactory1, (void**) (&pFactory));
#endif
        if (FAILED(hRes))
        {
            return false;
        }
        m_pDXGIFactory1 = pFactory;

        // get the number of adapters
        curAdapter = 0;
        maxAdapters = 0;
        mfxU32 outputs = 0;
        do
        {
            // get the required adapted
            hRes = pFactory->EnumAdapters1(curAdapter, &pAdapter);
            if (FAILED(hRes))
            {
                break;
            }

            mfxU32 curOutput = 0;
            HRESULT h;
            do
            {
                IDXGIOutput *out;
                h = pAdapter->EnumOutputs(curOutput, &out);
                
                if(FAILED(h))
                    break;

                // if it is the required adapter, save the interface
                if (outputs == adapterNum)
                    m_pDXGIAdapter1 = pAdapter;

                out->Release();
                
                outputs += 1;
                curOutput += 1;
            } while(!m_pDXGIAdapter1 && SUCCEEDED(h));

            if(!m_pDXGIAdapter1)
                pAdapter->Release();

            curAdapter += 1;

        } while (!m_pDXGIAdapter1 && SUCCEEDED(hRes));
        maxAdapters = curAdapter;

        // there is no required adapter
        if (adapterNum >= outputs)
        {
            return false;
        }
        pAdapter = (IDXGIAdapter1 *) m_pDXGIAdapter1;

        // get the adapter's parameters
        hRes = pAdapter->GetDesc1(&desc);
        if (FAILED(hRes))
        {
            return false;
        }

        // save the parameters
        m_vendorID = desc.VendorId;
        m_deviceID = desc.DeviceId;
        *((LUID *) &m_luid) = desc.AdapterLuid;
    }

//.........这里部分代码省略.........
开发者ID:AaronMike,项目名称:OBS,代码行数:101,代码来源:mfx_dxva2_device.cpp

示例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**)&copyTextureGame)))
    {
        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)))
//.........这里部分代码省略.........
开发者ID:choupachupss,项目名称:OBS,代码行数:101,代码来源:D3D11Capture.cpp


注:本文中的IDXGIAdapter1类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。