Domanda

I am trying to figure out how to convert the code below (which is for SlimDX) over to SharpDX.

var texure2d = new Texture2D(_device, texDesc);
var dbox = _deviceContext.MapSubresource(texure2d, 0, MapMode.WriteDiscard, MapFlags.None);
foreach (var thisColor4 in color) // color is a List<Color4>
{
    dbox.Data.Write((byte)(thisColor4.Red * 255));
    dbox.Data.Write((byte)(thisColor4.Green * 255));
    dbox.Data.Write((byte)(thisColor4.Blue * 255));
    dbox.Data.Write((byte)(0));
}
_deviceContext.UnmapSubresource(texure2d, 0);

I also have a similar questions with DataRectagle:

var heightMapTexure = new Texture2D(device, textureDesc,
    new DataRectangle(
        HeightMapWidth * Marshal.SizeOf(typeof(Half)), // Pitch
        new DataStream(hmap.ToArray(), false, false) // dataStream
    )
);

Reading through the SlimDX source it looks like they store a DataStreams while SharpDX stores a pointer and I am unsure how to proceed as I have never worked with pointers before. Any help with how to get this working or an alternative method to achieve the same results would be appreciated.

È stato utile?

Soluzione

So I have figured this out on my own, the way I was able to do this is:

DataStream mappedResource;
deviceContext.MapSubresource(texure2d, 0, MapMode.WriteDiscard, MapFlags.None, out mappedResource);
foreach (var thisColor4 in color)
{
    mappedResource.Write((byte)(thisColor4.Red * 255));
    mappedResource.Write((byte)(thisColor4.Green * 255));
    mappedResource.Write((byte)(thisColor4.Blue * 255));
    mappedResource.Write((byte)(0));
}
deviceContext.UnmapSubresource(texure2d, 0);

var heightMapTexure = new Texture2D(device, textureDesc,
    new DataRectangle(
        DataStream.Create(hmap.ToArray(), false, false).DataPointer,
        HeightMapWidth * Marshal.SizeOf(typeof(Half))   
    )
);

Hope this helps other that may have a similar question.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top