【问题标题】:Use a texture array as Direct2D surface render target使用纹理数组作为 Direct2D 表面渲染目标
【发布时间】:2020-10-04 00:21:20
【问题描述】:

我尝试创建一个 Direct3D 11 纹理数组,其中包含使用 DirectWrite 和 Direct2D 渲染的多页文本。假设layout 持有各个页面的IDWriteTextLayouts,那么我尝试执行以下操作:

{
    D3D11_TEXTURE2D_DESC desc;
    ::ZeroMemory(&desc, sizeof(desc));
    desc.ArraySize = static_cast<UINT>(layouts.size());
    desc.BindFlags = D3D11_BIND_RENDER_TARGET;
    desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    desc.Height = height;
    desc.MipLevels = 1;
    desc.SampleDesc.Count = 1;
    desc.Usage = D3D11_USAGE_DEFAULT;
    desc.Width = width;

    auto hr = this->_d3dDevice->CreateTexture2D(&desc, nullptr, &retval.Texture);
    if (FAILED(hr)) {
        throw std::system_error(hr, com_category());
    }
}

for (auto &l : layouts) {
    ATL::CComPtr<IDXGISurface> surface;

    {
        auto hr = retval.Texture->QueryInterface(&surface);
        if (FAILED(hr)) {
             // The code fails here with E_NOINTERFACE "No such interface supported."
             throw std::system_error(hr, com_category());
        }
    }

    // Go on creating the RT from 'surface'.
}

问题是代码在指定行失败,如果有超过一页(desc.ArraySize > 1),我尝试从ID3D11Texture2D 获取IDXGISurface 接口。我最终在文档 (https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nn-dxgi-idxgisurface) 中发现这是由 deisgn 编写的:

如果 2D 纹理 [...] 不包含纹理数组,则 QueryInterface 成功并返回指向 IDXGISurface 接口指针的指针。否则,QueryInterface 失败并且不返回指向 IDXGISurface 的指针。

有没有其他方法可以获取纹理数组中的各个 DXGI 表面,以便使用 Direct2D 一个接一个地绘制到它们?

【问题讨论】:

    标签: direct2d direct3d11 dxgi


    【解决方案1】:

    Texture => IDXGIResource1 => CreateSubresourceSurface 怎么样?

    【讨论】:

      【解决方案2】:

      由于我找不到任何解决子表面的方法,我现在创建一个暂存纹理​​,其中一层要渲染到并使用ID3D11DeviceContext::CopySubresourceRegion 将结果复制到纹理数组中。

      【讨论】:

        猜你喜欢
        • 2014-01-14
        • 1970-01-01
        • 1970-01-01
        • 2023-01-20
        • 2012-10-15
        • 2018-11-04
        • 1970-01-01
        • 1970-01-01
        • 2016-07-22
        相关资源
        最近更新 更多