diff --git a/src/Graphics/Texture2D.cs b/src/Graphics/Texture2D.cs index 582d8ffb..4807c9dd 100644 --- a/src/Graphics/Texture2D.cs +++ b/src/Graphics/Texture2D.cs @@ -298,6 +298,25 @@ int elementCount ); } + int elementSizeInBytes = MarshalHelper.SizeOf(); + ValidateGetDataFormat(Format, elementSizeInBytes); + + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + GetDataPointerEXT( + level, + rect, + handle.AddrOfPinnedObject() + (startIndex * elementSizeInBytes), + elementCount * elementSizeInBytes + ); + handle.Free(); + } + + public void GetDataPointerEXT( + int level, + Rectangle? rect, + IntPtr data, + int dataLengthBytes + ) { int subX, subY, subW, subH; if (rect == null) { @@ -313,11 +332,6 @@ int elementCount subW = rect.Value.Width; subH = rect.Value.Height; } - - int elementSizeInBytes = MarshalHelper.SizeOf(); - ValidateGetDataFormat(Format, elementSizeInBytes); - - GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); FNA3D.FNA3D_GetTextureData2D( GraphicsDevice.GLDevice, texture, @@ -326,10 +340,9 @@ int elementCount subW, subH, level, - handle.AddrOfPinnedObject() + (startIndex * elementSizeInBytes), - elementCount * elementSizeInBytes + data, + dataLengthBytes ); - handle.Free(); } #endregion