set up test

main
cosmonaut 2021-01-19 20:08:29 -08:00
parent f728288558
commit b6f8bd8c97
17 changed files with 410 additions and 20 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
bin/
obj/
.vs/

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "lib/MoonWorks"]
path = lib/MoonWorks
url = https://gitea.moonside.games/MoonsideGames/MoonWorks.git

BIN
Content/hexagon_grid.spv Normal file

Binary file not shown.

BIN
Content/noise.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 KiB

Binary file not shown.

BIN
Content/woodgrain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

19
CopyMoonlibs.targets Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Content Include=".\moonlibs\windows\**\*.*" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true' AND '$(Platform)' != 'x86'">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include=".\moonlibs\osx\**\*.*" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'" >
<Link>osx\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include=".\moonlibs\lib64\**\*.*" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'" >
<Link>lib64\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -17,4 +17,10 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\lib\MoonWorks\MoonWorks.csproj" />
</ItemGroup>
<Import Project=".\CopyMoonlibs.targets"/>
</Project>

View File

@ -1,34 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoonWorksTest", "MoonWorksTest.csproj", "{D03DE2E4-7731-4E13-B3DC-DB94F4156681}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonWorksTest", "MoonWorksTest.csproj", "{D03DE2E4-7731-4E13-B3DC-DB94F4156681}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonWorks", "lib\MoonWorks\MoonWorks.csproj", "{38EE757C-50C0-4ABF-851D-45586C1077A1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FAudio-CS.Core", "lib\MoonWorks\lib\FAudio\csharp\FAudio-CS.Core.csproj", "{3C123688-D3E5-48D7-8003-DDA4E93BFE6E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RefreshCS", "lib\MoonWorks\lib\RefreshCS\RefreshCS.csproj", "{1EF0BDFD-5583-41DE-9BF4-9E7112651D12}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2-CS.Core", "lib\MoonWorks\lib\SDL2-CS\SDL2-CS.Core.csproj", "{C0759474-25B1-4F51-AE5E-1E1F424BAC89}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Debug|x64.ActiveCfg = Debug|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Debug|x64.Build.0 = Debug|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Release|x64.ActiveCfg = Release|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Release|x64.Build.0 = Release|x64
{38EE757C-50C0-4ABF-851D-45586C1077A1}.Debug|x64.ActiveCfg = Debug|x64
{38EE757C-50C0-4ABF-851D-45586C1077A1}.Debug|x64.Build.0 = Debug|x64
{38EE757C-50C0-4ABF-851D-45586C1077A1}.Release|x64.ActiveCfg = Release|x64
{38EE757C-50C0-4ABF-851D-45586C1077A1}.Release|x64.Build.0 = Release|x64
{3C123688-D3E5-48D7-8003-DDA4E93BFE6E}.Debug|x64.ActiveCfg = Debug|x64
{3C123688-D3E5-48D7-8003-DDA4E93BFE6E}.Debug|x64.Build.0 = Debug|x64
{3C123688-D3E5-48D7-8003-DDA4E93BFE6E}.Release|x64.ActiveCfg = Release|x64
{3C123688-D3E5-48D7-8003-DDA4E93BFE6E}.Release|x64.Build.0 = Release|x64
{1EF0BDFD-5583-41DE-9BF4-9E7112651D12}.Debug|x64.ActiveCfg = Debug|x64
{1EF0BDFD-5583-41DE-9BF4-9E7112651D12}.Debug|x64.Build.0 = Debug|x64
{1EF0BDFD-5583-41DE-9BF4-9E7112651D12}.Release|x64.ActiveCfg = Release|x64
{1EF0BDFD-5583-41DE-9BF4-9E7112651D12}.Release|x64.Build.0 = Release|x64
{C0759474-25B1-4F51-AE5E-1E1F424BAC89}.Debug|x64.ActiveCfg = Debug|x64
{C0759474-25B1-4F51-AE5E-1E1F424BAC89}.Debug|x64.Build.0 = Debug|x64
{C0759474-25B1-4F51-AE5E-1E1F424BAC89}.Release|x64.ActiveCfg = Release|x64
{C0759474-25B1-4F51-AE5E-1E1F424BAC89}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Debug|Any CPU.ActiveCfg = Debug|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Debug|Any CPU.Build.0 = Debug|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Debug|x64.ActiveCfg = Debug|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Debug|x64.Build.0 = Debug|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Debug|x86.ActiveCfg = Debug|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Debug|x86.Build.0 = Debug|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Release|Any CPU.ActiveCfg = Release|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Release|Any CPU.Build.0 = Release|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Release|x64.ActiveCfg = Release|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Release|x64.Build.0 = Release|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Release|x86.ActiveCfg = Release|x64
{D03DE2E4-7731-4E13-B3DC-DB94F4156681}.Release|x86.Build.0 = Release|x64
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7DA782A1-7B3E-42D2-B4EF-EDB951E06A13}
EndGlobalSection
EndGlobal

1
lib/MoonWorks Submodule

@ -0,0 +1 @@
Subproject commit 408e438efcf8a19992c3b0ecd74bfd11b65441e6

BIN
moonlibs/windows/FAudio.dll Normal file

Binary file not shown.

Binary file not shown.

BIN
moonlibs/windows/SDL2.dll Normal file

Binary file not shown.

20
src/Program.cs Normal file
View File

@ -0,0 +1,20 @@
using MoonWorks;
namespace MoonWorksTest
{
class Program
{
static void Main(string[] args)
{
WindowCreateInfo windowCreateInfo = new WindowCreateInfo
{
WindowWidth = 1280,
WindowHeight = 720,
ScreenMode = ScreenMode.Windowed
};
TestGame game = new TestGame(windowCreateInfo, PresentMode.FIFO, 60, true);
game.Run();
}
}
}

11
src/RaymarchUniforms.cs Normal file
View File

@ -0,0 +1,11 @@
using System.Runtime.InteropServices;
namespace MoonWorksTest
{
[StructLayout(LayoutKind.Sequential)]
struct RaymarchUniforms
{
public float time, padding;
public float resolutionX, resolutionY;
}
}

303
src/TestGame.cs Normal file
View File

@ -0,0 +1,303 @@
using MoonWorks;
using MoonWorks.Graphics;
using RefreshCS;
using System.Threading;
namespace MoonWorksTest
{
public class TestGame : Game
{
ShaderModule passthroughVertexShaderModule;
ShaderModule raymarchFragmentShaderModule;
RaymarchUniforms raymarchUniforms;
Texture woodTexture;
Texture noiseTexture;
Sampler sampler;
Buffer vertexBuffer;
RefreshCS.Refresh.Rect renderArea;
RefreshCS.Refresh.Rect flip;
RefreshCS.Refresh.Color clearColor;
Texture mainColorTargetTexture;
TextureSlice mainColorTargetTextureSlice;
ColorTarget mainColorTarget;
RenderPass mainRenderPass;
Framebuffer mainFramebuffer;
GraphicsPipeline mainGraphicsPipeline;
byte[] screenshotPixels;
Buffer screenshotBuffer;
uint screenShotBufferSize;
Thread screenshotThread;
public TestGame(WindowCreateInfo windowCreateInfo, PresentMode presentMode, int targetTimestep = 60, bool debugMode = false) : base(windowCreateInfo, presentMode, targetTimestep, debugMode)
{
var windowWidth = windowCreateInfo.WindowWidth;
var windowHeight = windowCreateInfo.WindowHeight;
passthroughVertexShaderModule = new ShaderModule(GraphicsDevice, new System.IO.FileInfo("Content/passthrough_vert.spv"));
raymarchFragmentShaderModule = new ShaderModule(GraphicsDevice, new System.IO.FileInfo("Content/hexagon_grid.spv"));
raymarchUniforms.time = 0;
raymarchUniforms.padding = 0;
raymarchUniforms.resolutionX = windowWidth;
raymarchUniforms.resolutionY = windowHeight;
woodTexture = Texture.LoadPNG(GraphicsDevice, new System.IO.FileInfo("Content/woodgrain.png"));
noiseTexture = Texture.LoadPNG(GraphicsDevice, new System.IO.FileInfo("Content/noise.png"));
SamplerState samplerState = SamplerState.LinearWrap;
sampler = new Sampler(GraphicsDevice, ref samplerState);
/* Load Vertex Data */
var vertices = new Vertex[3];
vertices[0].x = -1;
vertices[0].y = -1;
vertices[0].z = 0;
vertices[0].u = 0;
vertices[0].v = 1;
vertices[1].x = 3;
vertices[1].y = -1;
vertices[1].z = 0;
vertices[1].u = 1;
vertices[1].v = 1;
vertices[2].x = -1;
vertices[2].y = 3;
vertices[2].z = 0;
vertices[2].u = 0;
vertices[2].v = 0;
vertexBuffer = new Buffer(GraphicsDevice, Refresh.BufferUsageFlags.Vertex, 4 * 5 * 3);
vertexBuffer.SetData(0, vertices, 4 * 5 * 3);
/* Render Pass */
renderArea.x = 0;
renderArea.y = 0;
renderArea.w = (int) windowWidth;
renderArea.h = (int) windowHeight;
flip.x = 0;
flip.y = (int) windowHeight;
flip.w = (int) windowWidth;
flip.h = -(int) windowHeight;
clearColor.r = 237;
clearColor.g = 41;
clearColor.b = 57;
clearColor.a = byte.MaxValue;
Refresh.ColorTargetDescription colorTargetDescription = new Refresh.ColorTargetDescription
{
format = Refresh.ColorFormat.R8G8B8A8,
multisampleCount = Refresh.SampleCount.One,
loadOp = Refresh.LoadOp.Clear,
storeOp = Refresh.StoreOp.Store
};
mainRenderPass = new RenderPass(GraphicsDevice, colorTargetDescription);
mainColorTargetTexture = Texture.CreateTexture2D(
GraphicsDevice,
windowWidth,
windowHeight,
Refresh.ColorFormat.R8G8B8A8,
Refresh.TextureUsageFlags.ColorTargetBit
);
mainColorTargetTextureSlice = new TextureSlice(mainColorTargetTexture);
mainColorTarget = new ColorTarget(GraphicsDevice, Refresh.SampleCount.One, ref mainColorTargetTextureSlice);
mainFramebuffer = new Framebuffer(
GraphicsDevice,
windowWidth,
windowHeight,
mainRenderPass,
null,
mainColorTarget
);
/* Pipeline */
ColorTargetBlendState[] colorTargetBlendStates = new ColorTargetBlendState[1]
{
ColorTargetBlendState.None
};
ColorBlendState colorBlendState = new ColorBlendState
{
LogicOpEnable = false,
LogicOp = Refresh.LogicOp.NoOp,
BlendConstants = new BlendConstants(),
ColorTargetBlendStates = colorTargetBlendStates
};
DepthStencilState depthStencilState = DepthStencilState.Disable;
ShaderStageState vertexShaderState = new ShaderStageState
{
ShaderModule = passthroughVertexShaderModule,
EntryPointName = "main",
UniformBufferSize = 0
};
ShaderStageState fragmentShaderState = new ShaderStageState
{
ShaderModule = raymarchFragmentShaderModule,
EntryPointName = "main",
UniformBufferSize = 4
};
MultisampleState multisampleState = MultisampleState.None;
GraphicsPipelineLayoutCreateInfo pipelineLayoutCreateInfo = new GraphicsPipelineLayoutCreateInfo
{
VertexSamplerBindingCount = 0,
FragmentSamplerBindingCount = 2
};
RasterizerState rasterizerState = RasterizerState.CullCounterClockwise;
var vertexBindings = new Refresh.VertexBinding[1]
{
new Refresh.VertexBinding
{
binding = 0,
inputRate = Refresh.VertexInputRate.Vertex,
stride = 4 * 5
}
};
var vertexAttributes = new Refresh.VertexAttribute[2]
{
new Refresh.VertexAttribute
{
binding = 0,
location = 0,
format = Refresh.VertexElementFormat.Vector3,
offset = 0
},
new Refresh.VertexAttribute
{
binding = 0,
location = 1,
format = Refresh.VertexElementFormat.Vector2,
offset = 4 * 3
}
};
VertexInputState vertexInputState = new VertexInputState
{
VertexBindings = vertexBindings,
VertexAttributes = vertexAttributes
};
var viewports = new Refresh.Viewport[1]
{
new Refresh.Viewport
{
x = 0,
y = 0,
w = windowWidth,
h = windowHeight,
minDepth = 0,
maxDepth = 1
}
};
var scissors = new Refresh.Rect[1]
{
new Refresh.Rect
{
x = 0,
y = 0,
w = (int) windowWidth,
h = (int) windowHeight
}
};
ViewportState viewportState = new ViewportState
{
Viewports = viewports,
Scissors = scissors
};
mainGraphicsPipeline = new GraphicsPipeline(
GraphicsDevice,
colorBlendState,
depthStencilState,
vertexShaderState,
fragmentShaderState,
multisampleState,
pipelineLayoutCreateInfo,
rasterizerState,
Refresh.PrimitiveType.TriangleList,
vertexInputState,
viewportState,
mainRenderPass
);
screenShotBufferSize = windowWidth * windowHeight * 4;
screenshotPixels = new byte[screenShotBufferSize];
screenshotBuffer = new Buffer(GraphicsDevice, 0, screenShotBufferSize);
screenshotThread = new Thread(new ThreadStart(SaveScreenshot));
}
protected override void Update(double dt)
{
raymarchUniforms.time += (float) dt;
}
protected override void Draw()
{
var screenshotPressed = Input.Keyboard.IsPressed(Keycode.S);
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
commandBuffer.BeginRenderPass(
mainRenderPass,
mainFramebuffer,
ref renderArea,
clearColor
);
commandBuffer.BindGraphicsPipeline(mainGraphicsPipeline);
var fragmentParamOffset = commandBuffer.PushFragmentShaderParams(raymarchUniforms);
commandBuffer.BindVertexBuffers(0, new BufferBinding(vertexBuffer, 0));
commandBuffer.BindFragmentSamplers(
new TextureSamplerBinding(woodTexture, sampler),
new TextureSamplerBinding(noiseTexture, sampler)
);
commandBuffer.DrawPrimitives(0, 1, 0, fragmentParamOffset);
commandBuffer.EndRenderPass();
if (screenshotPressed)
{
commandBuffer.CopyTextureToBuffer(ref mainColorTargetTextureSlice, screenshotBuffer);
}
commandBuffer.QueuePresent(ref mainColorTargetTextureSlice, ref flip, Refresh.Filter.Nearest);
GraphicsDevice.Submit(commandBuffer);
if (screenshotPressed)
{
screenshotThread.Start();
}
}
private void SaveScreenshot()
{
GraphicsDevice.Wait();
screenshotBuffer.GetData(screenshotPixels, screenShotBufferSize);
Texture.SavePNG("screenshot.png", 1280, 720, screenshotPixels);
}
}
}

11
src/Vertex.cs Normal file
View File

@ -0,0 +1,11 @@
using System.Runtime.InteropServices;
namespace MoonWorksTest
{
[StructLayout(LayoutKind.Sequential)]
struct Vertex
{
public float x, y, z;
public float u, v;
}
}