Skip to content

Commit

Permalink
Update renderer clear info to use PremultipliedColour
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Dec 14, 2024
1 parent 21f500d commit 5c9e39d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion osu.Framework/Graphics/BufferedDrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/OpenGL/GLRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions osu.Framework/Graphics/Rendering/ClearInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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
{
Expand All @@ -18,7 +18,7 @@ public readonly struct ClearInfo
/// <summary>
/// The colour to write to the frame buffer.
/// </summary>
public readonly Color4 Colour;
public readonly PremultipliedColour Colour;

/// <summary>
/// The depth to write to the frame buffer.
Expand All @@ -30,7 +30,7 @@ public readonly struct ClearInfo
/// </summary>
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;
Expand Down
3 changes: 2 additions & 1 deletion osu.Framework/Graphics/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void Begin()
/// <param name="clearInfo">The clearing parameters.</param>
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)
Expand Down

0 comments on commit 5c9e39d

Please sign in to comment.