首页 > 解决方案 > 使用纹理数组作为 Direct2D 表面渲染目标

问题描述

我尝试创建一个 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'.
}

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

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

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

标签: direct2ddirect3d11dxgi

解决方案


Texture => IDXGIResource1 => CreateSubresourceSurface 怎么样?


推荐阅读