SlimDX/slimdx

Construct a DataStream by making a shallow copy of a generic array

Closed this issue · 3 comments

Currently, there doesn't seem to be a convenient way of using 
UpdateSubresource without unsafe code:

// byte[] pixels, loaded from an image

fixed( byte* p = pixels )
{
    var buffer = ( IntPtr ) p;
    var srcStream = new DataStream( buffer, 4 * nPixels, true, false );                                
    var srcBox = new DataBox( srcRowPitch, srcDepthPitch, srcStream );
    device.UpdateSubresource( srcBox, Texture, 0, dstRegion );
}

The way to do it without unsafe code would be to construct a new datastream 
of the same size, write into it from the array, and then calling 
UpdateSubresource.

I would like to construct a DataStream that's just a shallow copy of a 
managed array.  Is this possible or convenient?  Alternatively, we could 
add constructors to create DataRectangles and DataBoxes out of arrays.

Original issue reported on code.google.com by jia...@gmail.com on 12 Jun 2009 at 6:23

Convenient, no -- DataStream already has two or three backing stores that can be
active with their own bits of unique behavior. But it is doable, certainly.  I 
will
take a more detailed look at this.

Original comment by josh.petrie on 12 Jun 2009 at 2:59

  • Changed state: Accepted
Added DataStream( Array userBuffer, bool canRead, bool canWrite ).

Original comment by josh.petrie on 13 Jun 2009 at 5:16

Original comment by josh.petrie on 13 Jun 2009 at 5:16

  • Changed state: Fixed