【发布时间】: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