Add BasicStencil test + set default rasterizer to CCW_CullNone
parent
5233dad0ca
commit
b2aa5adc3b
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MoonWorks\MoonWorks.csproj" />
|
||||
<ProjectReference Include="..\MoonWorks.Test.Common\MoonWorks.Test.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(SolutionDir)NativeAOT_Console.targets" Condition="Exists('$(SolutionDir)NativeAOT_Console.targets')" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,111 @@
|
|||
using MoonWorks;
|
||||
using MoonWorks.Graphics;
|
||||
using MoonWorks.Math.Float;
|
||||
|
||||
namespace MoonWorks.Test
|
||||
{
|
||||
class BasicStencilGame : Game
|
||||
{
|
||||
private GraphicsPipeline maskerPipeline;
|
||||
private GraphicsPipeline maskeePipeline;
|
||||
private Buffer vertexBuffer;
|
||||
private Texture depthStencilTexture;
|
||||
|
||||
public BasicStencilGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||
{
|
||||
// Load the shaders
|
||||
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColorVert"));
|
||||
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor"));
|
||||
|
||||
// Create the graphics pipelines
|
||||
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
||||
MainWindow.SwapchainFormat,
|
||||
vertShaderModule,
|
||||
fragShaderModule
|
||||
);
|
||||
pipelineCreateInfo.AttachmentInfo.HasDepthStencilAttachment = true;
|
||||
pipelineCreateInfo.AttachmentInfo.DepthStencilFormat = TextureFormat.D16S8;
|
||||
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
|
||||
pipelineCreateInfo.DepthStencilState = new DepthStencilState
|
||||
{
|
||||
StencilTestEnable = true,
|
||||
FrontStencilState = new StencilOpState
|
||||
{
|
||||
Reference = 1,
|
||||
WriteMask = 0xFFFFFFFF,
|
||||
CompareOp = CompareOp.Never,
|
||||
FailOp = StencilOp.Replace,
|
||||
}
|
||||
};
|
||||
maskerPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||
|
||||
pipelineCreateInfo.DepthStencilState = new DepthStencilState
|
||||
{
|
||||
StencilTestEnable = true,
|
||||
FrontStencilState = new StencilOpState
|
||||
{
|
||||
Reference = 0,
|
||||
CompareMask = 0xFFFFFFFF,
|
||||
WriteMask = 0,
|
||||
CompareOp = CompareOp.Equal,
|
||||
}
|
||||
};
|
||||
maskeePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||
|
||||
// Create and populate the GPU resources
|
||||
depthStencilTexture = Texture.CreateTexture2D(
|
||||
GraphicsDevice,
|
||||
MainWindow.Width,
|
||||
MainWindow.Height,
|
||||
TextureFormat.D16S8,
|
||||
TextureUsageFlags.DepthStencilTarget
|
||||
);
|
||||
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
|
||||
|
||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||
cmdbuf.SetBufferData(
|
||||
vertexBuffer,
|
||||
new PositionColorVertex[]
|
||||
{
|
||||
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(-1, 1, 0), Color.Red),
|
||||
new PositionColorVertex(new Vector3(1, 1, 0), Color.Lime),
|
||||
new PositionColorVertex(new Vector3(0, -1, 0), Color.Blue),
|
||||
}
|
||||
);
|
||||
GraphicsDevice.Submit(cmdbuf);
|
||||
GraphicsDevice.Wait();
|
||||
}
|
||||
|
||||
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 DepthStencilAttachmentInfo(depthStencilTexture, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare),
|
||||
new ColorAttachmentInfo(backbuffer, Color.Black)
|
||||
);
|
||||
cmdbuf.BindGraphicsPipeline(maskerPipeline);
|
||||
cmdbuf.BindVertexBuffers(vertexBuffer);
|
||||
cmdbuf.DrawPrimitives(0, 1, 0, 0);
|
||||
cmdbuf.BindGraphicsPipeline(maskeePipeline);
|
||||
cmdbuf.DrawPrimitives(3, 1, 0, 0);
|
||||
cmdbuf.EndRenderPass();
|
||||
}
|
||||
GraphicsDevice.Submit(cmdbuf);
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BasicStencilGame p = new BasicStencilGame();
|
||||
p.Run();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ namespace MoonWorks.Test
|
|||
DepthStencilState = DepthStencilState.Disable,
|
||||
MultisampleState = MultisampleState.None,
|
||||
PrimitiveType = PrimitiveType.TriangleList,
|
||||
RasterizerState = RasterizerState.CW_CullNone,
|
||||
RasterizerState = RasterizerState.CCW_CullNone,
|
||||
VertexInputState = VertexInputState.Empty,
|
||||
VertexShaderInfo = GraphicsShaderInfo.Create(vertShaderModule, "main", 0),
|
||||
FragmentShaderInfo = GraphicsShaderInfo.Create(fragShaderModule, "main", 0)
|
||||
|
|
|
@ -53,6 +53,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenderTextureMipmaps", "Ren
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextureMipmaps", "TextureMipmaps\TextureMipmaps.csproj", "{5A1AC35B-EF18-426D-A633-D4899E84EAA7}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicStencil", "Stencil\BasicStencil.csproj", "{E3FCEDC2-BAE3-4E21-AEBA-2AC3504526CD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
|
@ -159,6 +161,10 @@ Global
|
|||
{5A1AC35B-EF18-426D-A633-D4899E84EAA7}.Debug|x64.Build.0 = Debug|x64
|
||||
{5A1AC35B-EF18-426D-A633-D4899E84EAA7}.Release|x64.ActiveCfg = Release|x64
|
||||
{5A1AC35B-EF18-426D-A633-D4899E84EAA7}.Release|x64.Build.0 = Release|x64
|
||||
{E3FCEDC2-BAE3-4E21-AEBA-2AC3504526CD}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{E3FCEDC2-BAE3-4E21-AEBA-2AC3504526CD}.Debug|x64.Build.0 = Debug|x64
|
||||
{E3FCEDC2-BAE3-4E21-AEBA-2AC3504526CD}.Release|x64.ActiveCfg = Release|x64
|
||||
{E3FCEDC2-BAE3-4E21-AEBA-2AC3504526CD}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -91,3 +91,7 @@ Displays a cubemap generated by rendering to a cube render target. Tests binding
|
|||
**RenderTextureMipmaps**
|
||||
|
||||
Displays a quad that can be scaled to reveal various mip levels. The mips are solid colors, generated by clearing various levels of the texture in a render pass. Tests rendering to mipmap levels of a render texture, mip LOD bias, min/max LODs, and mip filter modes.
|
||||
|
||||
**BasicStencil**
|
||||
|
||||
Demonstrates stencil masking using two triangles. Tests stencil buffers and basic stencil operations.
|
||||
|
|
Loading…
Reference in New Issue