Direct2D可以实际使用direct3D 11设备吗?

时间:2015-08-06 23:38:39

标签: c++ direct2d direct3d11

我在互联网上听说Direct2D仅适用于Direct3D 10.1设备。但我决定尝试使用D2D,看看是否真的如此。一旦我完成了所有的实验......我得出的结论是Direct2d实际上可以使用direct3d 11设备。

无论如何,这是我用来试验的代码..我试图用direct3d 11设备创建一个DXGI表面(指向D3D11 2D纹理)。

            /* SharedTextureDesc object contains description of a 2D texture*/

D3D11device->CreateTexture2D(&SharedTextureDesc, NULL, &SharedTexture);

SharedTexture->QueryInterface(__uuidof(IDXGIResource), (void**)&SharedResource);

SharedResource->GetSharedHandle(&SharedHandle);

D3D11device->OpenSharedResource(SharedHandle, __uuidof(IDXGISurface1), (void**)&SharedSurface); 

上面的代码显示我使用direct3d 11设备创建了一个DXGI表面。现在在下面,我使用DXGI表面为Direct2D创建渲染目标。

/* RenderTargetProperties contains the description for render target */

D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), (void**) &D2DFactory);

D2DFactory->CreateDxgiSurfaceRenderTarget(SharedSurface, &RenderTargetProperties, &RenderTargetD2D)

Direct2d的渲染目标似乎有效,我可以用它来实际渲染文本到我的游戏中。方法CreateDxgiSurfaceRenderTarget()甚至返回S_OK,告诉我它已成功。

但我唯一的问题是...... direct2d的渲染目标是否仍可正常工作?或者Direct2D根本不能与Direct3D 11设备一起使用?

1 个答案:

答案 0 :(得分:4)

DirectX 11.1系统上的Direct2D可以与Direct3D 11设备配合使用。 DirectX 11.1包含在Windows 8或更高版本中,并且通过KB2670838

在Windows 7 SP1上得到部分支持

使用DirectX 11.0系统(即安装了KB971644,Windows 7 RTM或安装了KB2670838的Windows 7 SP1的Windows Vista SP2),您必须使用DXGI表面共享,以便Direct2D在Direct3D 10.1设备上运行并且您“共享”使用Direct3D 11设备的结果。

请参阅MSDNDirectX 11.1 and Windows 7DirectX 11.1 and Windows 7 Update