Add VertexSampler test
parent
49abd4e9ae
commit
db814ec092
Binary file not shown.
|
@ -0,0 +1,14 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 Position;
|
||||||
|
layout (location = 1) in vec2 TexCoord;
|
||||||
|
|
||||||
|
layout (location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
layout(binding = 0, set = 0) uniform sampler2D Sampler;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
outColor = texture(Sampler, TexCoord);
|
||||||
|
gl_Position = vec4(Position, 1);
|
||||||
|
}
|
|
@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Texture3D", "Texture3D\Text
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InstancingAndOffsets", "InstancingAndOffsets\InstancingAndOffsets.csproj", "{5CDA8D41-F96C-4DE7-AD53-5A76C4C0CC31}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InstancingAndOffsets", "InstancingAndOffsets\InstancingAndOffsets.csproj", "{5CDA8D41-F96C-4DE7-AD53-5A76C4C0CC31}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VertexSampler", "VertexSampler\VertexSampler.csproj", "{C525B6DE-3003-45D5-BB83-89679B108C08}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x64 = Debug|x64
|
Debug|x64 = Debug|x64
|
||||||
|
@ -129,6 +131,10 @@ Global
|
||||||
{5CDA8D41-F96C-4DE7-AD53-5A76C4C0CC31}.Debug|x64.Build.0 = Debug|x64
|
{5CDA8D41-F96C-4DE7-AD53-5A76C4C0CC31}.Debug|x64.Build.0 = Debug|x64
|
||||||
{5CDA8D41-F96C-4DE7-AD53-5A76C4C0CC31}.Release|x64.ActiveCfg = Release|x64
|
{5CDA8D41-F96C-4DE7-AD53-5A76C4C0CC31}.Release|x64.ActiveCfg = Release|x64
|
||||||
{5CDA8D41-F96C-4DE7-AD53-5A76C4C0CC31}.Release|x64.Build.0 = Release|x64
|
{5CDA8D41-F96C-4DE7-AD53-5A76C4C0CC31}.Release|x64.Build.0 = Release|x64
|
||||||
|
{C525B6DE-3003-45D5-BB83-89679B108C08}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{C525B6DE-3003-45D5-BB83-89679B108C08}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{C525B6DE-3003-45D5-BB83-89679B108C08}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{C525B6DE-3003-45D5-BB83-89679B108C08}.Release|x64.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -71,3 +71,7 @@ Plays a sample Ogg Theora video file. Tests YUV textures and video rendering.
|
||||||
**Texture3D**
|
**Texture3D**
|
||||||
|
|
||||||
Displays 2D slices of a 3D texture. Tests creating and drawing 3D textures.
|
Displays 2D slices of a 3D texture. Tests creating and drawing 3D textures.
|
||||||
|
|
||||||
|
**VertexSampler**
|
||||||
|
|
||||||
|
Displays a triangle whose colors are driven by sampling a texture in the vertex shader.
|
||||||
|
|
|
@ -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,82 @@
|
||||||
|
using MoonWorks;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Math.Float;
|
||||||
|
|
||||||
|
namespace MoonWorks.Test
|
||||||
|
{
|
||||||
|
class VertexSamplerGame : Game
|
||||||
|
{
|
||||||
|
private GraphicsPipeline pipeline;
|
||||||
|
private Buffer vertexBuffer;
|
||||||
|
private Texture texture;
|
||||||
|
private Sampler sampler;
|
||||||
|
|
||||||
|
public VertexSamplerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||||
|
{
|
||||||
|
// Load the shaders
|
||||||
|
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionSamplerVert"));
|
||||||
|
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor"));
|
||||||
|
|
||||||
|
// Create the graphics pipeline
|
||||||
|
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
||||||
|
MainWindow.SwapchainFormat,
|
||||||
|
vertShaderModule,
|
||||||
|
fragShaderModule
|
||||||
|
);
|
||||||
|
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
|
||||||
|
pipelineCreateInfo.VertexShaderInfo.SamplerBindingCount = 1;
|
||||||
|
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||||
|
|
||||||
|
// Create and populate the GPU resources
|
||||||
|
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 3);
|
||||||
|
texture = new Texture(GraphicsDevice, new TextureCreateInfo
|
||||||
|
{
|
||||||
|
Width = 3,
|
||||||
|
Height = 1,
|
||||||
|
Depth = 1,
|
||||||
|
Format = TextureFormat.R8G8B8A8,
|
||||||
|
IsCube = false,
|
||||||
|
LevelCount = 1,
|
||||||
|
UsageFlags = TextureUsageFlags.Sampler
|
||||||
|
});
|
||||||
|
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
|
||||||
|
|
||||||
|
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
|
cmdbuf.SetBufferData(
|
||||||
|
vertexBuffer,
|
||||||
|
new PositionTextureVertex[]
|
||||||
|
{
|
||||||
|
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 0)),
|
||||||
|
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(0.334f, 0)),
|
||||||
|
new PositionTextureVertex(new Vector3(0, -1, 0), new Vector2(0.667f, 0)),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
cmdbuf.SetTextureData(texture, new Color[] { Color.Yellow, Color.Indigo, Color.HotPink });
|
||||||
|
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, Color.Black));
|
||||||
|
cmdbuf.BindGraphicsPipeline(pipeline);
|
||||||
|
cmdbuf.BindVertexBuffers(vertexBuffer);
|
||||||
|
cmdbuf.BindVertexSamplers(new TextureSamplerBinding(texture, sampler));
|
||||||
|
cmdbuf.DrawPrimitives(0, 1, 0, 0);
|
||||||
|
cmdbuf.EndRenderPass();
|
||||||
|
}
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
VertexSamplerGame p = new VertexSamplerGame();
|
||||||
|
p.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue