From 5c9e39d7a1ec29c16cd6d8e057ea51e39bd5c30c Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Fri, 13 Dec 2024 08:17:27 -0500 Subject: [PATCH] Update renderer clear info to use `PremultipliedColour` --- osu.Framework/Graphics/BufferedDrawNode.cs | 3 ++- osu.Framework/Graphics/OpenGL/GLRenderer.cs | 4 ++-- osu.Framework/Graphics/Rendering/ClearInfo.cs | 6 +++--- osu.Framework/Graphics/Rendering/Renderer.cs | 3 ++- .../Graphics/Veldrid/Pipelines/GraphicsPipeline.cs | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/osu.Framework/Graphics/BufferedDrawNode.cs b/osu.Framework/Graphics/BufferedDrawNode.cs index f250b96411..7de61d5c41 100644 --- a/osu.Framework/Graphics/BufferedDrawNode.cs +++ b/osu.Framework/Graphics/BufferedDrawNode.cs @@ -5,6 +5,7 @@ using System; using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Rendering; using osu.Framework.Statistics; @@ -99,7 +100,7 @@ protected sealed override void Draw(IRenderer renderer) // We need to draw children as if they were zero-based to the top-left of the texture. // We can do this by adding a translation component to our (orthogonal) projection matrix. renderer.PushOrtho(screenSpaceDrawRectangle); - renderer.Clear(new ClearInfo(backgroundColour)); + renderer.Clear(new ClearInfo(backgroundColour.ToPremultiplied())); DrawOther(Child, renderer); diff --git a/osu.Framework/Graphics/OpenGL/GLRenderer.cs b/osu.Framework/Graphics/OpenGL/GLRenderer.cs index 338cff27f3..a887e1198e 100644 --- a/osu.Framework/Graphics/OpenGL/GLRenderer.cs +++ b/osu.Framework/Graphics/OpenGL/GLRenderer.cs @@ -238,8 +238,8 @@ protected override void DeleteFrameBufferImplementation(IFrameBuffer frameBuffer protected override void ClearImplementation(ClearInfo clearInfo) { - if (clearInfo.Colour != CurrentClearInfo.Colour) - GL.ClearColor(clearInfo.Colour); + if (!clearInfo.Colour.Equals(CurrentClearInfo.Colour)) + GL.ClearColor(clearInfo.Colour.Premultiplied); if (clearInfo.Depth != CurrentClearInfo.Depth) { diff --git a/osu.Framework/Graphics/Rendering/ClearInfo.cs b/osu.Framework/Graphics/Rendering/ClearInfo.cs index c9f19ba327..c94f91ff7f 100644 --- a/osu.Framework/Graphics/Rendering/ClearInfo.cs +++ b/osu.Framework/Graphics/Rendering/ClearInfo.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osuTK.Graphics; +using osu.Framework.Graphics.Colour; namespace osu.Framework.Graphics.Rendering { @@ -18,7 +18,7 @@ public readonly struct ClearInfo /// /// The colour to write to the frame buffer. /// - public readonly Color4 Colour; + public readonly PremultipliedColour Colour; /// /// The depth to write to the frame buffer. @@ -30,7 +30,7 @@ public readonly struct ClearInfo /// public readonly int Stencil; - public ClearInfo(Color4 colour = default, double depth = 1f, int stencil = 0) + public ClearInfo(PremultipliedColour colour = default, double depth = 1f, int stencil = 0) { Colour = colour; Depth = depth; diff --git a/osu.Framework/Graphics/Rendering/Renderer.cs b/osu.Framework/Graphics/Rendering/Renderer.cs index 8759b6ae31..98ce4ee9ad 100644 --- a/osu.Framework/Graphics/Rendering/Renderer.cs +++ b/osu.Framework/Graphics/Rendering/Renderer.cs @@ -9,6 +9,7 @@ using System.Reflection; using System.Runtime.InteropServices; using osu.Framework.Development; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Rendering.Vertices; @@ -265,7 +266,7 @@ protected internal virtual void BeginFrame(Vector2 windowSize) PushDepthInfo(DepthInfo.Default); PushStencilInfo(StencilInfo.Default); - Clear(new ClearInfo(Color4.Black)); + Clear(new ClearInfo(Color4.Black.ToPremultiplied())); freeUnusedVertexBuffers(); vboInUse.Value = vertexBuffersInUse.Count; diff --git a/osu.Framework/Graphics/Veldrid/Pipelines/GraphicsPipeline.cs b/osu.Framework/Graphics/Veldrid/Pipelines/GraphicsPipeline.cs index 76ff428298..931613f404 100644 --- a/osu.Framework/Graphics/Veldrid/Pipelines/GraphicsPipeline.cs +++ b/osu.Framework/Graphics/Veldrid/Pipelines/GraphicsPipeline.cs @@ -63,7 +63,7 @@ public override void Begin() /// The clearing parameters. public void Clear(ClearInfo clearInfo) { - Commands.ClearColorTarget(0, clearInfo.Colour.ToRgbaFloat()); + Commands.ClearColorTarget(0, clearInfo.Colour.Premultiplied.ToRgbaFloat()); var framebuffer = currentFrameBuffer?.Framebuffer ?? Device.SwapchainFramebuffer; if (framebuffer.DepthTarget != null)