Skip to content

Commit

Permalink
Rename ScreenSpaceAABB -> ScreenSpaceMaskingRect, add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Sep 27, 2024
1 parent 1e37545 commit de409a3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Audio/WaveformGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected override void Draw(IRenderer renderer)
// We're dealing with a _large_ number of points, so we need to optimise the quadToDraw * drawInfo.Matrix multiplications below
// for points that are going to be masked out anyway. This allows for higher resolution graphs at larger scales with virtually no performance loss.
// Since the points are generated in the local coordinate space, we need to convert the screen space masking quad coordinates into the local coordinate space
RectangleF localMaskingRectangle = (Quad.FromRectangle(renderer.CurrentMaskingInfo.ScreenSpaceAABB) * DrawInfo.MatrixInverse).AABBFloat;
RectangleF localMaskingRectangle = (Quad.FromRectangle(renderer.CurrentMaskingInfo.ScreenSpaceMaskingRect) * DrawInfo.MatrixInverse).AABBFloat;

float separation = drawSize.X / (points.Count - 1);

Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/BufferedDrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected ValueInvokeOnDisposal<IFrameBuffer> BindFrameBuffer(IFrameBuffer frame
{
renderer.PushMaskingInfo(new MaskingInfo
{
ScreenSpaceAABB = screenSpaceDrawRectangle,
ScreenSpaceMaskingRect = screenSpaceDrawRectangle,
MaskingRect = screenSpaceDrawRectangle,
ToMaskingSpace = Matrix3.Identity,
ToScissorSpace = Matrix3.Identity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public override void ApplyState()
? null
: new MaskingInfo
{
ScreenSpaceAABB = Source.ScreenSpaceDrawQuad.AABBFloat,
ScreenSpaceMaskingRect = Source.ScreenSpaceDrawQuad.AABBFloat,
MaskingRect = Source.DrawRectangle.Normalize(),
ConservativeScreenSpaceQuad = Quad.FromRectangle(shrunkDrawRectangle) * DrawInfo.Matrix,
ToMaskingSpace = DrawInfo.MatrixInverse,
Expand Down Expand Up @@ -127,7 +127,7 @@ private void drawEdgeEffect(IRenderer renderer)

MaskingInfo edgeEffectMaskingInfo = maskingInfo.Value;
edgeEffectMaskingInfo.MaskingRect = effectRect;
edgeEffectMaskingInfo.ScreenSpaceAABB = screenSpaceMaskingQuad.Value.AABBFloat;
edgeEffectMaskingInfo.ScreenSpaceMaskingRect = screenSpaceMaskingQuad.Value.AABBFloat;
edgeEffectMaskingInfo.CornerRadius = maskingInfo.Value.CornerRadius + edgeEffect.Radius + edgeEffect.Roundness;
edgeEffectMaskingInfo.BorderThickness = 0;
// HACK HACK HACK. We abuse blend range to give us the linear alpha gradient of
Expand Down
22 changes: 15 additions & 7 deletions osu.Framework/Graphics/Rendering/MaskingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,28 @@ namespace osu.Framework.Graphics.Rendering
{
public struct MaskingInfo : IEquatable<MaskingInfo>
{
public RectangleF ScreenSpaceAABB;
/// <summary>
/// The masking rectangle in coordinates relative to the masking space.
/// </summary>
public RectangleF MaskingRect;

public Quad ConservativeScreenSpaceQuad;
/// <summary>
/// The masking rectangle in screen-space coordinates.
/// </summary>
public RectangleF ScreenSpaceMaskingRect;

/// <summary>
/// This matrix transforms screen space coordinates to masking space (likely the parent
/// space of the container doing the masking).
/// It is used by a shader to determine which pixels to discard.
/// Transforms from screen-space coordinates to the masking space.
/// </summary>
public Matrix3 ToMaskingSpace;

/// <summary>
/// Transforms from screen-space coordinates to the scissor space.
/// </summary>
public Matrix3 ToScissorSpace;

public Quad ConservativeScreenSpaceQuad;

public float CornerRadius;
public float CornerExponent;

Expand All @@ -41,11 +49,11 @@ public struct MaskingInfo : IEquatable<MaskingInfo>
public readonly bool Equals(MaskingInfo other) => this == other;

public static bool operator ==(in MaskingInfo left, in MaskingInfo right) =>
left.ScreenSpaceAABB == right.ScreenSpaceAABB &&
left.MaskingRect == right.MaskingRect &&
left.ConservativeScreenSpaceQuad.Equals(right.ConservativeScreenSpaceQuad) &&
left.ScreenSpaceMaskingRect == right.ScreenSpaceMaskingRect &&
left.ToMaskingSpace == right.ToMaskingSpace &&
left.ToScissorSpace == right.ToScissorSpace &&
left.ConservativeScreenSpaceQuad.Equals(right.ConservativeScreenSpaceQuad) &&
left.CornerRadius == right.CornerRadius &&
left.CornerExponent == right.CornerExponent &&
left.BorderThickness == right.BorderThickness &&
Expand Down
12 changes: 6 additions & 6 deletions osu.Framework/Graphics/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected internal virtual void BeginFrame(Vector2 windowSize)
PushScissor(new RectangleI(0, 0, (int)windowSize.X, (int)windowSize.Y));
PushMaskingInfo(new MaskingInfo
{
ScreenSpaceAABB = new RectangleF(0, 0, windowSize.X, windowSize.Y),
ScreenSpaceMaskingRect = new RectangleF(0, 0, windowSize.X, windowSize.Y),
MaskingRect = new RectangleF(0, 0, windowSize.X, windowSize.Y),
ToMaskingSpace = Matrix3.Identity,
ToScissorSpace = Matrix3.Identity,
Expand Down Expand Up @@ -587,7 +587,7 @@ private void setProjectionMatrix(Matrix4 matrix)
public void PushMaskingInfo(MaskingInfo maskingInfo, bool overwritePreviousScissor = false)
{
if (!overwritePreviousScissor)
maskingInfo.ScreenSpaceAABB = RectangleF.Intersect(currentMaskingInfo.ScreenSpaceAABB, maskingInfo.ScreenSpaceAABB);
maskingInfo.ScreenSpaceMaskingRect = RectangleF.Intersect(currentMaskingInfo.ScreenSpaceMaskingRect, maskingInfo.ScreenSpaceMaskingRect);

maskingStack.Push(maskingInfo);
setMaskingInfo(maskingInfo);
Expand Down Expand Up @@ -930,10 +930,10 @@ public void DrawVertices(PrimitiveTopology topology, int vertexStart, int vertic
currentMaskingInfo.MaskingRect.Right,
currentMaskingInfo.MaskingRect.Bottom),
ScissorRect = new Vector4(
currentMaskingInfo.ScreenSpaceAABB.Left,
currentMaskingInfo.ScreenSpaceAABB.Top,
currentMaskingInfo.ScreenSpaceAABB.Right,
currentMaskingInfo.ScreenSpaceAABB.Bottom),
currentMaskingInfo.ScreenSpaceMaskingRect.Left,
currentMaskingInfo.ScreenSpaceMaskingRect.Top,
currentMaskingInfo.ScreenSpaceMaskingRect.Right,
currentMaskingInfo.ScreenSpaceMaskingRect.Bottom),
BorderThickness = currentMaskingInfo.BorderThickness / currentMaskingInfo.BlendRange,
BorderColour = currentMaskingInfo.BorderThickness > 0
? new Matrix4(
Expand Down

0 comments on commit de409a3

Please sign in to comment.