update tests for new image loader API
parent
a2d1fea543
commit
c84668b4b3
|
@ -9,6 +9,7 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using MoonWorks;
|
||||
using System.Runtime.InteropServices;
|
||||
using MoonWorks;
|
||||
using MoonWorks.Graphics;
|
||||
using MoonWorks.Math.Float;
|
||||
|
||||
|
@ -14,7 +15,7 @@ namespace MoonWorks.Test
|
|||
private Texture textureSmallCopy;
|
||||
private Sampler sampler;
|
||||
|
||||
public CopyTextureGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||
public unsafe CopyTextureGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||
{
|
||||
// Load the shaders
|
||||
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadVert"));
|
||||
|
@ -69,16 +70,22 @@ namespace MoonWorks.Test
|
|||
}
|
||||
);
|
||||
|
||||
// Load the texture. Copy-pasted from Texture.LoadPNG,
|
||||
// but with the texture bytes stored.
|
||||
var pixels = RefreshCS.Refresh.Refresh_Image_LoadPNGFromFile(
|
||||
TestUtils.GetTexturePath("ravioli.png"),
|
||||
out var width,
|
||||
out var height,
|
||||
out var channels
|
||||
);
|
||||
// Load the texture. Storing the texture bytes so we can compare them.
|
||||
var fileStream = new System.IO.FileStream(TestUtils.GetTexturePath("ravioli.png"), System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||
var fileLength = fileStream.Length;
|
||||
var fileBuffer = NativeMemory.Alloc((nuint) fileLength);
|
||||
var fileSpan = new System.Span<byte>(fileBuffer, (int) fileLength);
|
||||
fileStream.ReadExactly(fileSpan);
|
||||
|
||||
var byteCount = (uint)(width * height * channels);
|
||||
var pixels = RefreshCS.Refresh.Refresh_Image_Load(
|
||||
(nint) fileBuffer,
|
||||
(int) fileLength,
|
||||
out var width,
|
||||
out var height,
|
||||
out var byteCount
|
||||
);
|
||||
|
||||
NativeMemory.Free(fileBuffer);
|
||||
|
||||
TextureCreateInfo textureCreateInfo = new TextureCreateInfo();
|
||||
textureCreateInfo.Width = (uint) width;
|
||||
|
@ -90,12 +97,7 @@ namespace MoonWorks.Test
|
|||
textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler;
|
||||
|
||||
originalTexture = new Texture(GraphicsDevice, textureCreateInfo);
|
||||
cmdbuf.SetTextureData(originalTexture, pixels, byteCount);
|
||||
|
||||
byte[] textureBytes = new byte[byteCount];
|
||||
System.Runtime.InteropServices.Marshal.Copy(pixels, textureBytes, 0, (int) byteCount);
|
||||
|
||||
RefreshCS.Refresh.Refresh_Image_FreePNG(pixels);
|
||||
cmdbuf.SetTextureData(originalTexture, pixels, (uint) byteCount);
|
||||
|
||||
// Create a 1:1 copy of the texture
|
||||
textureCopy = new Texture(GraphicsDevice, textureCreateInfo);
|
||||
|
@ -122,18 +124,18 @@ namespace MoonWorks.Test
|
|||
);
|
||||
|
||||
// Copy the texture to a buffer
|
||||
Buffer compareBuffer = Buffer.Create<byte>(GraphicsDevice, 0, (uint) textureBytes.Length);
|
||||
Buffer compareBuffer = Buffer.Create<byte>(GraphicsDevice, 0, (uint) byteCount);
|
||||
cmdbuf.CopyTextureToBuffer(new TextureSlice(originalTexture), compareBuffer);
|
||||
|
||||
GraphicsDevice.Submit(cmdbuf);
|
||||
GraphicsDevice.Wait();
|
||||
|
||||
// Compare the original bytes to the copied bytes.
|
||||
byte[] copiedBytes = new byte[textureBytes.Length];
|
||||
compareBuffer.GetData(copiedBytes);
|
||||
var copiedBytes = NativeMemory.Alloc((nuint) byteCount);
|
||||
var copiedSpan = new System.Span<byte>(copiedBytes, byteCount);
|
||||
compareBuffer.GetData(copiedSpan);
|
||||
|
||||
var originalSpan = new System.ReadOnlySpan<byte>(textureBytes);
|
||||
var copiedSpan = new System.ReadOnlySpan<byte>(copiedBytes);
|
||||
var originalSpan = new System.Span<byte>((void*) pixels, byteCount);
|
||||
|
||||
if (System.MemoryExtensions.SequenceEqual(originalSpan, copiedSpan))
|
||||
{
|
||||
|
@ -144,6 +146,8 @@ namespace MoonWorks.Test
|
|||
{
|
||||
Logger.LogError("FAIL! Original texture bytes do not match bytes from CopyTextureToBuffer!");
|
||||
}
|
||||
|
||||
RefreshCS.Refresh.Refresh_Image_Free(pixels);
|
||||
}
|
||||
|
||||
protected override void Update(System.TimeSpan delta) { }
|
||||
|
|
|
@ -47,28 +47,17 @@ namespace MoonWorks.Test
|
|||
|
||||
void LoadCubemap(CommandBuffer cmdbuf, string[] imagePaths)
|
||||
{
|
||||
System.IntPtr textureData;
|
||||
int w, h, numChannels;
|
||||
|
||||
for (uint i = 0; i < imagePaths.Length; i++)
|
||||
{
|
||||
textureData = RefreshCS.Refresh.Refresh_Image_LoadPNGFromFile(
|
||||
imagePaths[i],
|
||||
out w,
|
||||
out h,
|
||||
out numChannels
|
||||
);
|
||||
cmdbuf.SetTextureData(
|
||||
new TextureSlice(
|
||||
skyboxTexture,
|
||||
new Rect(0, 0, w, h),
|
||||
0,
|
||||
i
|
||||
),
|
||||
textureData,
|
||||
(uint) (w * h * 4) // w * h * numChannels does not work
|
||||
);
|
||||
RefreshCS.Refresh.Refresh_Image_FreePNG(textureData);
|
||||
var textureSlice = new TextureSlice(
|
||||
skyboxTexture,
|
||||
new Rect(0, 0, (int) skyboxTexture.Width, (int) skyboxTexture.Height),
|
||||
0,
|
||||
i,
|
||||
0
|
||||
);
|
||||
|
||||
Texture.SetDataFromFile(cmdbuf, textureSlice, imagePaths[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,17 +80,11 @@ namespace MoonWorks.Test
|
|||
i
|
||||
);
|
||||
|
||||
var pixels = Refresh.Refresh_Image_LoadPNGFromFile(
|
||||
TestUtils.GetTexturePath($"tex3d_{i}.png"),
|
||||
out var width,
|
||||
out var height,
|
||||
out var channels
|
||||
);
|
||||
|
||||
var byteCount = (uint) (width * height * channels);
|
||||
cmdbuf.SetTextureData(slice, pixels, byteCount);
|
||||
|
||||
Refresh.Refresh_Image_FreePNG(pixels);
|
||||
Texture.SetDataFromFile(
|
||||
cmdbuf,
|
||||
slice,
|
||||
TestUtils.GetTexturePath($"tex3d_{i}.png")
|
||||
);
|
||||
}
|
||||
|
||||
GraphicsDevice.Submit(cmdbuf);
|
||||
|
|
|
@ -80,17 +80,7 @@ namespace MoonWorks.Test
|
|||
(uint) i
|
||||
);
|
||||
|
||||
var pixels = Refresh.Refresh_Image_LoadPNGFromFile(
|
||||
TestUtils.GetTexturePath($"mip{i}.png"),
|
||||
out var width,
|
||||
out var height,
|
||||
out var channels
|
||||
);
|
||||
|
||||
var byteCount = (uint)(width * height * channels);
|
||||
cmdbuf.SetTextureData(slice, pixels, byteCount);
|
||||
|
||||
Refresh.Refresh_Image_FreePNG(pixels);
|
||||
Texture.SetDataFromFile(cmdbuf, slice, TestUtils.GetTexturePath($"mip{i}.png"));
|
||||
}
|
||||
|
||||
GraphicsDevice.Submit(cmdbuf);
|
||||
|
|
|
@ -68,9 +68,8 @@ namespace MoonWorks.Test
|
|||
0, 2, 3,
|
||||
}
|
||||
);
|
||||
texture = Texture.LoadPNG(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
|
||||
texture = Texture.FromFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
|
||||
GraphicsDevice.Submit(cmdbuf);
|
||||
GraphicsDevice.Wait();
|
||||
}
|
||||
|
||||
protected override void Update(System.TimeSpan delta)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>x64</Platforms>
|
||||
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(SolutionDir)NativeAOT_Console.targets" Condition="Exists('$(SolutionDir)NativeAOT_Console.targets')" />
|
||||
|
|
|
@ -25,10 +25,10 @@ namespace MoonWorks.Test
|
|||
private Texture[] textures = new Texture[4];
|
||||
private string[] imageLoadFormatNames = new string[]
|
||||
{
|
||||
"PNGFromFile",
|
||||
"PNGFromMemory",
|
||||
"QOIFromFile",
|
||||
"QOIFromMemory"
|
||||
"PNG from file",
|
||||
"PNG from memory",
|
||||
"QOI from file",
|
||||
"QOI from memory"
|
||||
};
|
||||
|
||||
private int currentTextureIndex;
|
||||
|
@ -94,12 +94,11 @@ namespace MoonWorks.Test
|
|||
0, 2, 3,
|
||||
}
|
||||
);
|
||||
textures[0] = Texture.LoadPNG(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
|
||||
textures[1] = Texture.LoadPNG(GraphicsDevice, cmdbuf, pngBytes);
|
||||
textures[2] = Texture.LoadQOI(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.qoi"));
|
||||
textures[3] = Texture.LoadQOI(GraphicsDevice, cmdbuf, qoiBytes);
|
||||
textures[0] = Texture.FromFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
|
||||
textures[1] = Texture.FromData(GraphicsDevice, cmdbuf, pngBytes);
|
||||
textures[2] = Texture.FromFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.qoi"));
|
||||
textures[3] = Texture.FromData(GraphicsDevice, cmdbuf, qoiBytes);
|
||||
GraphicsDevice.Submit(cmdbuf);
|
||||
GraphicsDevice.Wait();
|
||||
}
|
||||
|
||||
protected override void Update(System.TimeSpan delta)
|
||||
|
|
Loading…
Reference in New Issue