Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix masking broken with TexturedVertex3D #5987

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 23 additions & 23 deletions osu.Framework/Graphics/Lines/Path_DrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void Draw(IRenderer renderer)

texture.Bind();

updateVertexBuffer();
updateVertexBuffer(renderer);

pathShader.Unbind();

Expand All @@ -88,7 +88,7 @@ private Color4 colourAt(Vector2 localPos) => DrawColourInfo.Colour.TryExtractSin
? colour.SRGB
: DrawColourInfo.Colour.Interpolate(relativePosition(localPos)).SRGB;

private void addSegmentQuads(Line segment, Line segmentLeft, Line segmentRight, RectangleF texRect)
private void addSegmentQuads(IRenderer renderer, Line segment, Line segmentLeft, Line segmentRight, RectangleF texRect)
{
Debug.Assert(triangleBatch != null);

Expand All @@ -101,87 +101,87 @@ private void addSegmentQuads(Line segment, Line segmentLeft, Line segmentRight,

// Each of the quads (mentioned above) is rendered as 2 triangles:
// Outer quad, triangle 1
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentRight.EndPoint.X, segmentRight.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.EndPoint)
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentRight.StartPoint.X, segmentRight.StartPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.StartPoint)
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});

// Outer quad, triangle 2
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = secondMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = secondMiddleColour
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentRight.EndPoint.X, segmentRight.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.EndPoint)
});

// Inner quad, triangle 1
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = secondMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = secondMiddleColour
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentLeft.EndPoint.X, segmentLeft.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.EndPoint)
});

// Inner quad, triangle 2
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentLeft.EndPoint.X, segmentLeft.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.EndPoint)
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentLeft.StartPoint.X, segmentLeft.StartPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.StartPoint)
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
}

private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight, Line prevSegmentLeft, Line prevSegmentRight, RectangleF texRect)
private void addSegmentCaps(IRenderer renderer, float thetaDiff, Line segmentLeft, Line segmentRight, Line prevSegmentLeft, Line prevSegmentRight, RectangleF texRect)
{
Debug.Assert(triangleBatch != null);

Expand Down Expand Up @@ -210,15 +210,15 @@ private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight
for (int i = 1; i <= stepCount; i++)
{
// Center point
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(origin.X, origin.Y, 1),
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = originColour
});

// First outer point
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(current.X, current.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Expand All @@ -229,7 +229,7 @@ private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight
currentColour = colourAt(current);

// Second outer point
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(current.X, current.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Expand All @@ -238,7 +238,7 @@ private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight
}
}

private void updateVertexBuffer()
private void updateVertexBuffer(IRenderer renderer)
{
// Explanation of the terms "left" and "right":
// "Left" and "right" are used here in terms of a typical (Cartesian) coordinate system.
Expand Down Expand Up @@ -277,15 +277,15 @@ private void updateVertexBuffer()
Line currSegmentLeft = new Line(currSegment.StartPoint + ortho * radius, currSegment.EndPoint + ortho * radius);
Line currSegmentRight = new Line(currSegment.StartPoint - ortho * radius, currSegment.EndPoint - ortho * radius);

addSegmentQuads(currSegment, currSegmentLeft, currSegmentRight, texRect);
addSegmentQuads(renderer, currSegment, currSegmentLeft, currSegmentRight, texRect);

if (prevSegmentLeft is Line psLeft && prevSegmentRight is Line psRight)
{
Debug.Assert(i > 0);

// Connection/filler caps between segment quads
float thetaDiff = currSegment.Theta - segments[i - 1].Theta;
addSegmentCaps(thetaDiff, currSegmentLeft, currSegmentRight, psLeft, psRight, texRect);
addSegmentCaps(renderer, thetaDiff, currSegmentLeft, currSegmentRight, psLeft, psRight, texRect);
}

// Explanation of semi-circle caps:
Expand All @@ -300,7 +300,7 @@ private void updateVertexBuffer()
Line flippedLeft = new Line(currSegmentRight.EndPoint, currSegmentRight.StartPoint);
Line flippedRight = new Line(currSegmentLeft.EndPoint, currSegmentLeft.StartPoint);

addSegmentCaps(MathF.PI, currSegmentLeft, currSegmentRight, flippedLeft, flippedRight, texRect);
addSegmentCaps(renderer, MathF.PI, currSegmentLeft, currSegmentRight, flippedLeft, flippedRight, texRect);
}

if (i == segments.Count - 1)
Expand All @@ -309,7 +309,7 @@ private void updateVertexBuffer()
Line flippedLeft = new Line(currSegmentRight.EndPoint, currSegmentRight.StartPoint);
Line flippedRight = new Line(currSegmentLeft.EndPoint, currSegmentLeft.StartPoint);

addSegmentCaps(MathF.PI, flippedLeft, flippedRight, currSegmentLeft, currSegmentRight, texRect);
addSegmentCaps(renderer, MathF.PI, flippedLeft, flippedRight, currSegmentLeft, currSegmentRight, texRect);
}

prevSegmentLeft = currSegmentLeft;
Expand Down
12 changes: 12 additions & 0 deletions osu.Framework/Graphics/Rendering/Vertices/TexturedVertex3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public struct TexturedVertex3D : IEquatable<TexturedVertex3D>, IVertex
[VertexMember(1, VertexAttribPointerType.Int)]
private readonly int maskingIndex;

[Obsolete("Initialise this type with an IRenderer instead", true)]
public TexturedVertex3D()
{
this = default; // explicitly initialise all members to default values
}

public TexturedVertex3D(IRenderer renderer)
{
this = default; // explicitly initialise all members to default values
maskingIndex = renderer.CurrentMaskingIndex;
}

public readonly bool Equals(TexturedVertex3D other)
=> Position.Equals(other.Position)
&& TexturePosition.Equals(other.TexturePosition)
Expand Down