rename Texture load methods for clarity

remotes/1695061714407202320/main
cosmonaut 2023-04-19 00:50:59 -07:00
parent 0ea60a376b
commit 2d7bb24b5c
1 changed files with 30 additions and 18 deletions

View File

@ -25,7 +25,7 @@ namespace MoonWorks.Graphics
/// <summary> /// <summary>
/// Creates a 2D Texture using PNG or QOI data from raw byte data. /// Creates a 2D Texture using PNG or QOI data from raw byte data.
/// </summary> /// </summary>
public static unsafe Texture FromData( public static unsafe Texture FromImageBytes(
GraphicsDevice device, GraphicsDevice device,
CommandBuffer commandBuffer, CommandBuffer commandBuffer,
Span<byte> data Span<byte> data
@ -58,7 +58,7 @@ namespace MoonWorks.Graphics
/// <summary> /// <summary>
/// Creates a 2D Texture using PNG or QOI data from a stream. /// Creates a 2D Texture using PNG or QOI data from a stream.
/// </summary> /// </summary>
public static unsafe Texture FromStream( public static unsafe Texture FromImageStream(
GraphicsDevice device, GraphicsDevice device,
CommandBuffer commandBuffer, CommandBuffer commandBuffer,
Stream stream Stream stream
@ -68,7 +68,7 @@ namespace MoonWorks.Graphics
var span = new Span<byte>(buffer, (int) length); var span = new Span<byte>(buffer, (int) length);
stream.ReadExactly(span); stream.ReadExactly(span);
var texture = FromData(device, commandBuffer, span); var texture = FromImageBytes(device, commandBuffer, span);
NativeMemory.Free((void*) buffer); NativeMemory.Free((void*) buffer);
@ -78,19 +78,40 @@ namespace MoonWorks.Graphics
/// <summary> /// <summary>
/// Creates a 2D Texture using PNG or QOI data from a file. /// Creates a 2D Texture using PNG or QOI data from a file.
/// </summary> /// </summary>
public static Texture FromFile( public static Texture FromImageFile(
GraphicsDevice device, GraphicsDevice device,
CommandBuffer commandBuffer, CommandBuffer commandBuffer,
string path string path
) { ) {
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read); var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
return FromStream(device, commandBuffer, fileStream); return FromImageStream(device, commandBuffer, fileStream);
}
public static unsafe void SetDataFromImageBytes(
CommandBuffer commandBuffer,
TextureSlice textureSlice,
Span<byte> data
) {
fixed (byte* ptr = data)
{
var pixels = Refresh.Refresh_Image_Load(
(nint) ptr,
(int) data.Length,
out var w,
out var h,
out var len
);
commandBuffer.SetTextureData(textureSlice, pixels, (uint) len);
Refresh.Refresh_Image_Free(pixels);
}
} }
/// <summary> /// <summary>
/// Sets data for a texture slice using PNG or QOI data from a stream. /// Sets data for a texture slice using PNG or QOI data from a stream.
/// </summary> /// </summary>
public static unsafe void SetDataFromStream( public static unsafe void SetDataFromImageStream(
CommandBuffer commandBuffer, CommandBuffer commandBuffer,
TextureSlice textureSlice, TextureSlice textureSlice,
Stream stream Stream stream
@ -100,30 +121,21 @@ namespace MoonWorks.Graphics
var span = new Span<byte>(buffer, (int) length); var span = new Span<byte>(buffer, (int) length);
stream.ReadExactly(span); stream.ReadExactly(span);
var pixels = Refresh.Refresh_Image_Load( SetDataFromImageBytes(commandBuffer, textureSlice, span);
(nint) buffer,
(int) length,
out var w,
out var h,
out var len
);
commandBuffer.SetTextureData(textureSlice, pixels, (uint) len);
Refresh.Refresh_Image_Free(pixels);
NativeMemory.Free((void*) buffer); NativeMemory.Free((void*) buffer);
} }
/// <summary> /// <summary>
/// Sets data for a texture slice using PNG or QOI data from a file. /// Sets data for a texture slice using PNG or QOI data from a file.
/// </summary> /// </summary>
public static void SetDataFromFile( public static void SetDataFromImageFile(
CommandBuffer commandBuffer, CommandBuffer commandBuffer,
TextureSlice textureSlice, TextureSlice textureSlice,
string path string path
) { ) {
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read); var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
SetDataFromStream(commandBuffer, textureSlice, fileStream); SetDataFromImageStream(commandBuffer, textureSlice, fileStream);
} }
public unsafe static Texture LoadDDS(GraphicsDevice graphicsDevice, CommandBuffer commandBuffer, System.IO.Stream stream) public unsafe static Texture LoadDDS(GraphicsDevice graphicsDevice, CommandBuffer commandBuffer, System.IO.Stream stream)