【问题标题】:Filling std::vector<byte> from ID3DBLob从 ID3DBlob 填充 std::vector<byte>
【发布时间】:2016-01-07 00:58:57
【问题描述】:

我正在使用 D3DCompile2() 编译一个着色器文件,它用编译后的字节码填充 ID3DBlob。

但我需要将编译后的缓冲区从 ID3DBlob 填充到 std::vector 容器中。 ID3DBlob有获取缓冲区指针和缓冲区大小的方法如下:

LPVOID GetBufferPointer();

SIZE_T GetBufferSize();

如何以最佳方式用 ID3DBlob 中的缓冲区填充 std::vector?

【问题讨论】:

    标签: c++ directx-11


    【解决方案1】:

    我不确定如何解释“最好的方法”,但从语法上讲,这是一种非常简洁的方法。

    using buffer_t = std::vector<unsigned char>;
    
    auto *p = reinterpret_cast<unsigned char *>(d3dblob->GetBufferPointer());
    auto  n = d3dblob->GetBufferSize();
    buffer_t buff;
    
    buff.reserve(n);
    std::copy(p, p+n, std::back_inserter(buff))
    

    【讨论】:

    • 如果有帮助,您可以接受这个作为答案:)
    猜你喜欢
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    相关资源
    最近更新 更多