Is there anyway to accept Texture2D Setdata in IntPtr

Hi All,
Is there any possible/alternative way to setdata source from IntPtr instead of using manage array (e.g. byte[])?

IntPtr dataSource;
int size = width * height * 4;

_texture2D.SetData(dataSource, 0, size);

Thank You

1 Like

Incase someone is looking for the same solution to get improve your SetData without double convert from unmanage to manage before pass it to SetData.

I have get my self MonoGame source to implement the function below:

Graphics\Texture2D.cs

/// <summary>
///     Changes the texture's pixels
/// </summary>
/// <param name="data">New data for the texture</param>
public void SetData(IntPtr data)
{
    PlatformSetData(0, data);
}

private void PlatformSetData(int level, IntPtr data)
{
    int w, h;
    GetSizeForLevel(Width, Height, level, out w, out h);

    // For DXT compressed formats the width and height must be
    // a multiple of 4 for the complete mip level to be set.
    if (_format.IsCompressedFormat())
    {
        w = (w + 3) & ~3;
        h = (h + 3) & ~3;
    }

    var region = new ResourceRegion();
    region.Top = 0;
    region.Front = 0;
    region.Back = 1;
    region.Bottom = h;
    region.Left = 0;
    region.Right = w;

    // TODO: We need to deal with threaded contexts here!
    var subresourceIndex = CalculateSubresourceIndex(0, level);
    var d3dContext = GraphicsDevice._d3dContext;
    lock (d3dContext)
        d3dContext.UpdateSubresource(GetTexture(), subresourceIndex, region, data, GetPitch(w), 0);
}