direct2d - 使用纹理数组作为 Direct2D 表面渲染目标
问题描述
我尝试创建一个 Direct3D 11 纹理数组,其中包含使用 DirectWrite 和 Direct2D 呈现的多页文本。假设为各个页面layout
保存IDWriteTextLayout
s,然后我尝试执行以下操作:
{
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 编写的:ID3D11Texture2D
desc.ArraySize
如果 2D 纹理 [...] 不包含纹理数组,则 QueryInterface 成功并返回指向 IDXGISurface 接口指针的指针。否则,QueryInterface 将失败并且不返回指向 IDXGISurface 的指针。
有没有其他方法可以获取纹理数组中的各个 DXGI 表面,以便使用 Direct2D 一个接一个地绘制它们?
解决方案
Texture => IDXGIResource1 => CreateSubresourceSurface 怎么样?
推荐阅读
- python - 如何根据条件从另一个数据框中替换一个数据框中的列值?
- html - 如何重定向单一类型的网址
- python - 在python中如何将字符串转换为带有时区的日期时间
- c# - Response.TransmitFile 在 mvc 5 中不起作用
- ios - 获取 naturalSize 和列表分辨率视频 m3u8
- javascript - 单击汉堡包图标时,粘性导航栏没有完全响应
- artificial-intelligence - 为什么使用非复杂算法
- javascript - html5画布比例与增加画布尺寸以进行缩放有什么区别?
- html - 在窗口重新调整大小时居中重叠图像
- hl7-fhir - 无法从批量 API 调用中获取数据