add GetBufferData test and include MoonWorks in the solution

pull/1/head
Caleb Cornett 2022-11-11 22:51:31 -05:00
parent 99e2594f60
commit 95243ef014
4 changed files with 147 additions and 1 deletions

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\MoonWorks\MoonWorks.csproj" />
<ProjectReference Include="..\MoonWorks.Test.Common\MoonWorks.Test.Common.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,109 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
using System.Runtime.InteropServices;
namespace MoonWorks.Test
{
internal class GetBufferDataGame : Game
{
public GetBufferDataGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
PositionColorVertex[] vertices = new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(0, 0, 0), Color.Red),
new PositionColorVertex(new Vector3(0, 0, 1), Color.Green),
new PositionColorVertex(new Vector3(0, 1, 0), Color.Blue),
new PositionColorVertex(new Vector3(0, 1, 1), Color.Yellow),
new PositionColorVertex(new Vector3(1, 0, 0), Color.Orange),
new PositionColorVertex(new Vector3(1, 0, 1), Color.Brown),
new PositionColorVertex(new Vector3(1, 1, 0), Color.Black),
new PositionColorVertex(new Vector3(1, 1, 1), Color.White),
};
PositionColorVertex[] otherVerts = new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(0.5f, 0.5f, 0.5f), Color.Fuchsia),
new PositionColorVertex(new Vector3(0.1f, 0.1f, 0.1f), Color.LightCoral),
new PositionColorVertex(new Vector3(0.2f, 0.2f, 0.2f), Color.Lime)
};
int vertexSize = Marshal.SizeOf<PositionColorVertex>();
Buffer vertexBuffer = Buffer.Create<PositionColorVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
(uint) vertices.Length
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(vertexBuffer, vertices);
GraphicsDevice.Submit(cmdbuf);
// Wait for the vertices to finish uploading...
GraphicsDevice.Wait();
// Read back and print out the vertex values
PositionColorVertex[] readbackVertices = new PositionColorVertex[vertices.Length];
vertexBuffer.GetData(
readbackVertices,
(uint) (readbackVertices.Length * vertexSize) // FIXME: Seems like this should get auto-calculated somehow
);
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
// Change the first three vertices
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(vertexBuffer, otherVerts);
GraphicsDevice.Submit(cmdbuf);
GraphicsDevice.Wait();
// Read the updated buffer
vertexBuffer.GetData(
readbackVertices,
(uint) (vertexSize * readbackVertices.Length)
);
Logger.LogInfo("===");
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
// Change the last two vertices
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
otherVerts,
(uint) (vertexSize * (vertices.Length - 2)),
1,
2
);
GraphicsDevice.Submit(cmdbuf);
GraphicsDevice.Wait();
// Read the updated buffer
vertexBuffer.GetData(
readbackVertices,
(uint) (readbackVertices.Length * vertexSize)
);
Logger.LogInfo("===");
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
}
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha) { }
public static void Main(string[] args)
{
GetBufferDataGame game = new GetBufferDataGame();
game.Run();
}
}
}

View File

@ -15,6 +15,11 @@ namespace MoonWorks.Test
Position = position; Position = position;
Color = color; Color = color;
} }
public override string ToString()
{
return Position + " | " + Color;
}
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
@ -28,5 +33,10 @@ namespace MoonWorks.Test
Position = position; Position = position;
TexCoord = texCoord; TexCoord = texCoord;
} }
public override string ToString()
{
return Position + " | " + TexCoord;
}
} }
} }

View File

@ -21,6 +21,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TexturedQuad", "TexturedQua
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TriangleVertexBuffer", "TriangleVertexBuffer\TriangleVertexBuffer.csproj", "{7EC935B1-DCD1-4ADD-96C8-614B4CA76501}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TriangleVertexBuffer", "TriangleVertexBuffer\TriangleVertexBuffer.csproj", "{7EC935B1-DCD1-4ADD-96C8-614B4CA76501}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GetBufferData", "GetBufferData\GetBufferData.csproj", "{37BDB4E6-FCDC-4F04-A9E3-C6B9D6C3AB4E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonWorks", "..\MoonWorks\MoonWorks.csproj", "{1695B1D8-4935-490C-A5EC-E2F2AA94B150}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
@ -63,6 +67,14 @@ Global
{7EC935B1-DCD1-4ADD-96C8-614B4CA76501}.Debug|x64.Build.0 = Debug|x64 {7EC935B1-DCD1-4ADD-96C8-614B4CA76501}.Debug|x64.Build.0 = Debug|x64
{7EC935B1-DCD1-4ADD-96C8-614B4CA76501}.Release|x64.ActiveCfg = Release|x64 {7EC935B1-DCD1-4ADD-96C8-614B4CA76501}.Release|x64.ActiveCfg = Release|x64
{7EC935B1-DCD1-4ADD-96C8-614B4CA76501}.Release|x64.Build.0 = Release|x64 {7EC935B1-DCD1-4ADD-96C8-614B4CA76501}.Release|x64.Build.0 = Release|x64
{37BDB4E6-FCDC-4F04-A9E3-C6B9D6C3AB4E}.Debug|x64.ActiveCfg = Debug|x64
{37BDB4E6-FCDC-4F04-A9E3-C6B9D6C3AB4E}.Debug|x64.Build.0 = Debug|x64
{37BDB4E6-FCDC-4F04-A9E3-C6B9D6C3AB4E}.Release|x64.ActiveCfg = Release|x64
{37BDB4E6-FCDC-4F04-A9E3-C6B9D6C3AB4E}.Release|x64.Build.0 = Release|x64
{1695B1D8-4935-490C-A5EC-E2F2AA94B150}.Debug|x64.ActiveCfg = Debug|x64
{1695B1D8-4935-490C-A5EC-E2F2AA94B150}.Debug|x64.Build.0 = Debug|x64
{1695B1D8-4935-490C-A5EC-E2F2AA94B150}.Release|x64.ActiveCfg = Release|x64
{1695B1D8-4935-490C-A5EC-E2F2AA94B150}.Release|x64.Build.0 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE