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">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<OutputType>Exe</OutputType>
<RootNamespace>MoonWorksTest</RootNamespace>
<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 MoonWorks.Math;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
namespace MoonWorksTest
{
[StructLayout(LayoutKind.Sequential)]
struct PositionTexture
struct PositionTexture : MoonWorks.Graphics.IVertexType
{
public Vector3 Position;
public Vector2 Texture;
}
public static VertexElementFormat[] Formats => new VertexElementFormat[] { VertexElementFormat.Vector3, VertexElementFormat.Vector2 };
}
}

View File

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

View File

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