load images from memory + QOI support
parent
8209051a3c
commit
8134761e44
|
@ -1 +1 @@
|
||||||
Subproject commit 10f54d6b034d685d314233f9507a4bbac7f235b4
|
Subproject commit fb5fee5f568bbb9f42920f0fcdd9f85024f5bf00
|
|
@ -28,10 +28,13 @@ namespace MoonWorks.Graphics
|
||||||
/// <param name="device"></param>
|
/// <param name="device"></param>
|
||||||
/// <param name="commandBuffer"></param>
|
/// <param name="commandBuffer"></param>
|
||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
/// <returns></returns>
|
/// <returns>A Texture object.</returns>
|
||||||
public static Texture LoadPNG(GraphicsDevice device, CommandBuffer commandBuffer, string filePath)
|
public static Texture LoadPNG(
|
||||||
{
|
GraphicsDevice device,
|
||||||
var pixels = Refresh.Refresh_Image_Load(
|
CommandBuffer commandBuffer,
|
||||||
|
string filePath
|
||||||
|
) {
|
||||||
|
var pixels = Refresh.Refresh_Image_LoadPNGFromFile(
|
||||||
filePath,
|
filePath,
|
||||||
out var width,
|
out var width,
|
||||||
out var height,
|
out var height,
|
||||||
|
@ -53,7 +56,56 @@ namespace MoonWorks.Graphics
|
||||||
var texture = new Texture(device, textureCreateInfo);
|
var texture = new Texture(device, textureCreateInfo);
|
||||||
commandBuffer.SetTextureData(texture, pixels, byteCount);
|
commandBuffer.SetTextureData(texture, pixels, byteCount);
|
||||||
|
|
||||||
Refresh.Refresh_Image_Free(pixels);
|
Refresh.Refresh_Image_FreePNG(pixels);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads a PNG from a byte array.
|
||||||
|
/// NOTE: You can queue as many of these as you want on to a command buffer but it MUST be submitted!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="device"></param>
|
||||||
|
/// <param name="commandBuffer"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns>A Texture object.</returns>
|
||||||
|
public unsafe static Texture LoadPNG(
|
||||||
|
GraphicsDevice device,
|
||||||
|
CommandBuffer commandBuffer,
|
||||||
|
byte[] data
|
||||||
|
) {
|
||||||
|
IntPtr pixels;
|
||||||
|
int width, height, numChannels;
|
||||||
|
|
||||||
|
fixed (byte* ptr = &data[0])
|
||||||
|
{
|
||||||
|
pixels = Refresh.Refresh_Image_LoadPNGFromMemory(
|
||||||
|
(nint) ptr,
|
||||||
|
data.Length,
|
||||||
|
out width,
|
||||||
|
out height,
|
||||||
|
out numChannels
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureCreateInfo textureCreateInfo = new TextureCreateInfo
|
||||||
|
{
|
||||||
|
Width = (uint) width,
|
||||||
|
Height = (uint) height,
|
||||||
|
Depth = 1,
|
||||||
|
Format = TextureFormat.R8G8B8A8,
|
||||||
|
IsCube = false,
|
||||||
|
LevelCount = 1,
|
||||||
|
SampleCount = SampleCount.One,
|
||||||
|
UsageFlags = TextureUsageFlags.Sampler
|
||||||
|
};
|
||||||
|
|
||||||
|
var byteCount = (uint) (width * height * numChannels);
|
||||||
|
|
||||||
|
var texture = new Texture(device, textureCreateInfo);
|
||||||
|
commandBuffer.SetTextureData(texture, pixels, byteCount);
|
||||||
|
|
||||||
|
Refresh.Refresh_Image_FreePNG(pixels);
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +126,97 @@ namespace MoonWorks.Graphics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads a QOI from a file path.
|
||||||
|
/// NOTE: You can queue as many of these as you want on to a command buffer but it MUST be submitted!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="device"></param>
|
||||||
|
/// <param name="commandBuffer"></param>
|
||||||
|
/// <param name="filePath"></param>
|
||||||
|
/// <returns>A Texture object.</returns>
|
||||||
|
public unsafe static Texture LoadQOI(
|
||||||
|
GraphicsDevice device,
|
||||||
|
CommandBuffer commandBuffer,
|
||||||
|
string filePath
|
||||||
|
) {
|
||||||
|
var pixels = Refresh.Refresh_Image_LoadQOIFromFile(
|
||||||
|
filePath,
|
||||||
|
out var width,
|
||||||
|
out var height,
|
||||||
|
out var numChannels
|
||||||
|
);
|
||||||
|
|
||||||
|
var byteCount = (uint) (width * height * numChannels);
|
||||||
|
|
||||||
|
TextureCreateInfo textureCreateInfo = new TextureCreateInfo
|
||||||
|
{
|
||||||
|
Width = (uint) width,
|
||||||
|
Height = (uint) height,
|
||||||
|
Depth = 1,
|
||||||
|
Format = TextureFormat.R8G8B8A8,
|
||||||
|
IsCube = false,
|
||||||
|
LevelCount = 1,
|
||||||
|
SampleCount = SampleCount.One,
|
||||||
|
UsageFlags = TextureUsageFlags.Sampler
|
||||||
|
};
|
||||||
|
|
||||||
|
var texture = new Texture(device, textureCreateInfo);
|
||||||
|
commandBuffer.SetTextureData(texture, pixels, byteCount);
|
||||||
|
|
||||||
|
Refresh.Refresh_Image_FreeQOI(pixels);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads a QOI from a byte array.
|
||||||
|
/// NOTE: You can queue as many of these as you want on to a command buffer but it MUST be submitted!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="device"></param>
|
||||||
|
/// <param name="commandBuffer"></param>
|
||||||
|
/// <param name="filePath"></param>
|
||||||
|
/// <returns>A Texture object.</returns>
|
||||||
|
public unsafe static Texture LoadQOI(
|
||||||
|
GraphicsDevice device,
|
||||||
|
CommandBuffer commandBuffer,
|
||||||
|
byte[] data
|
||||||
|
) {
|
||||||
|
IntPtr pixels;
|
||||||
|
int width, height, numChannels;
|
||||||
|
|
||||||
|
fixed (byte* ptr = &data[0])
|
||||||
|
{
|
||||||
|
pixels = Refresh.Refresh_Image_LoadQOIFromMemory(
|
||||||
|
(nint) ptr,
|
||||||
|
data.Length,
|
||||||
|
out width,
|
||||||
|
out height,
|
||||||
|
out numChannels
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureCreateInfo textureCreateInfo = new TextureCreateInfo
|
||||||
|
{
|
||||||
|
Width = (uint) width,
|
||||||
|
Height = (uint) height,
|
||||||
|
Depth = 1,
|
||||||
|
Format = TextureFormat.R8G8B8A8,
|
||||||
|
IsCube = false,
|
||||||
|
LevelCount = 1,
|
||||||
|
SampleCount = SampleCount.One,
|
||||||
|
UsageFlags = TextureUsageFlags.Sampler
|
||||||
|
};
|
||||||
|
|
||||||
|
var byteCount = (uint) (width * height * numChannels);
|
||||||
|
|
||||||
|
var texture = new Texture(device, textureCreateInfo);
|
||||||
|
commandBuffer.SetTextureData(texture, pixels, byteCount);
|
||||||
|
|
||||||
|
Refresh.Refresh_Image_FreePNG(pixels);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
public static Texture LoadDDS(GraphicsDevice graphicsDevice, CommandBuffer commandBuffer, System.IO.Stream stream)
|
public static Texture LoadDDS(GraphicsDevice graphicsDevice, CommandBuffer commandBuffer, System.IO.Stream stream)
|
||||||
{
|
{
|
||||||
using (var reader = new BinaryReader(stream))
|
using (var reader = new BinaryReader(stream))
|
||||||
|
|
Loading…
Reference in New Issue