From 4eb2cb6b090468b80eb1be99d8fe01100d821027 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 8 Feb 2021 18:10:02 -0800 Subject: [PATCH] some state tweaks --- src/Graphics/RefreshEnums.cs | 3 +- src/Graphics/Resources/RenderTarget.cs | 62 +++++++-------------- src/Graphics/State/ColorTargetBlendState.cs | 6 ++ 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/src/Graphics/RefreshEnums.cs b/src/Graphics/RefreshEnums.cs index 85c2865..d2f79f4 100644 --- a/src/Graphics/RefreshEnums.cs +++ b/src/Graphics/RefreshEnums.cs @@ -253,7 +253,8 @@ namespace MoonWorks.Graphics RGA = R | G | A, GBA = G | B | A, - RGBA = R | G | B | A + RGBA = R | G | B | A, + None = 0 } public enum ShaderStageType diff --git a/src/Graphics/Resources/RenderTarget.cs b/src/Graphics/Resources/RenderTarget.cs index 4e04470..597fa7a 100644 --- a/src/Graphics/Resources/RenderTarget.cs +++ b/src/Graphics/Resources/RenderTarget.cs @@ -10,7 +10,7 @@ namespace MoonWorks.Graphics protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyRenderTarget; - public static RenderTarget CreateBackedColorTarget2D( + public static RenderTarget CreateBackedRenderTarget( GraphicsDevice device, uint width, uint height, @@ -18,10 +18,26 @@ namespace MoonWorks.Graphics bool canBeSampled, SampleCount sampleCount = SampleCount.One, uint levelCount = 1 - ) - { - var flags = TextureUsageFlags.ColorTarget; - if (canBeSampled) { flags |= TextureUsageFlags.Sampler; } + ) { + TextureUsageFlags flags = 0; + + if ( + format == TextureFormat.D16 || + format == TextureFormat.D32 || + format == TextureFormat.D16S8 || + format == TextureFormat.D32S8 + ) { + flags |= TextureUsageFlags.DepthStencilTarget; + } + else + { + flags |= TextureUsageFlags.ColorTarget; + } + + if (canBeSampled) + { + flags |= TextureUsageFlags.Sampler; + } var texture = Texture.CreateTexture2D( device, @@ -36,42 +52,6 @@ namespace MoonWorks.Graphics return new RenderTarget(device, new TextureSlice(texture), sampleCount); } - public static RenderTarget CreateDepthBuffer( - GraphicsDevice device, - uint width, - uint height - ) { - var flags = TextureUsageFlags.DepthStencilTarget; - - var texture = Texture.CreateTexture2D( - device, - width, - height, - TextureFormat.D32, - flags - ); - - return new RenderTarget(device, new TextureSlice(texture)); - } - - public static RenderTarget CreateDepthStencilBuffer( - GraphicsDevice device, - uint width, - uint height - ) { - var flags = TextureUsageFlags.DepthStencilTarget; - - var texture = Texture.CreateTexture2D( - device, - width, - height, - TextureFormat.D32S8, - flags - ); - - return new RenderTarget(device, new TextureSlice(texture)); - } - public RenderTarget(GraphicsDevice device, in TextureSlice textureSlice, SampleCount sampleCount = SampleCount.One) : base(device) { Handle = Refresh.Refresh_CreateRenderTarget( diff --git a/src/Graphics/State/ColorTargetBlendState.cs b/src/Graphics/State/ColorTargetBlendState.cs index f5c082e..b29545c 100644 --- a/src/Graphics/State/ColorTargetBlendState.cs +++ b/src/Graphics/State/ColorTargetBlendState.cs @@ -67,6 +67,12 @@ namespace MoonWorks.Graphics ColorWriteMask = ColorComponentFlags.RGBA }; + public static readonly ColorTargetBlendState Disable = new ColorTargetBlendState + { + BlendEnable = false, + ColorWriteMask = ColorComponentFlags.None + }; + public Refresh.ColorTargetBlendState ToRefreshColorTargetBlendState() { return new Refresh.ColorTargetBlendState