shader fixup and new example structure
parent
da90d28c33
commit
69ffbbf03a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout (local_size_x = 8) in;
|
layout (local_size_x = 8) in;
|
||||||
layout (set = 0, binding = 0) buffer outBuffer
|
layout (set = 1, binding = 0) buffer outBuffer
|
||||||
{
|
{
|
||||||
uint squares[];
|
uint squares[];
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,23 +1,19 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
#define LOCAL_SIZE 8
|
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||||
|
|
||||||
layout (local_size_x = LOCAL_SIZE, local_size_y = LOCAL_SIZE, local_size_z = 1) in;
|
|
||||||
layout (set = 1, binding = 0, rgba8) uniform writeonly image2D outImage;
|
layout (set = 1, binding = 0, rgba8) uniform writeonly image2D outImage;
|
||||||
layout (set = 2, binding = 0) uniform UBO
|
layout (set = 2, binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
uvec2 workgroupSize;
|
float time;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
vec2 size = imageSize(outImage);
|
||||||
vec2 coord = gl_GlobalInvocationID.xy;
|
vec2 coord = gl_GlobalInvocationID.xy;
|
||||||
vec2 totalWorkgroupSize = vec2(ubo.workgroupSize) * vec2(LOCAL_SIZE);
|
vec2 uv = coord / size;
|
||||||
vec4 col = vec4(
|
|
||||||
coord.x / totalWorkgroupSize.x,
|
vec3 col = 0.5 + 0.5*cos(ubo.time + uv.xyx + vec3(0, 2, 4));
|
||||||
coord.y / totalWorkgroupSize.y,
|
|
||||||
1.0,
|
imageStore(outImage, ivec2(coord), vec4(col, 1.0));
|
||||||
1.0
|
|
||||||
);
|
|
||||||
imageStore(outImage, ivec2(coord), col);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ layout (location = 1) in vec4 Color;
|
||||||
|
|
||||||
layout (location = 0) out vec4 outColor;
|
layout (location = 0) out vec4 outColor;
|
||||||
|
|
||||||
layout (binding = 0, set = 2) uniform UniformBlock
|
layout (set = 1, binding = 0) uniform UniformBlock
|
||||||
{
|
{
|
||||||
mat4x4 MatrixTransform;
|
mat4x4 MatrixTransform;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@ layout (location = 1) in vec2 TexCoord;
|
||||||
|
|
||||||
layout (location = 0) out vec4 outColor;
|
layout (location = 0) out vec4 outColor;
|
||||||
|
|
||||||
layout(binding = 0, set = 0) uniform sampler2D Sampler;
|
layout(set = 0, binding = 0) uniform sampler2D Sampler;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,17 +8,17 @@ void main()
|
||||||
|
|
||||||
if (gl_VertexIndex == 0)
|
if (gl_VertexIndex == 0)
|
||||||
{
|
{
|
||||||
pos = vec2(-1, 1);
|
pos = vec2(-1, -1);
|
||||||
outColor = vec4(1, 0, 0, 1);
|
outColor = vec4(1, 0, 0, 1);
|
||||||
}
|
}
|
||||||
else if (gl_VertexIndex == 1)
|
else if (gl_VertexIndex == 1)
|
||||||
{
|
{
|
||||||
pos = vec2(1, 1);
|
pos = vec2(1, -1);
|
||||||
outColor = vec4(0, 1, 0, 1);
|
outColor = vec4(0, 1, 0, 1);
|
||||||
}
|
}
|
||||||
else if (gl_VertexIndex == 2)
|
else if (gl_VertexIndex == 2)
|
||||||
{
|
{
|
||||||
pos = vec2(0, -1);
|
pos = vec2(0, 1);
|
||||||
outColor = vec4(0, 0, 1, 1);
|
outColor = vec4(0, 0, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
layout(location = 0) in vec3 TexCoord;
|
layout(location = 0) in vec3 TexCoord;
|
||||||
layout(location = 0) out vec4 FragColor;
|
layout(location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout(binding = 0, set = 1) uniform samplerCube SkyboxSampler;
|
layout(set = 2, binding = 0) uniform samplerCube SkyboxSampler;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
layout(location = 0) in vec3 inPos;
|
layout(location = 0) in vec3 inPos;
|
||||||
layout(location = 0) out vec3 vPos;
|
layout(location = 0) out vec3 vPos;
|
||||||
|
|
||||||
layout(set = 2, binding = 0) uniform UBO
|
layout(set = 1, binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 ViewProjection;
|
mat4 ViewProjection;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout (location = 0) in vec2 TexCoord;
|
layout (location = 0) in vec2 TexCoord;
|
||||||
|
|
||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout(binding = 0, set = 1) uniform sampler2D Sampler;
|
layout(set = 2, binding = 0) uniform sampler2D Sampler;
|
||||||
|
|
||||||
layout (binding = 0, set = 3) uniform UniformBlock
|
layout (set = 3, binding = 0) uniform UniformBlock
|
||||||
{
|
{
|
||||||
float zNear;
|
float zNear;
|
||||||
float zFar;
|
float zFar;
|
||||||
|
|
|
@ -4,7 +4,7 @@ layout (location = 0) in vec2 TexCoord;
|
||||||
|
|
||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout(binding = 0, set = 1) uniform sampler2D Sampler;
|
layout(set = 2, binding = 0) uniform sampler2D Sampler;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,9 +4,9 @@ layout (location = 0) in vec2 TexCoord;
|
||||||
|
|
||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout(binding = 0, set = 1) uniform sampler2DArray Sampler;
|
layout(set = 2, binding = 0) uniform sampler2DArray Sampler;
|
||||||
|
|
||||||
layout (binding = 0, set = 3) uniform UniformBlock
|
layout (set = 3, binding = 0) uniform UniformBlock
|
||||||
{
|
{
|
||||||
float depth;
|
float depth;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,9 +4,9 @@ layout (location = 0) in vec2 TexCoord;
|
||||||
|
|
||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout(binding = 0, set = 1) uniform sampler3D Sampler;
|
layout(set = 2, binding = 0) uniform sampler3D Sampler;
|
||||||
|
|
||||||
layout (binding = 0, set = 3) uniform UniformBlock
|
layout (set = 3, binding = 0) uniform UniformBlock
|
||||||
{
|
{
|
||||||
float depth;
|
float depth;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@ layout (location = 1) in vec2 TexCoord;
|
||||||
|
|
||||||
layout (location = 0) out vec2 outTexCoord;
|
layout (location = 0) out vec2 outTexCoord;
|
||||||
|
|
||||||
layout (binding = 0, set = 2) uniform UniformBlock
|
layout (set = 1, binding = 0) uniform UniformBlock
|
||||||
{
|
{
|
||||||
mat4x4 MatrixTransform;
|
mat4x4 MatrixTransform;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,9 +4,9 @@ layout (location = 0) in vec2 TexCoord;
|
||||||
|
|
||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout(binding = 0, set = 1) uniform sampler2D Sampler;
|
layout(set = 2, binding = 0) uniform sampler2D Sampler;
|
||||||
|
|
||||||
layout (binding = 0, set = 3) uniform UniformBlock
|
layout (set = 3, binding = 0) uniform UniformBlock
|
||||||
{
|
{
|
||||||
vec4 MultiplyColor;
|
vec4 MultiplyColor;
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,7 +53,7 @@ public static class TestUtils
|
||||||
|
|
||||||
public static string GetShaderPath(string shaderName)
|
public static string GetShaderPath(string shaderName)
|
||||||
{
|
{
|
||||||
return SDL2.SDL.SDL_GetBasePath() + "Content/Shaders/Compiled/" + shaderName + ".refresh";
|
return SDL2.SDL.SDL_GetBasePath() + "Content/Shaders/Compiled/" + shaderName + ".spv";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetTexturePath(string textureName)
|
public static string GetTexturePath(string textureName)
|
||||||
|
@ -73,7 +73,7 @@ public static class TestUtils
|
||||||
Right // D/right arrow on keyboard, right face button on gamepad
|
Right // D/right arrow on keyboard, right face button on gamepad
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CheckButtonPressed(Input.Inputs inputs, ButtonType buttonType)
|
public static bool CheckButtonPressed(MoonWorks.Input.Inputs inputs, ButtonType buttonType)
|
||||||
{
|
{
|
||||||
bool pressed = false;
|
bool pressed = false;
|
||||||
|
|
||||||
|
@ -81,28 +81,31 @@ public static class TestUtils
|
||||||
{
|
{
|
||||||
pressed = (
|
pressed = (
|
||||||
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsPressed) ||
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsPressed) ||
|
||||||
inputs.Keyboard.IsPressed(Input.KeyCode.Left)
|
inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.Left) ||
|
||||||
|
inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.A)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (buttonType == ButtonType.Bottom)
|
else if (buttonType == ButtonType.Bottom)
|
||||||
{
|
{
|
||||||
pressed = (
|
pressed = (
|
||||||
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsPressed) ||
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsPressed) ||
|
||||||
inputs.Keyboard.IsPressed(Input.KeyCode.Down)
|
inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.Down) ||
|
||||||
|
inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.S)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (buttonType == ButtonType.Right)
|
else if (buttonType == ButtonType.Right)
|
||||||
{
|
{
|
||||||
pressed = (
|
pressed = (
|
||||||
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsPressed) ||
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsPressed) ||
|
||||||
inputs.Keyboard.IsPressed(Input.KeyCode.Right)
|
inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.Right) ||
|
||||||
|
inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.D)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CheckButtonDown(Input.Inputs inputs, ButtonType buttonType)
|
public static bool CheckButtonDown(MoonWorks.Input.Inputs inputs, ButtonType buttonType)
|
||||||
{
|
{
|
||||||
bool down = false;
|
bool down = false;
|
||||||
|
|
||||||
|
@ -110,24 +113,24 @@ public static class TestUtils
|
||||||
{
|
{
|
||||||
down = (
|
down = (
|
||||||
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsDown) ||
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsDown) ||
|
||||||
inputs.Keyboard.IsDown(Input.KeyCode.A) ||
|
inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.Left) ||
|
||||||
inputs.Keyboard.IsDown(Input.KeyCode.Left)
|
inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.A)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (buttonType == ButtonType.Bottom)
|
else if (buttonType == ButtonType.Bottom)
|
||||||
{
|
{
|
||||||
down = (
|
down = (
|
||||||
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsDown) ||
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsDown) ||
|
||||||
inputs.Keyboard.IsDown(Input.KeyCode.S) ||
|
inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.Down) ||
|
||||||
inputs.Keyboard.IsDown(Input.KeyCode.Down)
|
inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.S)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (buttonType == ButtonType.Right)
|
else if (buttonType == ButtonType.Right)
|
||||||
{
|
{
|
||||||
down = (
|
down = (
|
||||||
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsDown) ||
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsDown) ||
|
||||||
inputs.Keyboard.IsDown(Input.KeyCode.D) ||
|
inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.Right) ||
|
||||||
inputs.Keyboard.IsDown(Input.KeyCode.Right)
|
inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.D)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,43 +6,43 @@
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))">
|
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))">
|
||||||
<Content Include="..\..\moonlibs\x64\FAudio.dll">
|
<Content Include="..\moonlibs\x64\FAudio.dll">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="..\..\moonlibs\x64\Refresh.dll">
|
<Content Include="..\moonlibs\x64\Refresh.dll">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="..\..\moonlibs\x64\SDL2.dll">
|
<Content Include="..\moonlibs\x64\SDL2.dll">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="..\..\moonlibs\x64\dav1dfile.dll">
|
<Content Include="..\moonlibs\x64\dav1dfile.dll">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))">
|
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))">
|
||||||
<Content Include="..\..\moonlibs\lib64\libFAudio.*">
|
<Content Include="..\moonlibs\lib64\libFAudio.*">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="..\..\moonlibs\lib64\libRefresh.*">
|
<Content Include="..\moonlibs\lib64\libRefresh.*">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="..\..\moonlibs\lib64\libSDL2-2.0.*">
|
<Content Include="..\moonlibs\lib64\libSDL2-2.0.*">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="..\..\moonlibs\windows\libdav1dfile.*">
|
<Content Include="..\moonlibs\windows\libdav1dfile.*">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))">
|
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))">
|
||||||
<Content Include="..\..\moonlibs\osx\**\*.*" >
|
<Content Include="..\moonlibs\osx\**\*.*" >
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using MoonWorks;
|
using MoonWorks;
|
||||||
using MoonWorks.Graphics;
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Input;
|
||||||
using MoonWorks.Math.Float;
|
using MoonWorks.Math.Float;
|
||||||
|
|
||||||
namespace MoonWorksGraphicsTests;
|
namespace MoonWorksGraphicsTests;
|
||||||
|
@ -11,7 +12,7 @@ class BasicComputeExample : Example
|
||||||
private Sampler Sampler;
|
private Sampler Sampler;
|
||||||
private GpuBuffer VertexBuffer;
|
private GpuBuffer VertexBuffer;
|
||||||
|
|
||||||
public override void Init(Window window, GraphicsDevice graphicsDevice)
|
public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs)
|
||||||
{
|
{
|
||||||
Window = window;
|
Window = window;
|
||||||
GraphicsDevice = graphicsDevice;
|
GraphicsDevice = graphicsDevice;
|
||||||
|
@ -73,7 +74,9 @@ class BasicComputeExample : Example
|
||||||
fragShaderModule
|
fragShaderModule
|
||||||
);
|
);
|
||||||
drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
|
drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
|
||||||
drawPipelineCreateInfo.FragmentShaderResourceInfo.SamplerCount = 1;
|
drawPipelineCreateInfo.FragmentShaderResourceInfo = new GraphicsPipelineResourceInfo{
|
||||||
|
SamplerCount = 1
|
||||||
|
};
|
||||||
|
|
||||||
DrawPipeline = new GraphicsPipeline(
|
DrawPipeline = new GraphicsPipeline(
|
||||||
GraphicsDevice,
|
GraphicsDevice,
|
|
@ -1,21 +1,24 @@
|
||||||
using MoonWorks;
|
using MoonWorks;
|
||||||
using MoonWorks.Graphics;
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Input;
|
||||||
using MoonWorks.Math.Float;
|
using MoonWorks.Math.Float;
|
||||||
|
|
||||||
namespace MoonWorksGraphicsTests
|
namespace MoonWorksGraphicsTests
|
||||||
{
|
{
|
||||||
class BasicStencilGame : Example
|
class BasicStencilExample : Example
|
||||||
{
|
{
|
||||||
private GraphicsPipeline maskerPipeline;
|
private GraphicsPipeline MaskerPipeline;
|
||||||
private GraphicsPipeline maskeePipeline;
|
private GraphicsPipeline MaskeePipeline;
|
||||||
private GpuBuffer vertexBuffer;
|
private GpuBuffer VertexBuffer;
|
||||||
private Texture depthStencilTexture;
|
private Texture DepthStencilTexture;
|
||||||
|
|
||||||
public override void Init(Window window, GraphicsDevice graphicsDevice)
|
public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs)
|
||||||
{
|
{
|
||||||
Window = window;
|
Window = window;
|
||||||
GraphicsDevice = graphicsDevice;
|
GraphicsDevice = graphicsDevice;
|
||||||
|
|
||||||
|
Window.SetTitle("BasicStencil");
|
||||||
|
|
||||||
// Load the shaders
|
// Load the shaders
|
||||||
Shader vertShaderModule = new Shader(
|
Shader vertShaderModule = new Shader(
|
||||||
GraphicsDevice,
|
GraphicsDevice,
|
||||||
|
@ -52,7 +55,7 @@ namespace MoonWorksGraphicsTests
|
||||||
Reference = 1,
|
Reference = 1,
|
||||||
WriteMask = 0xFF
|
WriteMask = 0xFF
|
||||||
};
|
};
|
||||||
maskerPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
MaskerPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||||
|
|
||||||
pipelineCreateInfo.DepthStencilState = new DepthStencilState
|
pipelineCreateInfo.DepthStencilState = new DepthStencilState
|
||||||
{
|
{
|
||||||
|
@ -65,10 +68,10 @@ namespace MoonWorksGraphicsTests
|
||||||
CompareMask = 0xFF,
|
CompareMask = 0xFF,
|
||||||
WriteMask = 0
|
WriteMask = 0
|
||||||
};
|
};
|
||||||
maskeePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
MaskeePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||||
|
|
||||||
// Create and populate the GPU resources
|
// Create and populate the GPU resources
|
||||||
depthStencilTexture = Texture.CreateTexture2D(
|
DepthStencilTexture = Texture.CreateTexture2D(
|
||||||
GraphicsDevice,
|
GraphicsDevice,
|
||||||
Window.Width,
|
Window.Width,
|
||||||
Window.Height,
|
Window.Height,
|
||||||
|
@ -78,15 +81,15 @@ namespace MoonWorksGraphicsTests
|
||||||
|
|
||||||
var resourceUploader = new ResourceUploader(GraphicsDevice);
|
var resourceUploader = new ResourceUploader(GraphicsDevice);
|
||||||
|
|
||||||
vertexBuffer = resourceUploader.CreateBuffer(
|
VertexBuffer = resourceUploader.CreateBuffer(
|
||||||
[
|
[
|
||||||
new PositionColorVertex(new Vector3(-0.5f, 0.5f, 0), Color.Yellow),
|
new PositionColorVertex(new Vector3(-0.5f, -0.5f, 0), Color.Yellow),
|
||||||
new PositionColorVertex(new Vector3(0.5f, 0.5f, 0), Color.Yellow),
|
new PositionColorVertex(new Vector3( 0.5f, -0.5f, 0), Color.Yellow),
|
||||||
new PositionColorVertex(new Vector3(0, -0.5f, 0), Color.Yellow),
|
new PositionColorVertex(new Vector3( 0, 0.5f, 0), Color.Yellow),
|
||||||
|
|
||||||
new PositionColorVertex(new Vector3(-1, 1, 0), Color.Red),
|
new PositionColorVertex(new Vector3(-1, -1, 0), Color.Red),
|
||||||
new PositionColorVertex(new Vector3(1, 1, 0), Color.Lime),
|
new PositionColorVertex(new Vector3( 1, -1, 0), Color.Lime),
|
||||||
new PositionColorVertex(new Vector3(0, -1, 0), Color.Blue),
|
new PositionColorVertex(new Vector3( 0, 1, 0), Color.Blue),
|
||||||
],
|
],
|
||||||
BufferUsageFlags.Vertex
|
BufferUsageFlags.Vertex
|
||||||
);
|
);
|
||||||
|
@ -104,13 +107,13 @@ namespace MoonWorksGraphicsTests
|
||||||
if (swapchainTexture != null)
|
if (swapchainTexture != null)
|
||||||
{
|
{
|
||||||
var renderPass = cmdbuf.BeginRenderPass(
|
var renderPass = cmdbuf.BeginRenderPass(
|
||||||
new DepthStencilAttachmentInfo(depthStencilTexture, true, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare),
|
new DepthStencilAttachmentInfo(DepthStencilTexture, true, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare),
|
||||||
new ColorAttachmentInfo(swapchainTexture, false, Color.Black)
|
new ColorAttachmentInfo(swapchainTexture, false, Color.Black)
|
||||||
);
|
);
|
||||||
renderPass.BindGraphicsPipeline(maskerPipeline);
|
renderPass.BindGraphicsPipeline(MaskerPipeline);
|
||||||
renderPass.BindVertexBuffer(vertexBuffer);
|
renderPass.BindVertexBuffer(VertexBuffer);
|
||||||
renderPass.DrawPrimitives(0, 1);
|
renderPass.DrawPrimitives(0, 1);
|
||||||
renderPass.BindGraphicsPipeline(maskeePipeline);
|
renderPass.BindGraphicsPipeline(MaskeePipeline);
|
||||||
renderPass.DrawPrimitives(3, 1);
|
renderPass.DrawPrimitives(3, 1);
|
||||||
cmdbuf.EndRenderPass(renderPass);
|
cmdbuf.EndRenderPass(renderPass);
|
||||||
}
|
}
|
||||||
|
@ -119,7 +122,10 @@ namespace MoonWorksGraphicsTests
|
||||||
|
|
||||||
public override void Destroy()
|
public override void Destroy()
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
MaskerPipeline.Dispose();
|
||||||
|
MaskeePipeline.Dispose();
|
||||||
|
VertexBuffer.Dispose();
|
||||||
|
DepthStencilTexture.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,111 @@
|
||||||
|
using MoonWorks;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Input;
|
||||||
|
|
||||||
|
namespace MoonWorksGraphicsTests;
|
||||||
|
|
||||||
|
class BasicTriangleExample : Example
|
||||||
|
{
|
||||||
|
private GraphicsPipeline FillPipeline;
|
||||||
|
private GraphicsPipeline LinePipeline;
|
||||||
|
|
||||||
|
private Viewport SmallViewport = new Viewport(160, 120, 320, 240);
|
||||||
|
private Rect ScissorRect = new Rect(320, 240, 320, 240);
|
||||||
|
|
||||||
|
private bool UseWireframeMode;
|
||||||
|
private bool UseSmallViewport;
|
||||||
|
private bool UseScissorRect;
|
||||||
|
|
||||||
|
public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs)
|
||||||
|
{
|
||||||
|
Window = window;
|
||||||
|
GraphicsDevice = graphicsDevice;
|
||||||
|
Inputs = inputs;
|
||||||
|
|
||||||
|
Window.SetTitle("BasicTriangle");
|
||||||
|
|
||||||
|
Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect");
|
||||||
|
|
||||||
|
Shader vertShaderModule = new Shader(
|
||||||
|
GraphicsDevice,
|
||||||
|
TestUtils.GetShaderPath("RawTriangle.vert"),
|
||||||
|
"main",
|
||||||
|
ShaderStage.Vertex,
|
||||||
|
ShaderFormat.SPIRV
|
||||||
|
);
|
||||||
|
|
||||||
|
Shader fragShaderModule = new Shader(
|
||||||
|
GraphicsDevice,
|
||||||
|
TestUtils.GetShaderPath("SolidColor.frag"),
|
||||||
|
"main",
|
||||||
|
ShaderStage.Fragment,
|
||||||
|
ShaderFormat.SPIRV
|
||||||
|
);
|
||||||
|
|
||||||
|
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
||||||
|
Window.SwapchainFormat,
|
||||||
|
vertShaderModule,
|
||||||
|
fragShaderModule
|
||||||
|
);
|
||||||
|
FillPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||||
|
|
||||||
|
pipelineCreateInfo.RasterizerState.FillMode = FillMode.Line;
|
||||||
|
LinePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(System.TimeSpan delta)
|
||||||
|
{
|
||||||
|
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
|
||||||
|
{
|
||||||
|
UseWireframeMode = !UseWireframeMode;
|
||||||
|
Logger.LogInfo("Using wireframe mode: " + UseWireframeMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
|
||||||
|
{
|
||||||
|
UseSmallViewport = !UseSmallViewport;
|
||||||
|
Logger.LogInfo("Using small viewport: " + UseSmallViewport);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
|
||||||
|
{
|
||||||
|
UseScissorRect = !UseScissorRect;
|
||||||
|
Logger.LogInfo("Using scissor rect: " + UseScissorRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Draw(double alpha)
|
||||||
|
{
|
||||||
|
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
|
Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window);
|
||||||
|
if (swapchainTexture != null)
|
||||||
|
{
|
||||||
|
var renderPass = cmdbuf.BeginRenderPass(
|
||||||
|
new ColorAttachmentInfo(swapchainTexture, false, Color.Black)
|
||||||
|
);
|
||||||
|
|
||||||
|
renderPass.BindGraphicsPipeline(UseWireframeMode ? LinePipeline : FillPipeline);
|
||||||
|
|
||||||
|
if (UseSmallViewport)
|
||||||
|
{
|
||||||
|
renderPass.SetViewport(SmallViewport);
|
||||||
|
}
|
||||||
|
if (UseScissorRect)
|
||||||
|
{
|
||||||
|
renderPass.SetScissor(ScissorRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderPass.DrawPrimitives(0, 1);
|
||||||
|
|
||||||
|
cmdbuf.EndRenderPass(renderPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Destroy()
|
||||||
|
{
|
||||||
|
FillPipeline.Dispose();
|
||||||
|
LinePipeline.Dispose();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,86 +0,0 @@
|
||||||
using MoonWorks.Graphics;
|
|
||||||
|
|
||||||
namespace MoonWorks.Test
|
|
||||||
{
|
|
||||||
class BasicTriangleGame : Game
|
|
||||||
{
|
|
||||||
private GraphicsPipeline fillPipeline;
|
|
||||||
private GraphicsPipeline linePipeline;
|
|
||||||
|
|
||||||
private Viewport smallViewport = new Viewport(160, 120, 320, 240);
|
|
||||||
private Rect scissorRect = new Rect(320, 240, 320, 240);
|
|
||||||
|
|
||||||
private bool useWireframeMode;
|
|
||||||
private bool useSmallViewport;
|
|
||||||
private bool useScissorRect;
|
|
||||||
|
|
||||||
public BasicTriangleGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
|
|
||||||
{
|
|
||||||
Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect");
|
|
||||||
|
|
||||||
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
|
|
||||||
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
|
|
||||||
|
|
||||||
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
|
||||||
MainWindow.SwapchainFormat,
|
|
||||||
vertShaderModule,
|
|
||||||
fragShaderModule
|
|
||||||
);
|
|
||||||
fillPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
|
||||||
|
|
||||||
pipelineCreateInfo.RasterizerState.FillMode = FillMode.Line;
|
|
||||||
linePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update(System.TimeSpan delta)
|
|
||||||
{
|
|
||||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
|
|
||||||
{
|
|
||||||
useWireframeMode = !useWireframeMode;
|
|
||||||
Logger.LogInfo("Using wireframe mode: " + useWireframeMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
|
|
||||||
{
|
|
||||||
useSmallViewport = !useSmallViewport;
|
|
||||||
Logger.LogInfo("Using small viewport: " + useSmallViewport);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
|
|
||||||
{
|
|
||||||
useScissorRect = !useScissorRect;
|
|
||||||
Logger.LogInfo("Using scissor rect: " + useScissorRect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Draw(double alpha)
|
|
||||||
{
|
|
||||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
|
||||||
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
|
|
||||||
if (backbuffer != null)
|
|
||||||
{
|
|
||||||
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
|
|
||||||
cmdbuf.BindGraphicsPipeline(useWireframeMode ? linePipeline : fillPipeline);
|
|
||||||
|
|
||||||
if (useSmallViewport)
|
|
||||||
{
|
|
||||||
cmdbuf.SetViewport(smallViewport);
|
|
||||||
}
|
|
||||||
if (useScissorRect)
|
|
||||||
{
|
|
||||||
cmdbuf.SetScissor(scissorRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdbuf.DrawPrimitives(0, 1);
|
|
||||||
cmdbuf.EndRenderPass();
|
|
||||||
}
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
BasicTriangleGame game = new BasicTriangleGame();
|
|
||||||
game.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
using MoonWorks;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Input;
|
||||||
|
|
||||||
|
namespace MoonWorksGraphicsTests;
|
||||||
|
|
||||||
|
class ClearScreenExample : Example
|
||||||
|
{
|
||||||
|
public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs)
|
||||||
|
{
|
||||||
|
Window = window;
|
||||||
|
GraphicsDevice = graphicsDevice;
|
||||||
|
|
||||||
|
Window.SetTitle("ClearScreen");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(System.TimeSpan delta) { }
|
||||||
|
|
||||||
|
public override void Draw(double alpha)
|
||||||
|
{
|
||||||
|
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
|
Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window);
|
||||||
|
if (swapchainTexture != null)
|
||||||
|
{
|
||||||
|
var renderPass = cmdbuf.BeginRenderPass(
|
||||||
|
new ColorAttachmentInfo(swapchainTexture, false, Color.CornflowerBlue)
|
||||||
|
);
|
||||||
|
cmdbuf.EndRenderPass(renderPass);
|
||||||
|
}
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Destroy()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,30 +0,0 @@
|
||||||
using MoonWorks;
|
|
||||||
using MoonWorks.Graphics;
|
|
||||||
|
|
||||||
namespace MoonWorks.Test
|
|
||||||
{
|
|
||||||
class ClearScreenGame : Game
|
|
||||||
{
|
|
||||||
public ClearScreenGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) { }
|
|
||||||
|
|
||||||
protected override void Update(System.TimeSpan delta) { }
|
|
||||||
|
|
||||||
protected override void Draw(double alpha)
|
|
||||||
{
|
|
||||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
|
||||||
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
|
|
||||||
if (backbuffer != null)
|
|
||||||
{
|
|
||||||
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue));
|
|
||||||
cmdbuf.EndRenderPass();
|
|
||||||
}
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
ClearScreenGame game = new ClearScreenGame();
|
|
||||||
game.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
using MoonWorks;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Input;
|
||||||
|
|
||||||
|
namespace MoonWorksGraphicsTests
|
||||||
|
{
|
||||||
|
class ClearScreen_MultiWindowExample : Example
|
||||||
|
{
|
||||||
|
private Window SecondaryWindow;
|
||||||
|
|
||||||
|
public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs)
|
||||||
|
{
|
||||||
|
Window = window;
|
||||||
|
GraphicsDevice = graphicsDevice;
|
||||||
|
|
||||||
|
var (windowX, windowY) = Window.Position;
|
||||||
|
Window.SetPosition(windowX - 360, windowY);
|
||||||
|
|
||||||
|
SecondaryWindow = new Window(
|
||||||
|
new WindowCreateInfo("Secondary Window", 640, 480, ScreenMode.Windowed, SwapchainComposition.SDR, PresentMode.VSync, false, false),
|
||||||
|
SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN
|
||||||
|
);
|
||||||
|
(windowX, windowY) = SecondaryWindow.Position;
|
||||||
|
SecondaryWindow.SetPosition(windowX + 360, windowY);
|
||||||
|
|
||||||
|
GraphicsDevice.ClaimWindow(SecondaryWindow, SwapchainComposition.SDR, PresentMode.VSync);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(System.TimeSpan delta) { }
|
||||||
|
|
||||||
|
public override void Draw(double alpha)
|
||||||
|
{
|
||||||
|
CommandBuffer cmdbuf;
|
||||||
|
Texture swapchainTexture;
|
||||||
|
|
||||||
|
if (Window.Claimed)
|
||||||
|
{
|
||||||
|
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
|
swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window);
|
||||||
|
if (swapchainTexture != null)
|
||||||
|
{
|
||||||
|
var renderPass = cmdbuf.BeginRenderPass(
|
||||||
|
new ColorAttachmentInfo(swapchainTexture, false, Color.CornflowerBlue)
|
||||||
|
);
|
||||||
|
cmdbuf.EndRenderPass(renderPass);
|
||||||
|
}
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SecondaryWindow.Claimed)
|
||||||
|
{
|
||||||
|
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
|
swapchainTexture = cmdbuf.AcquireSwapchainTexture(SecondaryWindow);
|
||||||
|
if (swapchainTexture != null)
|
||||||
|
{
|
||||||
|
var renderPass = cmdbuf.BeginRenderPass(
|
||||||
|
new ColorAttachmentInfo(swapchainTexture, false, Color.Aquamarine)
|
||||||
|
);
|
||||||
|
cmdbuf.EndRenderPass(renderPass);
|
||||||
|
}
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Destroy()
|
||||||
|
{
|
||||||
|
GraphicsDevice.UnclaimWindow(SecondaryWindow);
|
||||||
|
SecondaryWindow.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,62 +0,0 @@
|
||||||
using MoonWorks;
|
|
||||||
using MoonWorks.Graphics;
|
|
||||||
|
|
||||||
namespace MoonWorks.Test
|
|
||||||
{
|
|
||||||
class ClearScreen_MultiWindowGame : Game
|
|
||||||
{
|
|
||||||
private Window secondaryWindow;
|
|
||||||
|
|
||||||
public ClearScreen_MultiWindowGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
|
|
||||||
{
|
|
||||||
var (windowX, windowY) = MainWindow.Position;
|
|
||||||
MainWindow.SetPosition(windowX - 360, windowY);
|
|
||||||
|
|
||||||
secondaryWindow = new Window(
|
|
||||||
new WindowCreateInfo("Secondary Window", 640, 480, ScreenMode.Windowed, PresentMode.FIFO, false, false),
|
|
||||||
GraphicsDevice.WindowFlags
|
|
||||||
);
|
|
||||||
(windowX, windowY) = secondaryWindow.Position;
|
|
||||||
secondaryWindow.SetPosition(windowX + 360, windowY);
|
|
||||||
GraphicsDevice.ClaimWindow(secondaryWindow, PresentMode.FIFO);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update(System.TimeSpan delta) { }
|
|
||||||
|
|
||||||
protected override void Draw(double alpha)
|
|
||||||
{
|
|
||||||
CommandBuffer cmdbuf;
|
|
||||||
Texture? backbuffer;
|
|
||||||
|
|
||||||
if (MainWindow.Claimed)
|
|
||||||
{
|
|
||||||
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
|
||||||
backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
|
|
||||||
if (backbuffer != null)
|
|
||||||
{
|
|
||||||
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue));
|
|
||||||
cmdbuf.EndRenderPass();
|
|
||||||
}
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secondaryWindow.Claimed)
|
|
||||||
{
|
|
||||||
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
|
||||||
backbuffer = cmdbuf.AcquireSwapchainTexture(secondaryWindow);
|
|
||||||
if (backbuffer != null)
|
|
||||||
{
|
|
||||||
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Aquamarine));
|
|
||||||
cmdbuf.EndRenderPass();
|
|
||||||
}
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
ClearScreen_MultiWindowGame game = new ClearScreen_MultiWindowGame();
|
|
||||||
game.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
using MoonWorks;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Input;
|
||||||
|
using MoonWorks.Math.Float;
|
||||||
|
|
||||||
|
namespace MoonWorksGraphicsTests;
|
||||||
|
|
||||||
|
class CompressedTexturesExample : Example
|
||||||
|
{
|
||||||
|
private GraphicsPipeline Pipeline;
|
||||||
|
private GpuBuffer VertexBuffer;
|
||||||
|
private GpuBuffer IndexBuffer;
|
||||||
|
private Sampler Sampler;
|
||||||
|
private Texture[] Textures;
|
||||||
|
private string[] TextureNames =
|
||||||
|
[
|
||||||
|
"BC1",
|
||||||
|
"BC2",
|
||||||
|
"BC3",
|
||||||
|
"BC7"
|
||||||
|
];
|
||||||
|
|
||||||
|
private int CurrentTextureIndex;
|
||||||
|
|
||||||
|
public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs)
|
||||||
|
{
|
||||||
|
Window = window;
|
||||||
|
GraphicsDevice = graphicsDevice;
|
||||||
|
Inputs = inputs;
|
||||||
|
|
||||||
|
Logger.LogInfo("Press Left and Right to cycle between textures");
|
||||||
|
Logger.LogInfo("Setting texture to: " + TextureNames[0]);
|
||||||
|
|
||||||
|
// Load the shaders
|
||||||
|
Shader vertShaderModule = new Shader(
|
||||||
|
GraphicsDevice,
|
||||||
|
TestUtils.GetShaderPath("TexturedQuad.vert"),
|
||||||
|
"main",
|
||||||
|
ShaderStage.Vertex,
|
||||||
|
ShaderFormat.SPIRV
|
||||||
|
);
|
||||||
|
|
||||||
|
Shader fragShaderModule = new Shader(
|
||||||
|
GraphicsDevice,
|
||||||
|
TestUtils.GetShaderPath("TexturedQuad.frag"),
|
||||||
|
"main",
|
||||||
|
ShaderStage.Fragment,
|
||||||
|
ShaderFormat.SPIRV
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create the graphics pipeline
|
||||||
|
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
||||||
|
Window.SwapchainFormat,
|
||||||
|
vertShaderModule,
|
||||||
|
fragShaderModule
|
||||||
|
);
|
||||||
|
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
|
||||||
|
pipelineCreateInfo.FragmentShaderResourceInfo = new GraphicsPipelineResourceInfo
|
||||||
|
{
|
||||||
|
SamplerCount = 1
|
||||||
|
};
|
||||||
|
Pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||||
|
|
||||||
|
// Create sampler
|
||||||
|
Sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap);
|
||||||
|
|
||||||
|
// Create texture array
|
||||||
|
Textures = new Texture[TextureNames.Length];
|
||||||
|
|
||||||
|
// Create and populate the GPU resources
|
||||||
|
var resourceUploader = new ResourceUploader(GraphicsDevice);
|
||||||
|
|
||||||
|
VertexBuffer = resourceUploader.CreateBuffer(
|
||||||
|
[
|
||||||
|
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
|
||||||
|
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)),
|
||||||
|
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
|
||||||
|
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1))
|
||||||
|
],
|
||||||
|
BufferUsageFlags.Vertex
|
||||||
|
);
|
||||||
|
|
||||||
|
IndexBuffer = resourceUploader.CreateBuffer<ushort>(
|
||||||
|
[
|
||||||
|
0, 1, 2,
|
||||||
|
0, 2, 3,
|
||||||
|
],
|
||||||
|
BufferUsageFlags.Index
|
||||||
|
);
|
||||||
|
|
||||||
|
for (int i = 0; i < TextureNames.Length; i += 1)
|
||||||
|
{
|
||||||
|
Logger.LogInfo(TextureNames[i]);
|
||||||
|
Textures[i] = resourceUploader.CreateTextureFromDDS(TestUtils.GetTexturePath(TextureNames[i] + ".dds"));
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceUploader.Upload();
|
||||||
|
resourceUploader.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(System.TimeSpan delta)
|
||||||
|
{
|
||||||
|
int prevSamplerIndex = CurrentTextureIndex;
|
||||||
|
|
||||||
|
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
|
||||||
|
{
|
||||||
|
CurrentTextureIndex -= 1;
|
||||||
|
if (CurrentTextureIndex < 0)
|
||||||
|
{
|
||||||
|
CurrentTextureIndex = TextureNames.Length - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
|
||||||
|
{
|
||||||
|
CurrentTextureIndex += 1;
|
||||||
|
if (CurrentTextureIndex >= TextureNames.Length)
|
||||||
|
{
|
||||||
|
CurrentTextureIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prevSamplerIndex != CurrentTextureIndex)
|
||||||
|
{
|
||||||
|
Logger.LogInfo("Setting texture to: " + TextureNames[CurrentTextureIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Draw(double alpha)
|
||||||
|
{
|
||||||
|
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
|
Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window);
|
||||||
|
if (swapchainTexture != null)
|
||||||
|
{
|
||||||
|
var renderPass = cmdbuf.BeginRenderPass(
|
||||||
|
new ColorAttachmentInfo(swapchainTexture, false, Color.Black)
|
||||||
|
);
|
||||||
|
renderPass.BindGraphicsPipeline(Pipeline);
|
||||||
|
renderPass.BindVertexBuffer(VertexBuffer);
|
||||||
|
renderPass.BindIndexBuffer(IndexBuffer, IndexElementSize.Sixteen);
|
||||||
|
renderPass.BindFragmentSampler(new TextureSamplerBinding(Textures[CurrentTextureIndex], Sampler));
|
||||||
|
renderPass.DrawIndexedPrimitives(0, 0, 2);
|
||||||
|
cmdbuf.EndRenderPass(renderPass);
|
||||||
|
}
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Destroy()
|
||||||
|
{
|
||||||
|
Pipeline.Dispose();
|
||||||
|
VertexBuffer.Dispose();
|
||||||
|
IndexBuffer.Dispose();
|
||||||
|
Sampler.Dispose();
|
||||||
|
|
||||||
|
for (int i = 0; i < TextureNames.Length; i += 1)
|
||||||
|
{
|
||||||
|
Textures[i].Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,131 +0,0 @@
|
||||||
using MoonWorks.Graphics;
|
|
||||||
using MoonWorks.Math.Float;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace MoonWorks.Test
|
|
||||||
{
|
|
||||||
class CompressedTexturesGame : Game
|
|
||||||
{
|
|
||||||
private GraphicsPipeline pipeline;
|
|
||||||
private GpuBuffer vertexBuffer;
|
|
||||||
private GpuBuffer indexBuffer;
|
|
||||||
private Sampler sampler;
|
|
||||||
private Texture[] textures;
|
|
||||||
private string[] textureNames = new string[]
|
|
||||||
{
|
|
||||||
"BC1",
|
|
||||||
"BC2",
|
|
||||||
"BC3",
|
|
||||||
"BC7"
|
|
||||||
};
|
|
||||||
|
|
||||||
private int currentTextureIndex;
|
|
||||||
|
|
||||||
public CompressedTexturesGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
|
|
||||||
{
|
|
||||||
Logger.LogInfo("Press Left and Right to cycle between textures");
|
|
||||||
Logger.LogInfo("Setting texture to: " + textureNames[0]);
|
|
||||||
|
|
||||||
// Load the shaders
|
|
||||||
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
|
|
||||||
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
|
|
||||||
|
|
||||||
// Create the graphics pipeline
|
|
||||||
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
|
||||||
MainWindow.SwapchainFormat,
|
|
||||||
vertShaderModule,
|
|
||||||
fragShaderModule
|
|
||||||
);
|
|
||||||
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
|
|
||||||
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
|
|
||||||
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
|
||||||
|
|
||||||
// Create sampler
|
|
||||||
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap);
|
|
||||||
|
|
||||||
// Create texture array
|
|
||||||
textures = new Texture[textureNames.Length];
|
|
||||||
|
|
||||||
// Create and populate the GPU resources
|
|
||||||
var resourceUploader = new ResourceUploader(GraphicsDevice);
|
|
||||||
|
|
||||||
vertexBuffer = resourceUploader.CreateBuffer(
|
|
||||||
[
|
|
||||||
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
|
|
||||||
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)),
|
|
||||||
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
|
|
||||||
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1))
|
|
||||||
],
|
|
||||||
BufferUsageFlags.Vertex
|
|
||||||
);
|
|
||||||
|
|
||||||
indexBuffer = resourceUploader.CreateBuffer<ushort>(
|
|
||||||
[
|
|
||||||
0, 1, 2,
|
|
||||||
0, 2, 3,
|
|
||||||
],
|
|
||||||
BufferUsageFlags.Index
|
|
||||||
);
|
|
||||||
|
|
||||||
for (int i = 0; i < textureNames.Length; i += 1)
|
|
||||||
{
|
|
||||||
Logger.LogInfo(textureNames[i]);
|
|
||||||
textures[i] = resourceUploader.CreateTextureFromDDS(TestUtils.GetTexturePath(textureNames[i] + ".dds"));
|
|
||||||
}
|
|
||||||
|
|
||||||
resourceUploader.Upload();
|
|
||||||
resourceUploader.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update(System.TimeSpan delta)
|
|
||||||
{
|
|
||||||
int prevSamplerIndex = currentTextureIndex;
|
|
||||||
|
|
||||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
|
|
||||||
{
|
|
||||||
currentTextureIndex -= 1;
|
|
||||||
if (currentTextureIndex < 0)
|
|
||||||
{
|
|
||||||
currentTextureIndex = textureNames.Length - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
|
|
||||||
{
|
|
||||||
currentTextureIndex += 1;
|
|
||||||
if (currentTextureIndex >= textureNames.Length)
|
|
||||||
{
|
|
||||||
currentTextureIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prevSamplerIndex != currentTextureIndex)
|
|
||||||
{
|
|
||||||
Logger.LogInfo("Setting texture to: " + textureNames[currentTextureIndex]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Draw(double alpha)
|
|
||||||
{
|
|
||||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
|
||||||
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
|
|
||||||
if (backbuffer != null)
|
|
||||||
{
|
|
||||||
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
|
|
||||||
cmdbuf.BindGraphicsPipeline(pipeline);
|
|
||||||
cmdbuf.BindVertexBuffers(vertexBuffer);
|
|
||||||
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
|
|
||||||
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textures[currentTextureIndex], sampler));
|
|
||||||
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
|
|
||||||
cmdbuf.EndRenderPass();
|
|
||||||
}
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
CompressedTexturesGame game = new CompressedTexturesGame();
|
|
||||||
game.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
using MoonWorks;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Input;
|
||||||
|
|
||||||
|
namespace MoonWorksGraphicsTests;
|
||||||
|
|
||||||
|
class ComputeUniformsExample : Example
|
||||||
|
{
|
||||||
|
private ComputePipeline GradientPipeline;
|
||||||
|
private Texture RenderTexture;
|
||||||
|
|
||||||
|
record struct GradientTextureComputeUniforms(float Time);
|
||||||
|
private GradientTextureComputeUniforms Uniforms;
|
||||||
|
|
||||||
|
public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs)
|
||||||
|
{
|
||||||
|
Window = window;
|
||||||
|
GraphicsDevice = graphicsDevice;
|
||||||
|
|
||||||
|
Window.SetTitle("ComputeUniforms");
|
||||||
|
Uniforms.Time = 0;
|
||||||
|
|
||||||
|
// Create the compute pipeline that writes texture data
|
||||||
|
Shader gradientTextureComputeShader = new Shader(
|
||||||
|
GraphicsDevice,
|
||||||
|
TestUtils.GetShaderPath("GradientTexture.comp"),
|
||||||
|
"main",
|
||||||
|
ShaderStage.Compute,
|
||||||
|
ShaderFormat.SPIRV
|
||||||
|
);
|
||||||
|
|
||||||
|
GradientPipeline = new ComputePipeline(
|
||||||
|
GraphicsDevice,
|
||||||
|
gradientTextureComputeShader,
|
||||||
|
new ComputePipelineResourceInfo {
|
||||||
|
ReadWriteStorageTextureCount = 1,
|
||||||
|
UniformBufferCount = 1
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
gradientTextureComputeShader.Dispose();
|
||||||
|
|
||||||
|
RenderTexture = Texture.CreateTexture2D(
|
||||||
|
GraphicsDevice,
|
||||||
|
Window.Width,
|
||||||
|
Window.Height,
|
||||||
|
TextureFormat.R8G8B8A8,
|
||||||
|
TextureUsageFlags.ComputeStorageWrite | TextureUsageFlags.Sampler
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(System.TimeSpan delta)
|
||||||
|
{
|
||||||
|
Uniforms.Time += (float) delta.TotalSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Draw(double alpha)
|
||||||
|
{
|
||||||
|
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
|
Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window);
|
||||||
|
if (swapchainTexture != null)
|
||||||
|
{
|
||||||
|
var computePass = cmdbuf.BeginComputePass(new StorageTextureReadWriteBinding
|
||||||
|
{
|
||||||
|
TextureSlice = RenderTexture,
|
||||||
|
Cycle = true
|
||||||
|
});
|
||||||
|
|
||||||
|
computePass.BindComputePipeline(GradientPipeline);
|
||||||
|
computePass.PushUniformData(Uniforms);
|
||||||
|
computePass.Dispatch(RenderTexture.Width / 8, RenderTexture.Height / 8, 1);
|
||||||
|
cmdbuf.EndComputePass(computePass);
|
||||||
|
|
||||||
|
cmdbuf.Blit(RenderTexture, swapchainTexture, Filter.Linear, false);
|
||||||
|
}
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Destroy()
|
||||||
|
{
|
||||||
|
GradientPipeline.Dispose();
|
||||||
|
RenderTexture.Dispose();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,132 +0,0 @@
|
||||||
using MoonWorks;
|
|
||||||
using MoonWorks.Graphics;
|
|
||||||
using MoonWorks.Math.Float;
|
|
||||||
|
|
||||||
namespace MoonWorks.Test
|
|
||||||
{
|
|
||||||
class ComputeUniformsGame : Game
|
|
||||||
{
|
|
||||||
private GraphicsPipeline drawPipeline;
|
|
||||||
private Texture texture;
|
|
||||||
private Sampler sampler;
|
|
||||||
private GpuBuffer vertexBuffer;
|
|
||||||
|
|
||||||
struct GradientTextureComputeUniforms
|
|
||||||
{
|
|
||||||
public uint groupCountX;
|
|
||||||
public uint groupCountY;
|
|
||||||
|
|
||||||
public GradientTextureComputeUniforms(uint w, uint h)
|
|
||||||
{
|
|
||||||
groupCountX = w;
|
|
||||||
groupCountY = h;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComputeUniformsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
|
|
||||||
{
|
|
||||||
// Create the compute pipeline that writes texture data
|
|
||||||
ShaderModule gradientTextureComputeShaderModule = new ShaderModule(
|
|
||||||
GraphicsDevice,
|
|
||||||
TestUtils.GetShaderPath("GradientTexture.comp")
|
|
||||||
);
|
|
||||||
|
|
||||||
ComputePipeline gradientTextureComputePipeline = new ComputePipeline(
|
|
||||||
GraphicsDevice,
|
|
||||||
ComputeShaderInfo.Create<GradientTextureComputeUniforms>(gradientTextureComputeShaderModule, "main", 0, 1)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create the graphics pipeline
|
|
||||||
ShaderModule vertShaderModule = new ShaderModule(
|
|
||||||
GraphicsDevice,
|
|
||||||
TestUtils.GetShaderPath("TexturedQuad.vert")
|
|
||||||
);
|
|
||||||
|
|
||||||
ShaderModule fragShaderModule = new ShaderModule(
|
|
||||||
GraphicsDevice,
|
|
||||||
TestUtils.GetShaderPath("TexturedQuad.frag")
|
|
||||||
);
|
|
||||||
|
|
||||||
GraphicsPipelineCreateInfo drawPipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
|
||||||
MainWindow.SwapchainFormat,
|
|
||||||
vertShaderModule,
|
|
||||||
fragShaderModule
|
|
||||||
);
|
|
||||||
drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
|
|
||||||
drawPipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
|
|
||||||
|
|
||||||
drawPipeline = new GraphicsPipeline(
|
|
||||||
GraphicsDevice,
|
|
||||||
drawPipelineCreateInfo
|
|
||||||
);
|
|
||||||
|
|
||||||
texture = Texture.CreateTexture2D(
|
|
||||||
GraphicsDevice,
|
|
||||||
MainWindow.Width,
|
|
||||||
MainWindow.Height,
|
|
||||||
TextureFormat.R8G8B8A8,
|
|
||||||
TextureUsageFlags.Compute | TextureUsageFlags.Sampler
|
|
||||||
);
|
|
||||||
|
|
||||||
sampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
|
|
||||||
|
|
||||||
// Upload GPU resources and dispatch compute work
|
|
||||||
|
|
||||||
var resourceUploader = new ResourceUploader(GraphicsDevice);
|
|
||||||
|
|
||||||
vertexBuffer = resourceUploader.CreateBuffer(
|
|
||||||
[
|
|
||||||
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
|
|
||||||
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)),
|
|
||||||
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
|
|
||||||
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
|
|
||||||
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
|
|
||||||
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
|
|
||||||
],
|
|
||||||
BufferUsageFlags.Vertex
|
|
||||||
);
|
|
||||||
|
|
||||||
resourceUploader.Upload();
|
|
||||||
resourceUploader.Dispose();
|
|
||||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
|
||||||
|
|
||||||
GradientTextureComputeUniforms gradientUniforms = new GradientTextureComputeUniforms(
|
|
||||||
texture.Width / 8,
|
|
||||||
texture.Height / 8
|
|
||||||
);
|
|
||||||
|
|
||||||
cmdbuf.BeginComputePass();
|
|
||||||
cmdbuf.BindComputePipeline(gradientTextureComputePipeline);
|
|
||||||
cmdbuf.BindComputeTextures(new ComputeTextureBinding(texture, 0));
|
|
||||||
cmdbuf.PushComputeShaderUniforms(gradientUniforms);
|
|
||||||
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1);
|
|
||||||
cmdbuf.EndComputePass();
|
|
||||||
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update(System.TimeSpan delta) { }
|
|
||||||
|
|
||||||
protected override void Draw(double alpha)
|
|
||||||
{
|
|
||||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
|
||||||
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
|
|
||||||
if (backbuffer != null)
|
|
||||||
{
|
|
||||||
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue));
|
|
||||||
cmdbuf.BindGraphicsPipeline(drawPipeline);
|
|
||||||
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
|
|
||||||
cmdbuf.BindVertexBuffers(vertexBuffer);
|
|
||||||
cmdbuf.DrawPrimitives(0, 2);
|
|
||||||
cmdbuf.EndRenderPass();
|
|
||||||
}
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
ComputeUniformsGame game = new ComputeUniformsGame();
|
|
||||||
game.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
using MoonWorks.Graphics;
|
using MoonWorks.Graphics;
|
||||||
using MoonWorks.Math.Float;
|
using MoonWorks.Math.Float;
|
||||||
|
|
||||||
namespace MoonWorks.Test
|
namespace MoonWorksGraphicsTests
|
||||||
{
|
{
|
||||||
class CopyTextureGame : Game
|
class CopyTextureGame : Game
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
using System;
|
using System;
|
||||||
using MoonWorks;
|
using MoonWorks;
|
||||||
using MoonWorks.Graphics;
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Input;
|
||||||
|
|
||||||
namespace MoonWorksGraphicsTests;
|
namespace MoonWorksGraphicsTests;
|
||||||
|
|
||||||
public abstract class Example
|
public abstract class Example
|
||||||
{
|
{
|
||||||
protected Window Window;
|
protected Window Window;
|
||||||
protected GraphicsDevice GraphicsDevice;
|
public GraphicsDevice GraphicsDevice;
|
||||||
|
public Inputs Inputs;
|
||||||
|
|
||||||
public abstract void Init(Window window, GraphicsDevice graphicsDevice);
|
public abstract void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs);
|
||||||
public abstract void Update(TimeSpan delta);
|
public abstract void Update(TimeSpan delta);
|
||||||
public abstract void Draw(double alpha);
|
public abstract void Draw(double alpha);
|
||||||
public abstract void Destroy();
|
public abstract void Destroy();
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="..\MoonWorks.Test.Common\Content\**\*.*">
|
<Content Include="Common\Content\**\*.*">
|
||||||
<Link>Content\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>Content\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
@ -16,6 +17,22 @@
|
||||||
<ProjectReference Include="..\MoonWorks\MoonWorks.csproj" />
|
<ProjectReference Include="..\MoonWorks\MoonWorks.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- TODO: remove this once examples are fully converted -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<DefaultItemExcludes>$(DefaultItemExcludes);Examples\**\*</DefaultItemExcludes>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Examples\Example.cs" />
|
||||||
|
<Compile Include="Examples\BasicComputeExample.cs" />
|
||||||
|
<Compile Include="Examples\BasicStencilExample.cs" />
|
||||||
|
<Compile Include="Examples\BasicTriangleExample.cs" />
|
||||||
|
<Compile Include="Examples\ClearScreenExample.cs" />
|
||||||
|
<Compile Include="Examples\ClearScreen_MultiWindowExample.cs" />
|
||||||
|
<Compile Include="Examples\CompressedTexturesExample.cs" />
|
||||||
|
<Compile Include="Examples\ComputeUniformsExample.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project=".\CopyMoonlibs.targets" />
|
<Import Project=".\CopyMoonlibs.targets" />
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
21
Program.cs
21
Program.cs
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using MoonWorks;
|
using MoonWorks;
|
||||||
using MoonWorks.Graphics;
|
using MoonWorks.Graphics;
|
||||||
using MoonWorks.Test;
|
|
||||||
|
|
||||||
namespace MoonWorksGraphicsTests;
|
namespace MoonWorksGraphicsTests;
|
||||||
|
|
||||||
|
@ -9,8 +8,13 @@ class Program : Game
|
||||||
{
|
{
|
||||||
Example[] Examples =
|
Example[] Examples =
|
||||||
[
|
[
|
||||||
|
new ClearScreenExample(),
|
||||||
|
new ClearScreen_MultiWindowExample(),
|
||||||
|
new BasicStencilExample(),
|
||||||
|
new BasicTriangleExample(),
|
||||||
|
new CompressedTexturesExample(),
|
||||||
new BasicComputeExample(),
|
new BasicComputeExample(),
|
||||||
new BasicStencilGame()
|
new ComputeUniformsExample()
|
||||||
];
|
];
|
||||||
|
|
||||||
int ExampleIndex = 0;
|
int ExampleIndex = 0;
|
||||||
|
@ -23,11 +27,12 @@ class Program : Game
|
||||||
bool debugMode = false
|
bool debugMode = false
|
||||||
) : base(windowCreateInfo, frameLimiterSettings, preferredBackends, targetTimestep, debugMode)
|
) : base(windowCreateInfo, frameLimiterSettings, preferredBackends, targetTimestep, debugMode)
|
||||||
{
|
{
|
||||||
|
Examples[ExampleIndex].Init(MainWindow, GraphicsDevice, Inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(TimeSpan delta)
|
protected override void Update(TimeSpan delta)
|
||||||
{
|
{
|
||||||
if (Inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.A))
|
if (Inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.Q))
|
||||||
{
|
{
|
||||||
Examples[ExampleIndex].Destroy();
|
Examples[ExampleIndex].Destroy();
|
||||||
|
|
||||||
|
@ -37,15 +42,15 @@ class Program : Game
|
||||||
ExampleIndex = Examples.Length - 1;
|
ExampleIndex = Examples.Length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Examples[ExampleIndex].Init(MainWindow, GraphicsDevice);
|
Examples[ExampleIndex].Init(MainWindow, GraphicsDevice, Inputs);
|
||||||
}
|
}
|
||||||
else if (Inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.D))
|
else if (Inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.E))
|
||||||
{
|
{
|
||||||
Examples[ExampleIndex].Destroy();
|
Examples[ExampleIndex].Destroy();
|
||||||
|
|
||||||
ExampleIndex = (ExampleIndex + 1) % Examples.Length;
|
ExampleIndex = (ExampleIndex + 1) % Examples.Length;
|
||||||
|
|
||||||
Examples[ExampleIndex].Init(MainWindow, GraphicsDevice);
|
Examples[ExampleIndex].Init(MainWindow, GraphicsDevice, Inputs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -68,8 +73,8 @@ class Program : Game
|
||||||
|
|
||||||
var windowCreateInfo = new WindowCreateInfo(
|
var windowCreateInfo = new WindowCreateInfo(
|
||||||
"MoonWorksGraphicsTests",
|
"MoonWorksGraphicsTests",
|
||||||
1280,
|
640,
|
||||||
720,
|
480,
|
||||||
ScreenMode.Windowed,
|
ScreenMode.Windowed,
|
||||||
SwapchainComposition.SDR,
|
SwapchainComposition.SDR,
|
||||||
PresentMode.VSync
|
PresentMode.VSync
|
||||||
|
|
Loading…
Reference in New Issue