Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct2D 直接与Direct3D 11 进行协同 #2

Open
dustpg opened this issue Jul 27, 2018 · 0 comments
Open

Direct2D 直接与Direct3D 11 进行协同 #2

dustpg opened this issue Jul 27, 2018 · 0 comments
Assignees

Comments

@dustpg
Copy link
Owner

dustpg commented Jul 27, 2018

进行协同

如果要在D3D11 上进行2D绘制, 使用Direct2D将是一个不错的选择,因为D2D就是由D3D实现的,可以实现几乎无缝地交互协同工作.
微软在Direct2D and Direct3D Interoperability Overview中提到了这两种协同:

  1. 直接在现有的交换链/RTV 上绘制, 就像一般正交投影绘制的UI一样
  2. 绘制到纹理上让模型展示出来. 这样可以干的事情就多了. 特别地, 如果不是专门设计的3D展示UI, 用一般2D的UI然后放在一个矩形里面充当一个伪3D UI也是不错的选择. 这也是LongUI的实现目标之一.
    division

直接协同

如同题目所述: 直接协同. 微软在文中是用一种"共享"的办法, 利用D3D 10作为中介让D3D11与D2D协同, 简直太麻烦了. 文中提到

With DirectX 11.1 or later, Direct2D supports interoperability with Direct3D 11 as well.

这里应该指的是版本号而非指特性等级.因为我在Win7的虚拟机(虚拟显卡只支持到10.1)也能够工作. 这里推荐的方法是(使用 Direct2D 1.1, 下面只包括D2D端必要数据)

                      +--------------+          +--------------+
                      |              |    QI    |              |
     +--------------> | ID3D11Device*+----------> IDXGIDevice1 |
     |                |              |          |              |
     |                +--------------+          +--+-----------+
     |                                             |
     |                                             |
     |                                             |      +-----------------+
+----+----+   +--------+     +----------------+    v      |                 |
|  D3D11  |   | D2D1.1 +-----> ID2D1Factory1  +----+----->+   ID2D1Device   |
+---+-----+   +--------+     +----------------+           |                 |
    |                                                     +-+---------------+
    |                                                       |
    |                                                       v
    |         +-------------------------+                  ++-------------------+
    +-------->+   ID3D11Texture2D**     |                  |                    |
              +--------------+----------+                  | ID2D1DeviceContext |
                             |                             |                    |
                             |                             +--------+-----------+
                             | QI  +---------------+                |
                             +---->+ IDXGISurface  +--------------->+
                                   +---------------+                |
                                                                    |
                                                                    v
                                                         +----------+-----------+
                                                         |     ID2D1Bitmap1***  |
                                                         +----------+-----------+
                                                                    |
                                                                    |
                                                                    v
                                              +---------------------+-----------+
                                              |                                 |
                                              | ID2D1DeviceContext::SetTarget   |
                                              |                                 |
                                              +---------------------------------+

*: 创建ID3D11Device: 记得D3D11_CREATE_DEVICE_BGRA_SUPPORT
**: 创建ID3D11Texture2D: 记得MipLevels=1
***: ID2D1DeviceContext::CreateBitmapFromDxgiSurface

这样全局可以共享一个ID2D1DeviceContext, 文本所使用的代码在NoteFL/D3D11/D3D11InteropWithD2D/main.cpp 这里,懒得渲染字体什么的了, 画个圈圈意思一下就行:
d3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant