From 7a98e98fc38218eccde9b7da7d6567ecdbed36e4 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Sat, 16 Jan 2021 16:12:20 -0800 Subject: [PATCH] backed color target convenience method --- src/ColorTarget.cs | 28 ++++++++++++++++++++++++++++ src/DepthStencilTarget.cs | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ColorTarget.cs b/src/ColorTarget.cs index b93d96c..25a86f2 100644 --- a/src/ColorTarget.cs +++ b/src/ColorTarget.cs @@ -13,6 +13,34 @@ namespace Campari protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyColorTarget; + public static ColorTarget CreateBackedColorTarget2D( + GraphicsDevice device, + uint width, + uint height, + Refresh.ColorFormat format, + bool canBeSampled, + Refresh.SampleCount sampleCount = Refresh.SampleCount.One, + uint levelCount = 1 + ) + { + var flags = Refresh.TextureUsageFlags.ColorTargetBit; + if (canBeSampled) { flags |= Refresh.TextureUsageFlags.SamplerBit; } + + var texture = Texture.CreateTexture2D( + device, + width, + height, + format, + flags, + sampleCount, + levelCount + ); + + var textureSlice = new TextureSlice(texture); + + return new ColorTarget(device, sampleCount, ref textureSlice); + } + public ColorTarget(GraphicsDevice device, Refresh.SampleCount sampleCount, ref TextureSlice textureSlice) : base(device) { var refreshTextureSlice = textureSlice.ToRefreshTextureSlice(); diff --git a/src/DepthStencilTarget.cs b/src/DepthStencilTarget.cs index d8e90ed..edfc41c 100644 --- a/src/DepthStencilTarget.cs +++ b/src/DepthStencilTarget.cs @@ -11,7 +11,12 @@ namespace Campari protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyDepthStencilTarget; - public DepthStencilTarget(GraphicsDevice device, uint width, uint height, Refresh.DepthFormat depthFormat) : base(device) + public DepthStencilTarget( + GraphicsDevice device, + uint width, + uint height, + Refresh.DepthFormat depthFormat + ) : base(device) { Handle = Refresh.Refresh_CreateDepthStencilTarget(device.Handle, width, height, depthFormat); Width = width;