update tests for QOI support

pull/2/head
cosmonaut 2023-04-03 23:13:37 -07:00
parent c9d929dc1f
commit 129421e80a
4 changed files with 55 additions and 17 deletions

View File

@ -71,7 +71,7 @@ namespace MoonWorks.Test
// Load the texture. Copy-pasted from Texture.LoadPNG,
// but with the texture bytes stored.
var pixels = RefreshCS.Refresh.Refresh_Image_Load(
var pixels = RefreshCS.Refresh.Refresh_Image_LoadPNGFromFile(
TestUtils.GetTexturePath("ravioli.png"),
out var width,
out var height,
@ -95,7 +95,7 @@ namespace MoonWorks.Test
byte[] textureBytes = new byte[byteCount];
System.Runtime.InteropServices.Marshal.Copy(pixels, textureBytes, 0, (int) byteCount);
RefreshCS.Refresh.Refresh_Image_Free(pixels);
RefreshCS.Refresh.Refresh_Image_FreePNG(pixels);
// Create a 1:1 copy of the texture
textureCopy = new Texture(GraphicsDevice, textureCreateInfo);
@ -129,20 +129,22 @@ namespace MoonWorks.Test
GraphicsDevice.Wait();
// Compare the original bytes to the copied bytes.
// Doing a manual equality check per byte because I can't find a way to memcmp in C#.
byte[] copiedBytes = new byte[textureBytes.Length];
compareBuffer.GetData<byte>(copiedBytes, (uint) copiedBytes.Length);
for (int i = 0; i < copiedBytes.Length; i += 1)
var originalSpan = new System.ReadOnlySpan<byte>(textureBytes);
var copiedSpan = new System.ReadOnlySpan<byte>(copiedBytes);
if (System.MemoryExtensions.SequenceEqual(originalSpan, copiedSpan))
{
if (textureBytes[i] != copiedBytes[i])
Logger.LogError("SUCCESS! Original texture bytes and the bytes from CopyTextureToBuffer match!");
}
else
{
Logger.LogError("FAIL! Original texture bytes do not match bytes from CopyTextureToBuffer!");
return;
}
}
Logger.LogError("SUCCESS! Original texture bytes and the bytes from CopyTextureToBuffer match!");
}
protected override void Update(System.TimeSpan delta) { }

View File

@ -52,7 +52,7 @@ namespace MoonWorks.Test
for (uint i = 0; i < imagePaths.Length; i++)
{
textureData = RefreshCS.Refresh.Refresh_Image_Load(
textureData = RefreshCS.Refresh.Refresh_Image_LoadPNGFromFile(
imagePaths[i],
out w,
out h,
@ -68,7 +68,7 @@ namespace MoonWorks.Test
textureData,
(uint) (w * h * 4) // w * h * numChannels does not work
);
RefreshCS.Refresh.Refresh_Image_Free(textureData);
RefreshCS.Refresh.Refresh_Image_FreePNG(textureData);
}
}

Binary file not shown.

View File

@ -9,7 +9,6 @@ namespace MoonWorks.Test
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture texture;
private Sampler[] samplers = new Sampler[6];
private string[] samplerNames = new string[]
{
@ -23,11 +22,33 @@ namespace MoonWorks.Test
private int currentSamplerIndex;
private Texture[] textures = new Texture[4];
private string[] imageLoadFormatNames = new string[]
{
"PNGFromFile",
"PNGFromMemory",
"QOIFromFile",
"QOIFromMemory"
};
private int currentTextureIndex;
private System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
public TexturedQuadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between sampler states");
Logger.LogInfo("Setting sampler state to: " + samplerNames[0]);
Logger.LogInfo("Press Down to cycle between image load formats");
Logger.LogInfo("Setting image format to: " + imageLoadFormatNames[0]);
var pngBytes = System.IO.File.ReadAllBytes(TestUtils.GetTexturePath("ravioli.png"));
var qoiBytes = System.IO.File.ReadAllBytes(TestUtils.GetTexturePath("ravioli.qoi"));
Logger.LogInfo(pngBytes.Length.ToString());
Logger.LogInfo(qoiBytes.Length.ToString());
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadVert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadFrag"));
@ -73,7 +94,10 @@ namespace MoonWorks.Test
0, 2, 3,
}
);
texture = Texture.LoadPNG(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
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);
GraphicsDevice.Submit(cmdbuf);
GraphicsDevice.Wait();
}
@ -104,6 +128,18 @@ namespace MoonWorks.Test
{
Logger.LogInfo("Setting sampler state to: " + samplerNames[currentSamplerIndex]);
}
int prevTextureIndex = currentTextureIndex;
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
{
currentTextureIndex = (currentTextureIndex + 1) % imageLoadFormatNames.Length;
}
if (prevTextureIndex != currentTextureIndex)
{
Logger.LogInfo("Setting texture format to: " + imageLoadFormatNames[currentTextureIndex]);
}
}
protected override void Draw(double alpha)
@ -116,7 +152,7 @@ namespace MoonWorks.Test
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, samplers[currentSamplerIndex]));
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textures[currentTextureIndex], samplers[currentSamplerIndex]));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.EndRenderPass();
}