From 7f6236cb492bece7584416948186cebfcd9f422a Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 26 Jan 2021 19:10:09 -0800 Subject: [PATCH] update render target and texture format API --- lib/RefreshCS | 2 +- src/Graphics/RefreshEnums.cs | 19 +++++------ src/Graphics/RefreshStructs.cs | 4 +-- src/Graphics/Resources/DepthStencilTarget.cs | 32 ------------------- src/Graphics/Resources/Framebuffer.cs | 4 +-- .../{ColorTarget.cs => RenderTarget.cs} | 22 ++++++------- src/Graphics/Resources/Texture.cs | 10 +++--- src/Graphics/State/TextureCreateInfo.cs | 4 +-- src/Graphics/TextureSlice.cs | 8 ++--- 9 files changed, 34 insertions(+), 71 deletions(-) delete mode 100644 src/Graphics/Resources/DepthStencilTarget.cs rename src/Graphics/Resources/{ColorTarget.cs => RenderTarget.cs} (57%) diff --git a/lib/RefreshCS b/lib/RefreshCS index 369ced4..f5beb97 160000 --- a/lib/RefreshCS +++ b/lib/RefreshCS @@ -1 +1 @@ -Subproject commit 369ced4f80f0e7de22fa806b547831154a23efad +Subproject commit f5beb976bbe9c5775bef66cf20d264e918edffcd diff --git a/src/Graphics/RefreshEnums.cs b/src/Graphics/RefreshEnums.cs index 8f6a2b5..85c2865 100644 --- a/src/Graphics/RefreshEnums.cs +++ b/src/Graphics/RefreshEnums.cs @@ -51,7 +51,7 @@ namespace MoonWorks.Graphics ThirtyTwo } - public enum ColorFormat + public enum TextureFormat { R8G8B8A8, R5G6B5, @@ -71,22 +71,19 @@ namespace MoonWorks.Graphics R32G32B32A32_SFLOAT, R16_SFLOAT, R16G16_SFLOAT, - R16G16B16A16_SFLOAT - } - - public enum DepthFormat - { - Depth16, - Depth32, - Depth16Stencil8, - Depth32Stencil8 + R16G16B16A16_SFLOAT, + D16, + D32, + D16S8, + D32S8 } [Flags] public enum TextureUsageFlags : uint { Sampler = 1, - ColorTarget = 2 + ColorTarget = 2, + DepthStencilTarget = 4 } public enum SampleCount diff --git a/src/Graphics/RefreshStructs.cs b/src/Graphics/RefreshStructs.cs index a42feb2..d65d2ad 100644 --- a/src/Graphics/RefreshStructs.cs +++ b/src/Graphics/RefreshStructs.cs @@ -84,7 +84,7 @@ namespace MoonWorks.Graphics [StructLayout(LayoutKind.Sequential)] public struct ColorTargetDescription { - public ColorFormat format; + public TextureFormat format; public SampleCount multisampleCount; public LoadOp loadOp; public StoreOp storeOp; @@ -93,7 +93,7 @@ namespace MoonWorks.Graphics [StructLayout(LayoutKind.Sequential)] public struct DepthStencilTargetDescription { - public DepthFormat depthFormat; + public TextureFormat depthFormat; public LoadOp loadOp; public StoreOp storeOp; public LoadOp stencilLoadOp; diff --git a/src/Graphics/Resources/DepthStencilTarget.cs b/src/Graphics/Resources/DepthStencilTarget.cs deleted file mode 100644 index 5d093e0..0000000 --- a/src/Graphics/Resources/DepthStencilTarget.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using RefreshCS; - -namespace MoonWorks.Graphics -{ - public class DepthStencilTarget : GraphicsResource - { - public uint Width { get; } - public uint Height { get; } - public DepthFormat Format { get; } - - protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyDepthStencilTarget; - - public DepthStencilTarget( - GraphicsDevice device, - uint width, - uint height, - DepthFormat depthFormat - ) : base(device) - { - Handle = Refresh.Refresh_CreateDepthStencilTarget( - device.Handle, - width, - height, - (Refresh.DepthFormat) depthFormat - ); - Width = width; - Height = height; - Format = depthFormat; - } - } -} diff --git a/src/Graphics/Resources/Framebuffer.cs b/src/Graphics/Resources/Framebuffer.cs index 71f09fd..3498080 100644 --- a/src/Graphics/Resources/Framebuffer.cs +++ b/src/Graphics/Resources/Framebuffer.cs @@ -12,8 +12,8 @@ namespace MoonWorks.Graphics uint width, uint height, RenderPass renderPass, - DepthStencilTarget depthStencilTarget, /* can be NULL */ - params ColorTarget[] colorTargets + RenderTarget depthStencilTarget, /* can be NULL */ + params RenderTarget[] colorTargets ) : base(device) { IntPtr[] colorTargetHandles = new IntPtr[colorTargets.Length]; diff --git a/src/Graphics/Resources/ColorTarget.cs b/src/Graphics/Resources/RenderTarget.cs similarity index 57% rename from src/Graphics/Resources/ColorTarget.cs rename to src/Graphics/Resources/RenderTarget.cs index 4ac5080..405a7c2 100644 --- a/src/Graphics/Resources/ColorTarget.cs +++ b/src/Graphics/Resources/RenderTarget.cs @@ -3,18 +3,18 @@ using RefreshCS; namespace MoonWorks.Graphics { - public class ColorTarget : GraphicsResource + public class RenderTarget : GraphicsResource { public TextureSlice TextureSlice { get; } - public ColorFormat Format => TextureSlice.Texture.Format; + public TextureFormat Format => TextureSlice.Texture.Format; - protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyColorTarget; + protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyRenderTarget; - public static ColorTarget CreateBackedColorTarget2D( + public static RenderTarget CreateBackedColorTarget2D( GraphicsDevice device, uint width, uint height, - ColorFormat format, + TextureFormat format, bool canBeSampled, SampleCount sampleCount = SampleCount.One, uint levelCount = 1 @@ -33,17 +33,15 @@ namespace MoonWorks.Graphics levelCount ); - var textureSlice = new TextureSlice(texture); - - return new ColorTarget(device, sampleCount, ref textureSlice); + return new RenderTarget(device, new TextureSlice(texture), sampleCount); } - public ColorTarget(GraphicsDevice device, SampleCount sampleCount, ref TextureSlice textureSlice) : base(device) + public RenderTarget(GraphicsDevice device, in TextureSlice textureSlice, SampleCount sampleCount = SampleCount.One) : base(device) { - Handle = Refresh.Refresh_CreateColorTarget( + Handle = Refresh.Refresh_CreateRenderTarget( device.Handle, - (Refresh.SampleCount) sampleCount, - textureSlice.ToRefreshTextureSlice() + textureSlice.ToRefreshTextureSlice(), + (Refresh.SampleCount) sampleCount ); TextureSlice = textureSlice; } diff --git a/src/Graphics/Resources/Texture.cs b/src/Graphics/Resources/Texture.cs index acc0ac2..e1dac28 100644 --- a/src/Graphics/Resources/Texture.cs +++ b/src/Graphics/Resources/Texture.cs @@ -9,7 +9,7 @@ namespace MoonWorks.Graphics { public uint Width { get; } public uint Height { get; } - public ColorFormat Format { get; } + public TextureFormat Format { get; } protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture; @@ -26,7 +26,7 @@ namespace MoonWorks.Graphics textureCreateInfo.Width = (uint)width; textureCreateInfo.Height = (uint)height; textureCreateInfo.Depth = 1; - textureCreateInfo.Format = ColorFormat.R8G8B8A8; + textureCreateInfo.Format = TextureFormat.R8G8B8A8; textureCreateInfo.IsCube = false; textureCreateInfo.LevelCount = 1; textureCreateInfo.SampleCount = SampleCount.One; @@ -52,7 +52,7 @@ namespace MoonWorks.Graphics GraphicsDevice device, uint width, uint height, - ColorFormat format, + TextureFormat format, TextureUsageFlags usageFlags, SampleCount sampleCount = SampleCount.One, uint levelCount = 1 @@ -78,7 +78,7 @@ namespace MoonWorks.Graphics uint width, uint height, uint depth, - ColorFormat format, + TextureFormat format, TextureUsageFlags usageFlags, SampleCount sampleCount = SampleCount.One, uint levelCount = 1 @@ -102,7 +102,7 @@ namespace MoonWorks.Graphics public static Texture CreateTextureCube( GraphicsDevice device, uint size, - ColorFormat format, + TextureFormat format, TextureUsageFlags usageFlags, SampleCount sampleCount = SampleCount.One, uint levelCount = 1 diff --git a/src/Graphics/State/TextureCreateInfo.cs b/src/Graphics/State/TextureCreateInfo.cs index 3cf93da..fad07b5 100644 --- a/src/Graphics/State/TextureCreateInfo.cs +++ b/src/Graphics/State/TextureCreateInfo.cs @@ -10,7 +10,7 @@ namespace MoonWorks.Graphics public bool IsCube; public SampleCount SampleCount; public uint LevelCount; - public ColorFormat Format; + public TextureFormat Format; public TextureUsageFlags UsageFlags; public Refresh.TextureCreateInfo ToRefreshTextureCreateInfo() @@ -23,7 +23,7 @@ namespace MoonWorks.Graphics isCube = Conversions.BoolToByte(IsCube), sampleCount = (Refresh.SampleCount) SampleCount, levelCount = LevelCount, - format = (Refresh.ColorFormat) Format, + format = (Refresh.TextureFormat) Format, usageFlags = (Refresh.TextureUsageFlags) UsageFlags }; } diff --git a/src/Graphics/TextureSlice.cs b/src/Graphics/TextureSlice.cs index 843a26f..b3b2a1b 100644 --- a/src/Graphics/TextureSlice.cs +++ b/src/Graphics/TextureSlice.cs @@ -5,7 +5,7 @@ namespace MoonWorks.Graphics public struct TextureSlice { public Texture Texture { get; } - public Refresh.Rect Rectangle { get; } + public Rect Rectangle { get; } public uint Depth { get; } public uint Layer { get; } public uint Level { get; } @@ -13,7 +13,7 @@ namespace MoonWorks.Graphics public TextureSlice(Texture texture) { Texture = texture; - Rectangle = new Refresh.Rect + Rectangle = new Rect { x = 0, y = 0, @@ -25,7 +25,7 @@ namespace MoonWorks.Graphics Level = 0; } - public TextureSlice(Texture texture, Refresh.Rect rectangle, uint depth = 0, uint layer = 0, uint level = 0) + public TextureSlice(Texture texture, Rect rectangle, uint depth = 0, uint layer = 0, uint level = 0) { Texture = texture; Rectangle = rectangle; @@ -39,7 +39,7 @@ namespace MoonWorks.Graphics Refresh.TextureSlice textureSlice = new Refresh.TextureSlice { texture = Texture.Handle, - rectangle = Rectangle, + rectangle = Rectangle.ToRefresh(), depth = Depth, layer = Layer, level = Level