首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SharpDX:从DataStream初始化Texture2D失败(尽管Texture1D可以正常工作)

SharpDX:从DataStream初始化Texture2D失败(尽管Texture1D可以正常工作)
EN

Stack Overflow用户
提问于 2012-11-07 08:13:24
回答 1查看 3.7K关注 0票数 2

我试图从内存中的数据创建SharpDX.Direct3D11.Texture2D,但总是得到一个SharpDXException (HRESULT: 0x80070057,“该参数不正确。”)。为此,我使用了一个Texture1D,在此之前创建它不会有任何问题。

我已经将代码简化为以下示例,它仍然会产生异常:

代码语言:javascript
复制
using (var device = new Device(DriverType.Hardware, DeviceCreationFlags.Debug)) {
    // empty stream sufficient for example
    var stream = new DataStream(16 * 4, true, true);

    var description1D = new Texture1DDescription() {
        Width = 16,
        ArraySize = 1,
        Format = Format.R8G8B8A8_UNorm,
        MipLevels = 1,
    };
    using (var texture1D = new Texture1D(device, description1D, new[] { new DataBox(stream.DataPointer) })) {
        // no exception on Texture1D
    }

    var description2D = new Texture2DDescription() {
        Width = 8,
        Height = 2,
        ArraySize = 1,
        MipLevels = 1,
        Format = Format.R8G8B8A8_UNorm,
        SampleDescription = new SampleDescription(1, 0),
    };
    using (var texture2D = new Texture2D(device, description2D, new[] { new DataBox(stream.DataPointer) })) {
        // HRESULT: [0x80070057], Module: [Unknown], ApiCode: [Unknown/Unknown], Message: The parameter is incorrect.
    }
}

在不传递数据的情况下创建纹理效果良好。有人能告诉我如何修复Texture2D初始化吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-07 09:24:25

您需要将2D纹理的行跨距传递到DataBox中。类似于:

代码语言:javascript
复制
new DataBox(stream.DataPointer, 8 * 4)

或者以更通用的方式:

代码语言:javascript
复制
new DataBox(stream.DataPointer, description2D.Width
            * (int)FormatHelper.SizeOfInBytes(description2D.Format))
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13261427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档