Compare commits

..

1 Commits

Author SHA1 Message Date
cosmonaut 3d5731f40d trying out QOA 2023-05-04 00:57:47 -07:00
14 changed files with 114 additions and 70 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
*.ogg filter=lfs diff=lfs merge=lfs -text
*.qoa filter=lfs diff=lfs merge=lfs -text

24
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net7.0/MoonWorksTest.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

42
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MoonWorksTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/MoonWorksTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/MoonWorksTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

BIN
Content/housecleaning_herbal_mix.ogg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/housecleaning_herbal_mix.qoa (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>MoonWorksTest</RootNamespace> <RootNamespace>MoonWorksTest</RootNamespace>
<Platforms>x64</Platforms> <Platforms>x64</Platforms>

@ -1 +1 @@
Subproject commit 111df04c0f7be740108cc3536eda3629572714d8 Subproject commit a869a0e958fd307a2883d111489ea7c49793baf6

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,12 +1,15 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MoonWorks.Math; using MoonWorks.Graphics;
using MoonWorks.Math.Float;
namespace MoonWorksTest namespace MoonWorksTest
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct PositionTexture struct PositionTexture : MoonWorks.Graphics.IVertexType
{ {
public Vector3 Position; public Vector3 Position;
public Vector2 Texture; public Vector2 Texture;
}
public static VertexElementFormat[] Formats => new VertexElementFormat[] { VertexElementFormat.Vector3, VertexElementFormat.Vector2 };
}
} }

View File

@ -15,9 +15,14 @@ namespace MoonWorksTest
ScreenMode = ScreenMode.Windowed ScreenMode = ScreenMode.Windowed
}; };
TestGame game = new TestGame( FrameLimiterSettings limiterSettings = new FrameLimiterSettings
{
Mode = FrameLimiterMode.Uncapped
};
TestGame game = new TestGame(
windowCreateInfo, windowCreateInfo,
PresentMode.FIFO, limiterSettings,
60, 60,
true true
); );

View File

