directX创建交换链 [英] directX creating the swapchain

查看:385
本文介绍了directX创建交换链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的书里,我的代码创建交换链。

In my book there i code to create swap chain.

IDXGIDevice * dxgiDevice = 0;
mD3dDevice->QueryInterface( __uuidof( IDXGIDevice ),( void ** ) & dxgiDevice );

IDXGIAdapter * dxgiAdapter = 0;
dxgiDevice->GetParent( __uuidof( IDXGIAdapter ),( void ** ) & dxgiAdapter );

IDXGIFactory * dxgiFactory = 0;
dxgiAdapter->GetParent( __uuidof( IDXGIFactory ),( void ** ) & dxgiFactory );

dxgiFactory->CreateSwapChain( mD3dDevice, & sd, & mSwapChain );

对于这个代码没有解释,我检查几个书籍,有太多,此代码。

For this code there is no explanation, i check few mor books and there is too, noo explanation for this code.

请帮助mi。
我真的不明白做什么GetParent方法。
idxgiDevice extends idxgiObject。
idxgiDevice的父类是idxgiObject,为什么它们使用指向idxgiFacory的指针作为参数。

Please help mi with this. I realy dont understand what doing GetParent method. idxgiDevice extend idxgiObject. parent for idxgiDevice is idxgiObject, why they use pointer to idxgiFacory as a parametr.

我不知道我理解queryInterface好

And i dont know that i understand the queryInterface good

请帮助解答这个

推荐答案

此代码用于使用DirectX创建交换链11或更高版本的接口,并且此模式专门设计为确保您使用的DXGI工厂实例是在创建Direct3D 11设备时实际使用的实例。

This code is for creating the swap chain with DirectX 11 or later version of the interfaces, and this pattern is specifically designed to ensure that the DXGI factory instance you use is the one that was actually used when you created the Direct3D 11 device.

基本上,当您第一次创建Direct3D 11设备时,您可以选择提供要使用的 IDXGIAdapter 实例。大多数人在这里传递 nullptr NULL ,只是让它在系统中的默认适配器上创建一个设备。但是,要完成交换链的设置,您需要DXGI工厂实例。你可以在理论上使用 DXGICreateFactory1 创建一个,但是你可以使用 DXGICreateFactory 或者 DXGICreateFactory2 有错误的标志。

Basically, when you first created the Direct3D 11 device, you had the option of providing the IDXGIAdapter instance to use. Most people pass nullptr or NULL here and just let it create a device on the default adapter in the system. To finish setting up the swap chain, however, you need the DXGI factory instance. You could in theory create one yourself using DXGICreateFactory1 but you could easily mess up and get the 'wrong one' by using DXGICreateFactory or maybe DXGICreateFactory2 with the wrong flags.

相反,最安全的事情是获取<$ c使用标准COM 从您的 ID3D11Device 中获取$ c> IDXGIDevice library / windows / desktop / ms682521.aspxrel =nofollow> IUnknown :: QueryInterface

Instead, the safest thing to do is get the IDXGIDevice from your ID3D11Device using the standard COM IUnknown::QueryInterface:

IDXGIDevice * dxgiDevice = 0;
HRESULT hr = mD3dDevice->QueryInterface( __uuidof( IDXGIDevice ),( void ** ) & dxgiDevice );
if ( SUCCEEDED(hr) )

然后获取 IDXGIAdapter 使用 IDXGIDevice .aspxrel =nofollow> IDXGIObject :: GetParent

Then get the IDXGIAdapter from the IDXGIDevice using IDXGIObject::GetParent:

IDXGIAdapter * dxgiAdapter = 0;
hr = dxgiDevice->GetParent( __uuidof( IDXGIAdapter ),( void ** ) & dxgiAdapter );
if ( SUCCEEDED(hr) )

然后得到 IDXGIFactory 使用 IDXGIAdapter .aspxrel =nofollow> IDXGIObject :: GetParent

Then get the IDXGIFactory from the IDXGIAdapter using IDXGIObject::GetParent again:

IDXGIFactory * dxgiFactory = 0;
hr = dxgiAdapter->GetParent( __uuidof( IDXGIFactory ),( void ** ) & dxgiFactory );
if ( SUCCEEDED(hr) )

IDXGIFactory 与您的Direct3D 11设备相关联,无论它是如何创建的。记住COM引用计数意味着你已经引用了所有这些对象,现在你必须清理:

Now you have the IDXGIFactory associated with your Direct3D 11 device no matter how it was created. Remember that COM reference counting means you have references to all these objects now you have to cleanup:

dxgiFactory->Release();
dxgiAdapter->Release();
dxgiDevice->Release();

请注意, IDXGIFactory :: CreateSwapChain DirectX 11.0创建交换链的方法,如果你使用 D3D11CreateDeviceAndSwapChain ,而不是 D3D11CreateDevice 。对于DirectX 11.1或更高版本的系统,您可以考虑使用 IDXGIFactory2 :: CreateSwapChainForHwnd 代替Win32桌面应用程序。对于Windows应用商店应用,Windows Phone 8和Xbox One,您总是使用 IDXGIFactory2 :: CreateSwapChainForCoreWindow

Note that IDXGIFactory::CreateSwapChain is the DirectX 11.0 way of creating the swap chain, and you'd get basically the same results if you had used D3D11CreateDeviceAndSwapChain rather than D3D11CreateDevice in the first place. For DirectX 11.1 or later systems, you would consider using IDXGIFactory2::CreateSwapChainForHwnd instead for Win32 desktop apps. For Windows Store apps, Windows phone 8, and Xbox One, you'd always use IDXGIFactory2::CreateSwapChainForCoreWindow.

对于Win32桌面应用程序,您可以按照以下代码:

For a Win32 desktop application, you'd follow the code above with something like:

IDXGIFactory2* dxgiFactory2 = 0;
hr = dxgiFactory->QueryInterface( __uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory2) );
if ( SUCCEEDED(hr) )
{
    // This system has DirectX 11.1 or later installed, so we can use this interface
    dxgiFactory2->CreateSwapChainForHwnd( /* parameters */ );
    dxgiFactory2->Release();
}
else
{
    // This system only has DirectX 11.0 installed
     dxgiFactory->CreateSwapChain( /* parameters */ );
}

查看 =https://code.msdn.microsoft.com/Direct3D-Tutorial-Win32-829979ef =nofollow> Win32桌面应用程序版本 Windows商店应用版本

这篇关于directX创建交换链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