Skip to content

Commit

Permalink
Add Texture2D.GetDataPointerEXT
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 13, 2024
1 parent 846c9e3 commit b738202
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/Graphics/Texture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,30 @@ int elementCount
);
}

int elementSizeInBytes = MarshalHelper.SizeOf<T>();
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)
{
subX = 0;
subY = 0;
subX = 0;
subY = 0;
subW = Width >> level;
subH = Height >> level;
}
Expand All @@ -313,11 +332,6 @@ int elementCount
subW = rect.Value.Width;
subH = rect.Value.Height;
}

int elementSizeInBytes = MarshalHelper.SizeOf<T>();
ValidateGetDataFormat(Format, elementSizeInBytes);

GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
FNA3D.FNA3D_GetTextureData2D(
GraphicsDevice.GLDevice,
texture,
Expand All @@ -326,10 +340,9 @@ int elementCount
subW,
subH,
level,
handle.AddrOfPinnedObject() + (startIndex * elementSizeInBytes),
elementCount * elementSizeInBytes
data,
dataLengthBytes
);
handle.Free();
}

#endregion
Expand Down

0 comments on commit b738202

Please sign in to comment.