diff --git a/MoonWorksComputeSpriteBatch.csproj b/MoonWorksComputeSpriteBatch.csproj
index 715009e..764e39f 100644
--- a/MoonWorksComputeSpriteBatch.csproj
+++ b/MoonWorksComputeSpriteBatch.csproj
@@ -2,7 +2,7 @@
Exe
- net5.0
+ net6.0
true
diff --git a/lib/MoonWorks b/lib/MoonWorks
index cb25e6f..b8b1014 160000
--- a/lib/MoonWorks
+++ b/lib/MoonWorks
@@ -1 +1 @@
-Subproject commit cb25e6feff2d9ac3f399b3a43cd11d374f90f127
+Subproject commit b8b10140a95457a00d658e84d4b67b926f467b15
diff --git a/moonlibs/lib64/libRefresh.so.0 b/moonlibs/lib64/libRefresh.so.0
index c2f6a3a..0d583ce 100755
--- a/moonlibs/lib64/libRefresh.so.0
+++ b/moonlibs/lib64/libRefresh.so.0
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:1914d3dceec819e7724c705be77cf50d003cfbc6a88af274e20cb26c5d4a873b
-size 492552
+oid sha256:cb944bc1142b91a8ace4a96b475634affbce23f35047be6f8f36986534ab169e
+size 170792
diff --git a/src/SpriteBatch.cs b/src/SpriteBatch.cs
index 4cf983e..4e697f1 100644
--- a/src/SpriteBatch.cs
+++ b/src/SpriteBatch.cs
@@ -5,185 +5,184 @@ using MoonWorks.Math;
namespace MoonWorksComputeSpriteBatch
{
- [StructLayout(LayoutKind.Sequential)]
- public struct SpriteBatchUniforms
- {
- public uint VertexCount { get; set; }
- }
+ [StructLayout(LayoutKind.Sequential)]
+ public struct SpriteBatchUniforms
+ {
+ public uint VertexCount { get; set; }
+ }
- public class SpriteBatch
- {
- public const int MAX_SPRITES = 65536;
- private const int MAX_VERTICES = MAX_SPRITES * 4;
- private const int MAX_INDICES = MAX_SPRITES * 6;
- private const int MAX_MATRICES = MAX_SPRITES;
+ public class SpriteBatch
+ {
+ public const int MAX_SPRITES = 65536;
+ private const int MAX_VERTICES = MAX_SPRITES * 4;
+ private const int MAX_INDICES = MAX_SPRITES * 6;
+ private const int MAX_MATRICES = MAX_SPRITES;
- private static ComputePipeline ComputePipeline = null;
+ private static ComputePipeline ComputePipeline = null;
- private Buffer VertexBuffer { get; }
- private Buffer IndexBuffer { get; }
- private Buffer TransformBuffer { get; }
+ private Buffer VertexBuffer { get; }
+ private Buffer IndexBuffer { get; }
+ private Buffer TransformBuffer { get; }
- private readonly VertexPositionTexcoord[] Vertices;
- private static readonly short[] Indices = GenerateIndexArray();
- private readonly Matrix4x4[] Transforms;
+ private readonly VertexPositionTexcoord[] Vertices;
+ private static readonly short[] Indices = GenerateIndexArray();
+ private readonly Matrix4x4[] Transforms;
- private Texture CurrentTexture { get; set; }
- private Sampler CurrentSampler { get; set; }
- private uint VertexCount { get; set; }
- private uint TransformCount { get; set; }
+ private Texture CurrentTexture { get; set; }
+ private Sampler CurrentSampler { get; set; }
+ private uint VertexCount { get; set; }
+ private uint TransformCount { get; set; }
- public SpriteBatch(GraphicsDevice graphicsDevice)
- {
- if (ComputePipeline == null)
- {
- var computeShaderModule = new ShaderModule(graphicsDevice, Path.Combine(System.Environment.CurrentDirectory, "Content", "spritebatch.comp.spv"));
+ public SpriteBatch(GraphicsDevice graphicsDevice)
+ {
+ if (ComputePipeline == null)
+ {
+ var computeShaderModule = new ShaderModule(graphicsDevice, Path.Combine(System.Environment.CurrentDirectory, "Content", "spritebatch.comp.spv"));
- var computeShaderState = new ShaderStageState
- {
- ShaderModule = computeShaderModule,
- EntryPointName = "main",
- UniformBufferSize = (uint) Marshal.SizeOf()
- };
+ var computeShaderState = new ShaderStageState
+ {
+ ShaderModule = computeShaderModule,
+ EntryPointName = "main",
+ UniformBufferSize = (uint)Marshal.SizeOf()
+ };
- ComputePipeline = new ComputePipeline(graphicsDevice, computeShaderState, 2, 0);
- }
+ ComputePipeline = new ComputePipeline(graphicsDevice, computeShaderState, 2, 0);
+ }
- Vertices = new VertexPositionTexcoord[MAX_VERTICES];
- VertexBuffer = new Buffer(
- graphicsDevice,
- BufferUsageFlags.Vertex | BufferUsageFlags.Compute,
- (uint)(MAX_VERTICES * Marshal.SizeOf())
- );
+ Vertices = new VertexPositionTexcoord[MAX_VERTICES];
+ VertexBuffer = new Buffer(
+ graphicsDevice,
+ BufferUsageFlags.Vertex | BufferUsageFlags.Compute,
+ (uint)(MAX_VERTICES * Marshal.SizeOf())
+ );
- IndexBuffer = new Buffer(
- graphicsDevice,
- BufferUsageFlags.Index | BufferUsageFlags.Compute,
- MAX_INDICES * sizeof(short)
- );
+ IndexBuffer = new Buffer(
+ graphicsDevice,
+ BufferUsageFlags.Index | BufferUsageFlags.Compute,
+ MAX_INDICES * sizeof(short)
+ );
- Transforms = new Matrix4x4[MAX_MATRICES];
- TransformBuffer = new Buffer(
- graphicsDevice,
- BufferUsageFlags.Compute,
- (uint)(MAX_MATRICES * Marshal.SizeOf())
- );
+ Transforms = new Matrix4x4[MAX_MATRICES];
+ TransformBuffer = new Buffer(
+ graphicsDevice,
+ BufferUsageFlags.Compute,
+ (uint)(MAX_MATRICES * Marshal.SizeOf())
+ );
- var commandBuffer = graphicsDevice.AcquireCommandBuffer();
- commandBuffer.SetBufferData(IndexBuffer, Indices);
- graphicsDevice.Submit(commandBuffer);
- }
+ var commandBuffer = graphicsDevice.AcquireCommandBuffer();
+ commandBuffer.SetBufferData(IndexBuffer, Indices);
+ graphicsDevice.Submit(commandBuffer);
+ }
- public void Start(Texture texture, Sampler sampler)
- {
- TransformCount = 0;
- VertexCount = 0;
- CurrentTexture = texture;
- CurrentSampler = sampler;
- }
+ public void Start(Texture texture, Sampler sampler)
+ {
+ TransformCount = 0;
+ VertexCount = 0;
+ CurrentTexture = texture;
+ CurrentSampler = sampler;
+ }
- public void Add(Sprite sprite, Matrix4x4 transform, Color color)
- {
- Vertices[VertexCount].position.X = 0;
- Vertices[VertexCount].position.Y = 0;
- Vertices[VertexCount].texcoord.X = sprite.Texcoord.X;
- Vertices[VertexCount].texcoord.Y = sprite.Texcoord.Y;
- Vertices[VertexCount].color.X = color.R / 255f;
- Vertices[VertexCount].color.Y = color.G / 255f;
- Vertices[VertexCount].color.Z = color.B / 255f;
- Vertices[VertexCount].color.W = color.A / 255f;
+ public void Add(Sprite sprite, Matrix4x4 transform, Color color)
+ {
+ Vertices[VertexCount].position.X = 0;
+ Vertices[VertexCount].position.Y = 0;
+ Vertices[VertexCount].texcoord.X = sprite.Texcoord.X;
+ Vertices[VertexCount].texcoord.Y = sprite.Texcoord.Y;
+ Vertices[VertexCount].color.X = color.R / 255f;
+ Vertices[VertexCount].color.Y = color.G / 255f;
+ Vertices[VertexCount].color.Z = color.B / 255f;
+ Vertices[VertexCount].color.W = color.A / 255f;
- Vertices[VertexCount + 1].position.X = sprite.Width;
- Vertices[VertexCount + 1].position.Y = 0;
- Vertices[VertexCount + 1].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W;
- Vertices[VertexCount + 1].texcoord.Y = sprite.Texcoord.Y;
- Vertices[VertexCount + 1].color.X = color.R / 255f;
- Vertices[VertexCount + 1].color.Y = color.G / 255f;
- Vertices[VertexCount + 1].color.Z = color.B / 255f;
- Vertices[VertexCount + 1].color.W = color.A / 255f;
+ Vertices[VertexCount + 1].position.X = sprite.Width;
+ Vertices[VertexCount + 1].position.Y = 0;
+ Vertices[VertexCount + 1].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W;
+ Vertices[VertexCount + 1].texcoord.Y = sprite.Texcoord.Y;
+ Vertices[VertexCount + 1].color.X = color.R / 255f;
+ Vertices[VertexCount + 1].color.Y = color.G / 255f;
+ Vertices[VertexCount + 1].color.Z = color.B / 255f;
+ Vertices[VertexCount + 1].color.W = color.A / 255f;
- Vertices[VertexCount + 2].position.X = 0;
- Vertices[VertexCount + 2].position.Y = sprite.Height;
- Vertices[VertexCount + 2].texcoord.X = sprite.Texcoord.X;
- Vertices[VertexCount + 2].texcoord.Y = sprite.Texcoord.Y + sprite.Texcoord.H;
- Vertices[VertexCount + 2].color.X = color.R / 255f;
- Vertices[VertexCount + 2].color.Y = color.G / 255f;
- Vertices[VertexCount + 2].color.Z = color.B / 255f;
- Vertices[VertexCount + 2].color.W = color.A / 255f;
+ Vertices[VertexCount + 2].position.X = 0;
+ Vertices[VertexCount + 2].position.Y = sprite.Height;
+ Vertices[VertexCount + 2].texcoord.X = sprite.Texcoord.X;
+ Vertices[VertexCount + 2].texcoord.Y = sprite.Texcoord.Y + sprite.Texcoord.H;
+ Vertices[VertexCount + 2].color.X = color.R / 255f;
+ Vertices[VertexCount + 2].color.Y = color.G / 255f;
+ Vertices[VertexCount + 2].color.Z = color.B / 255f;
+ Vertices[VertexCount + 2].color.W = color.A / 255f;
- Vertices[VertexCount + 3].position.X = sprite.Width;
- Vertices[VertexCount + 3].position.Y = sprite.Height;
- Vertices[VertexCount + 3].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W;
- Vertices[VertexCount + 3].texcoord.Y = sprite.Texcoord.Y + sprite.Texcoord.H;
- Vertices[VertexCount + 3].color.X = color.R / 255f;
- Vertices[VertexCount + 3].color.Y = color.G / 255f;
- Vertices[VertexCount + 3].color.Z = color.B / 255f;
- Vertices[VertexCount + 3].color.W = color.A / 255f;
+ Vertices[VertexCount + 3].position.X = sprite.Width;
+ Vertices[VertexCount + 3].position.Y = sprite.Height;
+ Vertices[VertexCount + 3].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W;
+ Vertices[VertexCount + 3].texcoord.Y = sprite.Texcoord.Y + sprite.Texcoord.H;
+ Vertices[VertexCount + 3].color.X = color.R / 255f;
+ Vertices[VertexCount + 3].color.Y = color.G / 255f;
+ Vertices[VertexCount + 3].color.Z = color.B / 255f;
+ Vertices[VertexCount + 3].color.W = color.A / 255f;
- VertexCount += 4;
+ VertexCount += 4;
- Transforms[TransformCount] = transform;
- TransformCount += 1;
- }
+ Transforms[TransformCount] = transform;
+ TransformCount += 1;
+ }
- public void Flush(
- CommandBuffer commandBuffer,
- RenderPass renderPass,
- Framebuffer framebuffer,
- Rect renderArea,
- GraphicsPipeline graphicsPipeline,
- CameraUniforms cameraUniforms
- ) {
- if (VertexCount == 0)
- {
- return;
- }
+ public void Flush(
+ CommandBuffer commandBuffer,
+ ColorAttachmentInfo colorAttachmentInfo,
+ GraphicsPipeline graphicsPipeline,
+ CameraUniforms cameraUniforms
+ )
+ {
+ if (VertexCount == 0)
+ {
+ return;
+ }
- commandBuffer.SetBufferData(VertexBuffer, Vertices, 0, 0, VertexCount);
- commandBuffer.SetBufferData(TransformBuffer, Transforms, 0, 0, TransformCount);
+ commandBuffer.SetBufferData(VertexBuffer, Vertices, 0, 0, VertexCount);
+ commandBuffer.SetBufferData(TransformBuffer, Transforms, 0, 0, TransformCount);
- commandBuffer.BindComputePipeline(ComputePipeline);
- commandBuffer.BindComputeBuffers(VertexBuffer, TransformBuffer);
- var offset = commandBuffer.PushComputeShaderUniforms(new SpriteBatchUniforms
- {
- VertexCount = VertexCount
- });
- commandBuffer.DispatchCompute(System.Math.Max(1, VertexCount / 256), 1, 1, offset);
+ commandBuffer.BindComputePipeline(ComputePipeline);
+ commandBuffer.BindComputeBuffers(VertexBuffer, TransformBuffer);
+ var offset = commandBuffer.PushComputeShaderUniforms(new SpriteBatchUniforms
+ {
+ VertexCount = VertexCount
+ });
+ commandBuffer.DispatchCompute(System.Math.Max(1, VertexCount / 256), 1, 1, offset);
- commandBuffer.BeginRenderPass(renderPass, framebuffer, renderArea, Vector4.Zero);
- commandBuffer.BindGraphicsPipeline(graphicsPipeline);
- commandBuffer.BindVertexBuffers(VertexBuffer);
- commandBuffer.BindIndexBuffer(IndexBuffer, IndexElementSize.Sixteen);
- commandBuffer.BindFragmentSamplers(new TextureSamplerBinding { Texture = CurrentTexture, Sampler = CurrentSampler });
- offset = commandBuffer.PushVertexShaderUniforms(cameraUniforms);
+ commandBuffer.BeginRenderPass(colorAttachmentInfo);
+ commandBuffer.BindGraphicsPipeline(graphicsPipeline);
+ commandBuffer.BindVertexBuffers(VertexBuffer);
+ commandBuffer.BindIndexBuffer(IndexBuffer, IndexElementSize.Sixteen);
+ commandBuffer.BindFragmentSamplers(new TextureSamplerBinding { Texture = CurrentTexture, Sampler = CurrentSampler });
+ offset = commandBuffer.PushVertexShaderUniforms(cameraUniforms);
- commandBuffer.DrawIndexedPrimitives(
- 0,
- 0,
- VertexCount / 2,
- offset,
- 0
- );
+ commandBuffer.DrawIndexedPrimitives(
+ 0,
+ 0,
+ VertexCount / 2,
+ offset,
+ 0
+ );
- commandBuffer.EndRenderPass();
+ commandBuffer.EndRenderPass();
- VertexCount = 0;
- TransformCount = 0;
- }
+ VertexCount = 0;
+ TransformCount = 0;
+ }
- private static short[] GenerateIndexArray()
- {
- var result = new short[MAX_INDICES];
- for (int i = 0, j = 0; i < MAX_INDICES; i += 6, j += 4)
- {
- result[i] = (short)j;
- result[i + 1] = (short)(j + 1);
- result[i + 2] = (short)(j + 2);
- result[i + 3] = (short)(j + 2);
- result[i + 4] = (short)(j + 1);
- result[i + 5] = (short)(j + 3);
- }
- return result;
- }
- }
+ private static short[] GenerateIndexArray()
+ {
+ var result = new short[MAX_INDICES];
+ for (int i = 0, j = 0; i < MAX_INDICES; i += 6, j += 4)
+ {
+ result[i] = (short)j;
+ result[i + 1] = (short)(j + 1);
+ result[i + 2] = (short)(j + 2);
+ result[i + 3] = (short)(j + 2);
+ result[i + 4] = (short)(j + 1);
+ result[i + 5] = (short)(j + 3);
+ }
+ return result;
+ }
+ }
}
diff --git a/src/TestGame.cs b/src/TestGame.cs
index a557c02..253ebf2 100644
--- a/src/TestGame.cs
+++ b/src/TestGame.cs
@@ -9,238 +9,238 @@ using MoonWorks.Window;
namespace MoonWorksComputeSpriteBatch
{
- public class TestGame : Game
- {
- private RenderPass mainRenderPass;
- private RenderTarget mainColorTarget;
- private Framebuffer mainFramebuffer;
- private Rect mainRenderArea;
+ public class TestGame : Game
+ {
+ private RenderTarget mainColorTarget;
- private GraphicsPipeline spritePipeline;
+ private GraphicsPipeline spritePipeline;
- private SpriteBatch spriteBatch;
+ private SpriteBatch spriteBatch;
- private Texture whitePixel;
- private Sampler sampler;
+ private Texture whitePixel;
+ private Sampler sampler;
- private const int SPRITECOUNT = SpriteBatch.MAX_SPRITES;
- private Vector3[] positions = new Vector3[SPRITECOUNT];
+ private const int SPRITECOUNT = SpriteBatch.MAX_SPRITES;
+ private Vector3[] positions = new Vector3[SPRITECOUNT];
- private uint windowWidth;
- private uint windowHeight;
+ private uint windowWidth;
+ private uint windowHeight;
- private Random random = new Random();
+ private Random random = new Random();
- public TestGame(WindowCreateInfo windowCreateInfo, PresentMode presentMode, int targetTimestep = 60, bool debugMode = false) : base(windowCreateInfo, presentMode, targetTimestep, debugMode)
- {
- windowWidth = windowCreateInfo.WindowWidth;
- windowHeight = windowCreateInfo.WindowHeight;
+ public TestGame(WindowCreateInfo windowCreateInfo, PresentMode presentMode, int targetTimestep = 60, bool debugMode = false) : base(windowCreateInfo, presentMode, targetTimestep, debugMode)
+ {
+ windowWidth = windowCreateInfo.WindowWidth;
+ windowHeight = windowCreateInfo.WindowHeight;
- var vertexShaderModule = new ShaderModule(GraphicsDevice, Path.Combine(Environment.CurrentDirectory, "Content", "sprite.vert.spv"));
- var fragmentShaderModule = new ShaderModule(GraphicsDevice, Path.Combine(Environment.CurrentDirectory, "Content", "sprite.frag.spv"));
+ var vertexShaderModule = new ShaderModule(GraphicsDevice, Path.Combine(Environment.CurrentDirectory, "Content", "sprite.vert.spv"));
+ var fragmentShaderModule = new ShaderModule(GraphicsDevice, Path.Combine(Environment.CurrentDirectory, "Content", "sprite.frag.spv"));
- ColorTargetDescription colorTargetDescription = new ColorTargetDescription
- {
- Format = TextureFormat.R8G8B8A8,
- MultisampleCount = SampleCount.One,
- LoadOp = LoadOp.Clear,
- StoreOp = StoreOp.Store
- };
+ mainColorTarget = RenderTarget.CreateBackedRenderTarget(
+ GraphicsDevice,
+ windowWidth,
+ windowHeight,
+ TextureFormat.R8G8B8A8,
+ false
+ );
- mainRenderPass = new RenderPass(GraphicsDevice, colorTargetDescription);
+ /* Pipeline */
- mainColorTarget = RenderTarget.CreateBackedRenderTarget(
- GraphicsDevice,
- windowWidth,
- windowHeight,
- TextureFormat.R8G8B8A8,
- false
- );
+ ColorTargetBlendState[] colorTargetBlendStates = new ColorTargetBlendState[1]
+ {
+ ColorTargetBlendState.None
+ };
- mainFramebuffer = new Framebuffer(
- GraphicsDevice,
- windowWidth,
- windowHeight,
- mainRenderPass,
- null,
- mainColorTarget
- );
+ ColorBlendState colorBlendState = new ColorBlendState
+ {
+ LogicOpEnable = false,
+ LogicOp = LogicOp.NoOp,
+ BlendConstants = new BlendConstants(),
+ ColorTargetBlendStates = colorTargetBlendStates
+ };
- mainRenderArea = new Rect
- {
- X = 0,
- Y = 0,
- W = (int) windowWidth,
- H = (int) windowHeight
- };
+ DepthStencilState depthStencilState = DepthStencilState.Disable;
- /* Pipeline */
+ ShaderStageState vertexShaderState = new ShaderStageState
+ {
+ ShaderModule = vertexShaderModule,
+ EntryPointName = "main",
+ UniformBufferSize = (uint)Marshal.SizeOf()
+ };
- ColorTargetBlendState[] colorTargetBlendStates = new ColorTargetBlendState[1]
- {
- ColorTargetBlendState.None
- };
+ ShaderStageState fragmentShaderState = new ShaderStageState
+ {
+ ShaderModule = fragmentShaderModule,
+ EntryPointName = "main",
+ UniformBufferSize = 0
+ };
- ColorBlendState colorBlendState = new ColorBlendState
- {
- LogicOpEnable = false,
- LogicOp = LogicOp.NoOp,
- BlendConstants = new BlendConstants(),
- ColorTargetBlendStates = colorTargetBlendStates
- };
+ MultisampleState multisampleState = MultisampleState.None;
- DepthStencilState depthStencilState = DepthStencilState.Disable;
+ GraphicsPipelineLayoutInfo pipelineLayoutInfo = new GraphicsPipelineLayoutInfo
+ {
+ VertexSamplerBindingCount = 0,
+ FragmentSamplerBindingCount = 1
+ };
- ShaderStageState vertexShaderState = new ShaderStageState
- {
- ShaderModule = vertexShaderModule,
- EntryPointName = "main",
- UniformBufferSize = (uint) Marshal.SizeOf()
- };
+ RasterizerState rasterizerState = RasterizerState.CCW_CullNone;
- ShaderStageState fragmentShaderState = new ShaderStageState
- {
- ShaderModule = fragmentShaderModule,
- EntryPointName = "main",
- UniformBufferSize = 0
- };
+ var vertexBindings = new VertexBinding[1]
+ {
+ new VertexBinding
+ {
+ Binding = 0,
+ InputRate = VertexInputRate.Vertex,
+ Stride = (uint) Marshal.SizeOf()
+ }
+ };
- MultisampleState multisampleState = MultisampleState.None;
+ var vertexAttributes = new VertexAttribute[3]
+ {
+ new VertexAttribute
+ {
+ Binding = 0,
+ Location = 0,
+ Format = VertexElementFormat.Vector3,
+ Offset = 0
+ },
+ new VertexAttribute
+ {
+ Binding = 0,
+ Location = 1,
+ Format = VertexElementFormat.Vector2,
+ Offset = (uint) Marshal.OffsetOf("texcoord")
+ },
+ new VertexAttribute
+ {
+ Binding = 0,
+ Location = 2,
+ Format = VertexElementFormat.Vector4,
+ Offset = (uint) Marshal.OffsetOf("color")
+ }
+ };
- GraphicsPipelineLayoutInfo pipelineLayoutInfo = new GraphicsPipelineLayoutInfo
- {
- VertexSamplerBindingCount = 0,
- FragmentSamplerBindingCount = 1
- };
+ VertexInputState vertexInputState = new VertexInputState
+ {
+ VertexBindings = vertexBindings,
+ VertexAttributes = vertexAttributes
+ };
- RasterizerState rasterizerState = RasterizerState.CCW_CullNone;
+ var viewports = new Viewport[1]
+ {
+ new Viewport
+ {
+ X = 0,
+ Y = 0,
+ W = windowWidth,
+ H = windowHeight,
+ MinDepth = 0,
+ MaxDepth = 1
+ }
+ };
- var vertexBindings = new VertexBinding[1]
- {
- new VertexBinding
- {
- Binding = 0,
- InputRate = VertexInputRate.Vertex,
- Stride = (uint) Marshal.SizeOf()
- }
- };
+ var scissors = new Rect[1]
+ {
+ new Rect
+ {
+ X = 0,
+ Y = 0,
+ W = (int) windowWidth,
+ H = (int) windowHeight
+ }
+ };
- var vertexAttributes = new VertexAttribute[3]
- {
- new VertexAttribute
- {
- Binding = 0,
- Location = 0,
- Format = VertexElementFormat.Vector3,
- Offset = 0
- },
- new VertexAttribute
- {
- Binding = 0,
- Location = 1,
- Format = VertexElementFormat.Vector2,
- Offset = (uint) Marshal.OffsetOf("texcoord")
- },
- new VertexAttribute
- {
- Binding = 0,
- Location = 2,
- Format = VertexElementFormat.Vector4,
- Offset = (uint) Marshal.OffsetOf("color")
- }
- };
+ ViewportState viewportState = new ViewportState
+ {
+ Viewports = viewports,
+ Scissors = scissors
+ };
- VertexInputState vertexInputState = new VertexInputState
- {
- VertexBindings = vertexBindings,
- VertexAttributes = vertexAttributes
- };
+ var colorAttachmentDescriptions = new ColorAttachmentDescription[1]
+ {
+ new ColorAttachmentDescription
+ {
+ format = TextureFormat.R8G8B8A8,
+ sampleCount = SampleCount.One
+ }
+ };
- var viewports = new Viewport[1]
- {
- new Viewport
- {
- X = 0,
- Y = 0,
- W = windowWidth,
- H = windowHeight,
- MinDepth = 0,
- MaxDepth = 1
- }
- };
+ GraphicsPipelineAttachmentInfo graphicsPipelineAttachmentInfo = new GraphicsPipelineAttachmentInfo
+ {
+ colorAttachmentDescriptions = colorAttachmentDescriptions,
+ colorAttachmentCount = 1,
+ hasDepthStencilAttachment = false,
+ depthStencilFormat = 0
+ };
- var scissors = new Rect[1]
- {
- new Rect
- {
- X = 0,
- Y = 0,
- W = (int) windowWidth,
- H = (int) windowHeight
- }
- };
+ var graphicsPipelineCreateInfo = new GraphicsPipelineCreateInfo
+ {
+ ColorBlendState = colorBlendState,
+ DepthStencilState = depthStencilState,
+ VertexShaderState = vertexShaderState,
+ FragmentShaderState = fragmentShaderState,
+ MultisampleState = multisampleState,
+ PipelineLayoutInfo = pipelineLayoutInfo,
+ RasterizerState = rasterizerState,
+ PrimitiveType = PrimitiveType.TriangleList,
+ VertexInputState = vertexInputState,
+ ViewportState = viewportState,
+ AttachmentInfo = graphicsPipelineAttachmentInfo
+ };
- ViewportState viewportState = new ViewportState
- {
- Viewports = viewports,
- Scissors = scissors
- };
+ spritePipeline = new GraphicsPipeline(GraphicsDevice, graphicsPipelineCreateInfo);
- var graphicsPipelineCreateInfo = new GraphicsPipelineCreateInfo
- {
- ColorBlendState = colorBlendState,
- DepthStencilState = depthStencilState,
- VertexShaderState = vertexShaderState,
- FragmentShaderState = fragmentShaderState,
- MultisampleState = multisampleState,
- PipelineLayoutInfo = pipelineLayoutInfo,
- RasterizerState = rasterizerState,
- PrimitiveType = PrimitiveType.TriangleList,
- VertexInputState = vertexInputState,
- ViewportState = viewportState,
- RenderPass = mainRenderPass
- };
+ spriteBatch = new SpriteBatch(GraphicsDevice);
- spritePipeline = new GraphicsPipeline(GraphicsDevice, graphicsPipelineCreateInfo);
+ whitePixel = Texture.CreateTexture2D(GraphicsDevice, 1, 1, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
- spriteBatch = new SpriteBatch(GraphicsDevice);
+ var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
+ commandBuffer.SetTextureData(whitePixel, new Color[] { Color.White });
+ GraphicsDevice.Submit(commandBuffer);
- whitePixel = Texture.CreateTexture2D(GraphicsDevice, 1, 1, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
+ sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointWrap);
+ }
- var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
- commandBuffer.SetTextureData(whitePixel, new Color[] { Color.White });
- GraphicsDevice.Submit(commandBuffer);
+ protected override void Update(TimeSpan dt)
+ {
+ for (var i = 0; i < SPRITECOUNT; i += 1)
+ {
+ positions[i].X = (float)(random.NextDouble() * windowWidth) - 64;
+ positions[i].Y = (float)(random.NextDouble() * windowHeight) - 64;
+ }
+ }
- sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointWrap);
- }
+ protected override void Draw(TimeSpan dt, double alpha)
+ {
+ var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
- protected override void Update(TimeSpan dt)
- {
- for (var i = 0; i < SPRITECOUNT; i += 1)
- {
- positions[i].X = (float) (random.NextDouble() * windowWidth) - 64;
- positions[i].Y = (float) (random.NextDouble() * windowHeight) - 64;
- }
- }
+ var viewProjection = Matrix4x4.CreateLookAt(new Vector3(windowWidth / 2, windowHeight / 2, 1), new Vector3(windowWidth / 2, windowHeight / 2, 0), Vector3.Up) * Matrix4x4.CreateOrthographic(windowWidth, windowHeight, 0.1f, 1000);
+ spriteBatch.Start(whitePixel, sampler);
- protected override void Draw(TimeSpan dt, double alpha)
- {
- var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
+ for (var i = 0; i < SPRITECOUNT; i += 1)
+ {
+ var transform = Matrix4x4.CreateTranslation(positions[i]);
+ var color = new Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 255f);
+ spriteBatch.Add(new Sprite(new Rect { X = 0, Y = 0, W = 0, H = 0 }, 128, 128), transform, color);
+ }
- var viewProjection = Matrix4x4.CreateLookAt(new Vector3(windowWidth / 2, windowHeight / 2, 1), new Vector3(windowWidth / 2, windowHeight / 2, 0), Vector3.Up) * Matrix4x4.CreateOrthographic(windowWidth, windowHeight, 0.1f, 1000);
- spriteBatch.Start(whitePixel, sampler);
+ var colorAttachmentInfo = new ColorAttachmentInfo
+ {
+ renderTarget = mainColorTarget,
+ clearColor = Color.Black,
+ loadOp = LoadOp.Clear,
+ storeOp = StoreOp.DontCare
+ };
- for (var i = 0; i < SPRITECOUNT; i += 1)
- {
- var transform = Matrix4x4.CreateTranslation(positions[i]);
- var color = new Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 255f);
- spriteBatch.Add(new Sprite(new Rect { X = 0, Y = 0, W = 0, H = 0 }, 128, 128), transform, color);
- }
+ spriteBatch.Flush(commandBuffer, colorAttachmentInfo, spritePipeline, new CameraUniforms { viewProjectionMatrix = viewProjection });
- spriteBatch.Flush(commandBuffer, mainRenderPass, mainFramebuffer, mainRenderArea, spritePipeline, new CameraUniforms { viewProjectionMatrix = viewProjection });
+ commandBuffer.QueuePresent(mainColorTarget.TextureSlice, Filter.Nearest, Window);
+ GraphicsDevice.Submit(commandBuffer);
+ }
- commandBuffer.QueuePresent(mainColorTarget.TextureSlice, Filter.Nearest, Window);
- GraphicsDevice.Submit(commandBuffer);
- }
- }
+ protected override void OnDestroy()
+ {
+
+ }
+ }
}