@ -23,23 +23,17 @@ namespace MoonWorksTest
GraphicsPipeline mainGraphicsPipeline; GraphicsPipeline mainGraphicsPipeline;
byte[] screenshotPixels;
Buffer screenshotBuffer;
uint screenshotBufferSize;
StaticSound music; StaticSound music;
StaticSoundInstance musicInstance; StaticSoundInstance musicInstance;
StreamingSoundOgg musicStream; StreamingSoundOgg musicStream;
bool screenshotInProgress = false; public TestGame(WindowCreateInfo windowCreateInfo, FrameLimiterSettings limiterSettings, int targetTimestep = 60, bool debugMode = false) : base(windowCreateInfo, limiterSettings, targetTimestep, debugMode)
public TestGame(WindowCreateInfo windowCreateInfo, PresentMode presentMode, int targetTimestep = 60, bool debugMode = false) : base(windowCreateInfo, presentMode, targetTimestep, debugMode)
{ {
var windowWidth = windowCreateInfo.WindowWidth; var windowWidth = windowCreateInfo.WindowWidth;
var windowHeight = windowCreateInfo.WindowHeight; var windowHeight = windowCreateInfo.WindowHeight;
passthroughVertexShaderModule = new ShaderModule(GraphicsDevice, Path.Combine("Content", "passthrough_vert.spv")); //passthroughVertexShaderModule = new ShaderModule(GraphicsDevice, Path.Combine("Content", "passthrough_vert.spv"));
raymarchFragmentShaderModule = new ShaderModule(GraphicsDevice, Path.Combine("Content", "hexagon_grid.spv")); //raymarchFragmentShaderModule = new ShaderModule(GraphicsDevice, Path.Combine("Content", "hexagon_grid.spv"));
raymarchUniforms.time = 0; raymarchUniforms.time = 0;
raymarchUniforms.padding = 0; raymarchUniforms.padding = 0;
@ -48,8 +42,8 @@ namespace MoonWorksTest
var uploadCommandBuffer = GraphicsDevice.AcquireCommandBuffer(); var uploadCommandBuffer = GraphicsDevice.AcquireCommandBuffer();
woodTexture = Texture.LoadPNG(GraphicsDevice, uploadCommandBuffer, "Content/woodgrain.png"); woodTexture = Texture.FromImageFile(GraphicsDevice, uploadCommandBuffer, "Content/woodgrain.png");
noiseTexture = Texture.LoadPNG(GraphicsDevice, uploadCommandBuffer, "Content/noise.png"); noiseTexture = Texture.FromImageFile(GraphicsDevice, uploadCommandBuffer, "Content/noise.png");
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap); sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap);
@ -81,54 +75,51 @@ namespace MoonWorksTest
/* Pipeline */ /* Pipeline */
/*
mainGraphicsPipeline = new GraphicsPipeline( mainGraphicsPipeline = new GraphicsPipeline(
GraphicsDevice, GraphicsDevice,
new GraphicsPipelineCreateInfo new GraphicsPipelineCreateInfo
{ {
AttachmentInfo = new GraphicsPipelineAttachmentInfo( AttachmentInfo = new GraphicsPipelineAttachmentInfo(
new ColorAttachmentDescription( new ColorAttachmentDescription(
GraphicsDevice.GetSwapchainFormat(Window), MainWindow.SwapchainFormat,
ColorAttachmentBlendState.None ColorAttachmentBlendState.None
) )
), ),
DepthStencilState = DepthStencilState.Disable, DepthStencilState = DepthStencilState.Disable,
VertexShaderInfo = GraphicsShaderInfo.Create(passthroughVertexShaderModule, "main", 0), VertexShaderInfo = GraphicsShaderInfo.Create(passthroughVertexShaderModule, "main", 0),
VertexInputState = new VertexInputState( VertexInputState = VertexInputState.CreateSingleBinding<PositionTexture>(),
VertexBinding.Create<PositionTexture>(),
VertexAttribute.Create<PositionTexture>("Position", 0),
VertexAttribute.Create<PositionTexture>("Texture", 1)
),
PrimitiveType = PrimitiveType.TriangleList, PrimitiveType = PrimitiveType.TriangleList,
FragmentShaderInfo = GraphicsShaderInfo.Create<RaymarchUniforms>(raymarchFragmentShaderModule, "main", 2), FragmentShaderInfo = GraphicsShaderInfo.Create<RaymarchUniforms>(raymarchFragmentShaderModule, "main", 2),
RasterizerState = RasterizerState.CW_CullBack, RasterizerState = RasterizerState.CW_CullBack,
ViewportState = new ViewportState((int)Window.Width, (int)Window.Height),
MultisampleState = MultisampleState.None MultisampleState = MultisampleState.None
} }
); );
*/
screenshotBufferSize = windowWidth * windowHeight * 4; // music = StaticSound.LoadOgg(AudioDevice, Path.Combine("Content", "title_screen.ogg"));
screenshotPixels = new byte[screenshotBufferSize]; // musicInstance = music.CreateInstance();
screenshotBuffer = new Buffer(GraphicsDevice, 0, screenshotBufferSize);
music = StaticSound.LoadOgg(AudioDevice, Path.Combine("Content", "title_screen.ogg"));
musicInstance = music.CreateInstance();
// musicInstance.Play(); // musicInstance.Play();
musicStream = StreamingSoundOgg.Load(AudioDevice, Path.Combine("Content", "title_screen.ogg"), false, true); musicStream = StreamingSoundOgg.Load(AudioDevice, Path.Combine("Content", "housecleaning_herbal_mix.ogg"));
musicStream.Play(); musicStream.QueueSyncPlay();
}
var musicQoaStream = StreamingSoundQoa.Load(AudioDevice, Path.Combine("Content", "housecleaning_herbal_mix.qoa"));
musicQoaStream.QueueSyncPlay();
AudioDevice.SyncPlay();
}
protected override void Update(System.TimeSpan dt) protected override void Update(System.TimeSpan dt)
{ {
raymarchUniforms.time += (float)dt.TotalSeconds; raymarchUniforms.time += (float)dt.TotalSeconds;
} }
protected override void Draw(System.TimeSpan dt, double alpha) protected override void Draw(double alpha)
{ {
var commandBuffer = GraphicsDevice.AcquireCommandBuffer(); var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(Window); var swapchainTexture = commandBuffer.AcquireSwapchainTexture(MainWindow);
var takeScreenshot = Inputs.Keyboard.IsPressed(Keycode.S) && !screenshotInProgress && (swapchainTexture != null);
if (swapchainTexture != null) if (swapchainTexture != null)
{ {
@ -136,6 +127,7 @@ namespace MoonWorksTest
new ColorAttachmentInfo(swapchainTexture, clearColor) new ColorAttachmentInfo(swapchainTexture, clearColor)
); );
/*
commandBuffer.BindGraphicsPipeline(mainGraphicsPipeline); commandBuffer.BindGraphicsPipeline(mainGraphicsPipeline);
commandBuffer.BindVertexBuffers(vertexBuffer); commandBuffer.BindVertexBuffers(vertexBuffer);
@ -146,46 +138,16 @@ namespace MoonWorksTest
var fragmentParamOffset = commandBuffer.PushFragmentShaderUniforms(raymarchUniforms); var fragmentParamOffset = commandBuffer.PushFragmentShaderUniforms(raymarchUniforms);
commandBuffer.DrawPrimitives(0, 1, 0, fragmentParamOffset); commandBuffer.DrawPrimitives(0, 1, 0, fragmentParamOffset);
*/
commandBuffer.EndRenderPass(); commandBuffer.EndRenderPass();
if (takeScreenshot)
{
commandBuffer.CopyTextureToBuffer(new TextureSlice(swapchainTexture), screenshotBuffer);
}
} }
GraphicsDevice.Submit(commandBuffer); GraphicsDevice.Submit(commandBuffer);
if (takeScreenshot)
{
Task.Run(() => SaveScreenshot());
}
} }
private void SaveScreenshot() protected override void Destroy()
{
screenshotInProgress = true;
var name = "MoonWorksTest-" + System.DateTime.Now.ToString("MM-dd-yyyy-hh-mm-ss") + ".png";
System.Console.WriteLine("Saving screenshot " + name + " ...");
GraphicsDevice.Wait();
screenshotBuffer.GetData(screenshotPixels, screenshotBufferSize);
Texture.SavePNG(
name,
1280,
720,
GraphicsDevice.GetSwapchainFormat(Window),
screenshotPixels
);
System.Console.WriteLine("Screenshot saved!");
screenshotInProgress = false;
}
protected override void OnDestroy()
{ {
} }