Skip to content

Commit

Permalink
Change masking-based scissor to use floats
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Sep 27, 2024
1 parent 5533d02 commit 5430a44
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 50 deletions.
9 changes: 5 additions & 4 deletions osu.Framework/Graphics/BufferedDrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ protected ValueInvokeOnDisposal<IFrameBuffer> BindFrameBuffer(IFrameBuffer frame
// Disable masking for generating the frame buffer since masking will be re-applied
// when actually drawing later on anyways. This allows more information to be captured
// in the frame buffer and helps with cached buffers being re-used.
RectangleI screenSpaceMaskingRect = new RectangleI((int)Math.Floor(screenSpaceDrawRectangle.X), (int)Math.Floor(screenSpaceDrawRectangle.Y), (int)frameBufferSize.X + 1,
(int)frameBufferSize.Y + 1);
RectangleF screenSpaceMaskingRect = new RectangleF(
MathF.Floor(screenSpaceDrawRectangle.X),
MathF.Floor(screenSpaceDrawRectangle.Y),
MathF.Ceiling(frameBufferSize.X),
MathF.Ceiling(frameBufferSize.Y));

renderer.PushMaskingInfo(new MaskingInfo
{
Expand All @@ -174,14 +177,12 @@ protected ValueInvokeOnDisposal<IFrameBuffer> BindFrameBuffer(IFrameBuffer frame
// Match viewport to FrameBuffer such that we don't draw unnecessary pixels.
renderer.PushViewport(new RectangleI(0, 0, (int)frameBufferSize.X, (int)frameBufferSize.Y));
renderer.PushScissor(new RectangleI(0, 0, (int)frameBufferSize.X, (int)frameBufferSize.Y));
renderer.PushScissorOffset(screenSpaceMaskingRect.Location);

return new ValueInvokeOnDisposal<(BufferedDrawNode node, IRenderer renderer)>((this, renderer), static tup => tup.node.returnViewport(tup.renderer));
}

private void returnViewport(IRenderer renderer)
{
renderer.PopScissorOffset();
renderer.PopViewport();
renderer.PopScissor();
renderer.PopMaskingInfo();
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.AABB,
ScreenSpaceAABB = 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.AABB;
edgeEffectMaskingInfo.ScreenSpaceAABB = 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
16 changes: 0 additions & 16 deletions osu.Framework/Graphics/Rendering/IRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ public interface IRenderer
/// </summary>
RectangleI Scissor { get; }

/// <summary>
/// The current scissor offset.
/// </summary>
Vector2I ScissorOffset { get; }

/// <summary>
/// The current projection matrix.
/// </summary>
Expand Down Expand Up @@ -276,17 +271,6 @@ public interface IRenderer
/// </summary>
void PopScissor();

/// <summary>
/// Applies a new scissor offset to the scissor rectangle.
/// </summary>
/// <param name="offset">The scissor offset.</param>
void PushScissorOffset(Vector2I offset);

/// <summary>
/// Restores the last scissor offset.
/// </summary>
void PopScissorOffset();

/// <summary>
/// Applies a new projection matrix.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Rendering/MaskingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace osu.Framework.Graphics.Rendering
{
public struct MaskingInfo : IEquatable<MaskingInfo>
{
public RectangleI ScreenSpaceAABB;
public RectangleF ScreenSpaceAABB;
public RectangleF MaskingRect;

public Quad ConservativeScreenSpaceQuad;
Expand Down
28 changes: 1 addition & 27 deletions osu.Framework/Graphics/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ protected internal Storage? CacheStorage
private readonly Stack<RectangleI> scissorRectStack = new Stack<RectangleI>();
private readonly Stack<DepthInfo> depthStack = new Stack<DepthInfo>();
private readonly Stack<StencilInfo> stencilStack = new Stack<StencilInfo>();
private readonly Stack<Vector2I> scissorOffsetStack = new Stack<Vector2I>();
private readonly Stack<IFrameBuffer> frameBufferStack = new Stack<IFrameBuffer>();
private readonly Stack<IShader> shaderStack = new Stack<IShader>();
private readonly Stack<bool> scissorStateStack = new Stack<bool>();
Expand Down Expand Up @@ -235,7 +234,6 @@ protected internal virtual void BeginFrame(Vector2 windowSize)
depthStack.Clear();
stencilStack.Clear();
scissorStateStack.Clear();
scissorOffsetStack.Clear();
shaderStack.Clear();

quadBatches.Clear();
Expand All @@ -251,10 +249,9 @@ protected internal virtual void BeginFrame(Vector2 windowSize)
PushScissorState(true);
PushViewport(new RectangleI(0, 0, (int)windowSize.X, (int)windowSize.Y));
PushScissor(new RectangleI(0, 0, (int)windowSize.X, (int)windowSize.Y));
PushScissorOffset(Vector2I.Zero);
PushMaskingInfo(new MaskingInfo
{
ScreenSpaceAABB = new RectangleI(0, 0, (int)windowSize.X, (int)windowSize.Y),
ScreenSpaceAABB = 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 @@ -486,12 +483,6 @@ public void PushScissorState(bool enabled)
setScissorState(enabled);
}

public void PushScissorOffset(Vector2I offset)
{
scissorOffsetStack.Push(offset);
setScissorOffset(offset);
}

public void PopScissor()
{
Trace.Assert(scissorRectStack.Count > 1);
Expand All @@ -508,14 +499,6 @@ public void PopScissorState()
setScissorState(scissorStateStack.Peek());
}

public void PopScissorOffset()
{
Trace.Assert(scissorOffsetStack.Count > 1);

scissorOffsetStack.Pop();
setScissorOffset(scissorOffsetStack.Peek());
}

private void setScissor(RectangleI scissor)
{
if (scissor.Width < 0)
Expand Down Expand Up @@ -556,15 +539,6 @@ private void setScissorState(bool enabled)
ScissorState = enabled;
}

private void setScissorOffset(Vector2I offset)
{
if (ScissorOffset == offset)
return;

FlushCurrentBatch(FlushBatchSource.SetScissor);
ScissorOffset = offset;
}

/// <summary>
/// Updates the graphics device with a new scissor rectangle.
/// </summary>
Expand Down

0 comments on commit 5430a44

Please sign in to comment.