update tests for QOI support
parent
c9d929dc1f
commit
129421e80a
|
@ -71,7 +71,7 @@ namespace MoonWorks.Test
|
||||||
|
|
||||||
// Load the texture. Copy-pasted from Texture.LoadPNG,
|
// Load the texture. Copy-pasted from Texture.LoadPNG,
|
||||||
// but with the texture bytes stored.
|
// but with the texture bytes stored.
|
||||||
var pixels = RefreshCS.Refresh.Refresh_Image_Load(
|
var pixels = RefreshCS.Refresh.Refresh_Image_LoadPNGFromFile(
|
||||||
TestUtils.GetTexturePath("ravioli.png"),
|
TestUtils.GetTexturePath("ravioli.png"),
|
||||||
out var width,
|
out var width,
|
||||||
out var height,
|
out var height,
|
||||||
|
@ -95,7 +95,7 @@ namespace MoonWorks.Test
|
||||||
byte[] textureBytes = new byte[byteCount];
|
byte[] textureBytes = new byte[byteCount];
|
||||||
System.Runtime.InteropServices.Marshal.Copy(pixels, textureBytes, 0, (int) 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
|
// Create a 1:1 copy of the texture
|
||||||
textureCopy = new Texture(GraphicsDevice, textureCreateInfo);
|
textureCopy = new Texture(GraphicsDevice, textureCreateInfo);
|
||||||
|
@ -129,20 +129,22 @@ namespace MoonWorks.Test
|
||||||
GraphicsDevice.Wait();
|
GraphicsDevice.Wait();
|
||||||
|
|
||||||
// Compare the original bytes to the copied bytes.
|
// 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];
|
byte[] copiedBytes = new byte[textureBytes.Length];
|
||||||
compareBuffer.GetData<byte>(copiedBytes, (uint) copiedBytes.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!");
|
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) { }
|
protected override void Update(System.TimeSpan delta) { }
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace MoonWorks.Test
|
||||||
|
|
||||||
for (uint i = 0; i < imagePaths.Length; i++)
|
for (uint i = 0; i < imagePaths.Length; i++)
|
||||||
{
|
{
|
||||||
textureData = RefreshCS.Refresh.Refresh_Image_Load(
|
textureData = RefreshCS.Refresh.Refresh_Image_LoadPNGFromFile(
|
||||||
imagePaths[i],
|
imagePaths[i],
|
||||||
out w,
|
out w,
|
||||||
out h,
|
out h,
|
||||||
|
@ -68,7 +68,7 @@ namespace MoonWorks.Test
|
||||||
textureData,
|
textureData,
|
||||||
(uint) (w * h * 4) // w * h * numChannels does not work
|
(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.
|
@ -9,7 +9,6 @@ namespace MoonWorks.Test
|
||||||
private GraphicsPipeline pipeline;
|
private GraphicsPipeline pipeline;
|
||||||
private Buffer vertexBuffer;
|
private Buffer vertexBuffer;
|
||||||
private Buffer indexBuffer;
|
private Buffer indexBuffer;
|
||||||
private Texture texture;
|
|
||||||
private Sampler[] samplers = new Sampler[6];
|
private Sampler[] samplers = new Sampler[6];
|
||||||
private string[] samplerNames = new string[]
|
private string[] samplerNames = new string[]
|
||||||
{
|
{
|
||||||
|
@ -23,11 +22,33 @@ namespace MoonWorks.Test
|
||||||
|
|
||||||
private int currentSamplerIndex;
|
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)
|
public TexturedQuadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||||
{
|
{
|
||||||
Logger.LogInfo("Press Left and Right to cycle between sampler states");
|
Logger.LogInfo("Press Left and Right to cycle between sampler states");
|
||||||
Logger.LogInfo("Setting sampler state to: " + samplerNames[0]);
|
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
|
// Load the shaders
|
||||||
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadVert"));
|
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadVert"));
|
||||||
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadFrag"));
|
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadFrag"));
|
||||||
|
@ -73,7 +94,10 @@ namespace MoonWorks.Test
|
||||||
0, 2, 3,
|
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.Submit(cmdbuf);
|
||||||
GraphicsDevice.Wait();
|
GraphicsDevice.Wait();
|
||||||
}
|
}
|
||||||
|
@ -104,6 +128,18 @@ namespace MoonWorks.Test
|
||||||
{
|
{
|
||||||
Logger.LogInfo("Setting sampler state to: " + samplerNames[currentSamplerIndex]);
|
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)
|
protected override void Draw(double alpha)
|
||||||
|
@ -116,7 +152,7 @@ namespace MoonWorks.Test
|
||||||
cmdbuf.BindGraphicsPipeline(pipeline);
|
cmdbuf.BindGraphicsPipeline(pipeline);
|
||||||
cmdbuf.BindVertexBuffers(vertexBuffer);
|
cmdbuf.BindVertexBuffers(vertexBuffer);
|
||||||
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
|
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.DrawIndexedPrimitives(0, 0, 2, 0, 0);
|
||||||
cmdbuf.EndRenderPass();
|
cmdbuf.EndRenderPass();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue