From 7328cbc13dc0e1f156689aeeae2fd5ae4be24084 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 25 Feb 2022 18:01:22 -0800 Subject: [PATCH] add some constructors to reduce boilerplate --- src/Graphics/RefreshStructs.cs | 46 +++++++++++++++++++ .../State/GraphicsPipelineLayoutInfo.cs | 9 ++++ src/Graphics/State/ViewportState.cs | 9 ++++ 3 files changed, 64 insertions(+) diff --git a/src/Graphics/RefreshStructs.cs b/src/Graphics/RefreshStructs.cs index f0597c3..8af0cc9 100644 --- a/src/Graphics/RefreshStructs.cs +++ b/src/Graphics/RefreshStructs.cs @@ -31,6 +31,22 @@ namespace MoonWorks.Graphics public int W; public int H; + public Rect(int x, int y, int w, int h) + { + X = x; + Y = y; + W = w; + H = h; + } + + public Rect(int w, int h) + { + X = 0; + Y = 0; + W = w; + H = h; + } + // FIXME: can we do an unsafe cast somehow? public Refresh.Rect ToRefresh() { @@ -53,6 +69,36 @@ namespace MoonWorks.Graphics public float H; public float MinDepth; public float MaxDepth; + + public Viewport(float w, float h) + { + X = 0; + Y = 0; + W = w; + H = h; + MinDepth = 0; + MaxDepth = 1; + } + + public Viewport(float x, float y, float w, float h) + { + X = x; + Y = y; + W = w; + H = h; + MinDepth = 0; + MaxDepth = 1; + } + + public Viewport(float x, float y, float w, float h, float minDepth, float maxDepth) + { + X = x; + Y = y; + W = w; + H = h; + MinDepth = minDepth; + MaxDepth = maxDepth; + } } [StructLayout(LayoutKind.Sequential)] diff --git a/src/Graphics/State/GraphicsPipelineLayoutInfo.cs b/src/Graphics/State/GraphicsPipelineLayoutInfo.cs index 40cd14c..4d8913d 100644 --- a/src/Graphics/State/GraphicsPipelineLayoutInfo.cs +++ b/src/Graphics/State/GraphicsPipelineLayoutInfo.cs @@ -7,5 +7,14 @@ { public uint VertexSamplerBindingCount; public uint FragmentSamplerBindingCount; + + public GraphicsPipelineLayoutInfo( + uint vertexSamplerBindingCount, + uint fragmentSamplerBindingCount + ) + { + VertexSamplerBindingCount = vertexSamplerBindingCount; + FragmentSamplerBindingCount = fragmentSamplerBindingCount; + } } } diff --git a/src/Graphics/State/ViewportState.cs b/src/Graphics/State/ViewportState.cs index 294b6ec..5f789ad 100644 --- a/src/Graphics/State/ViewportState.cs +++ b/src/Graphics/State/ViewportState.cs @@ -7,5 +7,14 @@ { public Viewport[] Viewports; public Rect[] Scissors; + + /// + /// A default single viewport with no scissor area. + /// + public ViewportState(int width, int height) + { + Viewports = new Viewport[] { new Viewport(width, height) }; + Scissors = new Rect[] { new Rect(width, height) }; + } } }