Domanda

I'm trying to create a SharpDX.Direct3D11.Texture2D from in-memory data but always get a SharpDXException (HRESULT: 0x80070057, "The parameter is incorrect."). I have used a Texture1D for this purpose before which can be created without a problem.

I have reduced the code to this sample which still produces the exception:

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.
    }
}

Creating the texture without passing the data works fine. Can someone tell me how to fix the Texture2D initialization?

È stato utile?

Soluzione

You need to pass the row stride of a texture 2D into the DataBox. Something like:

new DataBox(stream.DataPointer, 8 * 4)

Or in a more generic manner:

new DataBox(stream.DataPointer, description2D.Width
            * (int)FormatHelper.SizeOfInBytes(description2D.Format))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top