【问题标题】:How to get the DirectX::Image (from DirectXTex) structure based on ID3D11Texture2D?如何获取基于 ID3D11Texture2D 的 DirectX::Image(来自 DirectXTex)结构?
【发布时间】:2015-12-16 02:13:29
【问题描述】:

我有一个自定义纹理类:

class Texture{
    ID3D11Texture2D * renderTargetTexture;
public:
    ...
    void saveToTGA(std::wstring filePath);
};

我在渲染通道之间使用这个纹理作为渲染目标。我想编写将纹理保存到文件的saveToTGA(std::wstring filePath) 方法(类似于屏幕截图)。

MSDND3DX11SaveTextureToFile(...) 已贬值,所以我决定按照他们的建议使用 DirectXTex 库。

我知道我必须使用:

DirectX::Image image = ...
DirectX::SaveToTGAFile(image, filePath.c_str());

但问题是:如何基于ID3D11Texture2D得到DirectX::Image(来自DirectXTex)结构?

【问题讨论】:

    标签: c++ directx directx-11 texture2d render-to-texture


    【解决方案1】:

    来自 MSDN 文档,您可以使用

    Blockquote 我们建议您使用 DirectXTex 库、CaptureTexture 然后 SaveToXXXFile(其中 XXX 是 WIC、DDS 或 TGA;WIC 不支持 DDS 和 TGA;D3DX 9 支持 TGA 作为游戏的常见艺术源格式)。

    所以,首先你使用

    从纹理缓冲区中捕获你的纹理
    HRESULT hr = DirectX::CaptureTexture(m_D3D->GetDevice(), m_D3D->GetDeviceContext(), resourceContext, image);
    

    然后使用保存功能

    hr = DirectX::SaveToDDSFile(image.GetImages(),image.GetImageCount(), image.GetMetadata(), DirectX::DDS_FLAGS_NONE, Filename);
    

    请参阅此参考https://github.com/Microsoft/DirectXTex/wiki/CaptureTexture

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 2018-04-09
      • 2021-09-27
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 2014-03-10
      相关资源
      最近更新 更多