简体   繁体   English

将 Directx 11 后台缓冲区渲染到 Direct2d

[英]Rendering Directx 11 Back Buffer onto Direct2d

I want to make a simple level editor, in which editor's gui will be rendered by Direct2d and all the other 3D graphics will be handle by Directx 11.. Like Unity3D does.. as shown in the figure...我想做一个简单的关卡编辑器,其中编辑器的 gui 将由 Direct2d 渲染,所有其他 3D 图形将由 Directx 11 处理.. 就像 Unity3D 一样.. 如图所示......

https://i.stack.imgur.com/tf5G1.png https://i.stack.imgur.com/tf5G1.png

As you can see the 3D graphics are being render inside the GUI.. how can i share backbuffer of my directx 11 application with a direct2d(use to render gui)... so that 3D scene will be rendered inside the GUI.. or please suggest some other suggest other ideas other then using direct2d... also considering the performance.. Thank you..正如您所看到的,3D 图形正在 GUI 内渲染......我如何与 direct2d(用于渲染 gui)共享我的 directx 11 应用程序的后台缓冲区......以便 3D 场景将在 GUI 内渲染......或请建议一些其他建议其他想法,然后使用direct2d ...也考虑到性能..谢谢..

I don't know if sharing is possible.不知道能不能分享。 It's probably easier to create another d3d11 texture, get surface from it, then create Direct2D target/context on this surface.创建另一个 d3d11 纹理,从中获取表面,然后在该表面上创建 Direct2D 目标/上下文可能更容易。 Later you can render this UI texture together with your 3D content, like you would do for any other texture.稍后您可以将这个 UI 纹理与您的 3D 内容一起渲染,就像您对任何其他纹理所做的一样。

Yes, you can do it.是的,你可以做到。

In your header keep:在你的标题中保持:

ID2D1Device* m_d2device;
ID2D1DeviceContext* m_deviceContext;
ID2D1RenderTarget* m_renderTargetView;
ID2D1Factory* m_factory2d;
IDXGISurface* m_dxgiBackbuffer;
IDWriteFactory1* m_writeFactory;

Factory 2D:工厂2D:

HRESULT result;
// create the D2D factory

D2D1_FACTORY_OPTIONS options2d;
options2d.debugLevel = D2D1_DEBUG_LEVEL_NONE;
result = D2D1CreateFactory(D2D1_FACTORY_TYPE::D2D1_FACTORY_TYPE_MULTI_THREADED, options2d, &m_factory2d);

Create DXGI surface:创建 DXGI 表面:

// set up the D2D render target using the back buffer
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&m_dxgiBackbuffer));

D2D1_RENDER_TARGET_PROPERTIES props =
D2D1::RenderTargetProperties
(D2D1_RENDER_TARGET_TYPE_DEFAULT,
D2D1::PixelFormat
  (
  DXGI_FORMAT_UNKNOWN,
  D2D1_ALPHA_MODE_PREMULTIPLIED
  )
);

m_factory2d->CreateDxgiSurfaceRenderTarget(
m_dxgiBackbuffer,
props,
&m_d2dRenderTarget);

DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(m_writeFactory), 
(IUnknown**)(&m_writeFactory));

In your render loop first render 3D things then 2D things.在您的渲染循环中,首先渲染 3D 事物,然后渲染 2D 事物。 You can both render 2D over 3D or vice versa.您可以在 3D 上渲染 2D,反之亦然。 Just pass it trough 3D.只需通过 3D 即可。 I tested both on DX11.0 and win10.我在 DX11.0 和 win10 上都进行了测试。 I highly advise you to seperate 3D call and 2D call into different classes that would provide better management.我强烈建议您将 3D 调用和 2D 调用分离到不同的类中,以提供更好的管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM