mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 09:03:50 +09:00
Adjust drawnodes to use the new shared data structure
This commit is contained in:
@ -35,7 +35,6 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
|
|
||||||
public override bool IsPresent => true;
|
public override bool IsPresent => true;
|
||||||
|
|
||||||
private readonly TrailDrawNodeSharedData trailDrawNodeSharedData = new TrailDrawNodeSharedData();
|
|
||||||
private const int max_sprites = 2048;
|
private const int max_sprites = 2048;
|
||||||
|
|
||||||
private readonly TrailPart[] parts = new TrailPart[max_sprites];
|
private readonly TrailPart[] parts = new TrailPart[max_sprites];
|
||||||
@ -55,7 +54,6 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
tNode.Texture = texture;
|
tNode.Texture = texture;
|
||||||
tNode.Size = size;
|
tNode.Size = size;
|
||||||
tNode.Time = time;
|
tNode.Time = time;
|
||||||
tNode.Shared = trailDrawNodeSharedData;
|
|
||||||
|
|
||||||
for (int i = 0; i < parts.Length; ++i)
|
for (int i = 0; i < parts.Length; ++i)
|
||||||
if (parts[i].InvalidationID > tNode.Parts[i].InvalidationID)
|
if (parts[i].InvalidationID > tNode.Parts[i].InvalidationID)
|
||||||
@ -167,22 +165,18 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
public bool WasUpdated;
|
public bool WasUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TrailDrawNodeSharedData
|
|
||||||
{
|
|
||||||
public VertexBuffer<TexturedTrailVertex> VertexBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TrailDrawNode : DrawNode
|
private class TrailDrawNode : DrawNode
|
||||||
{
|
{
|
||||||
public Shader Shader;
|
public Shader Shader;
|
||||||
public Texture Texture;
|
public Texture Texture;
|
||||||
|
|
||||||
public float Time;
|
public float Time;
|
||||||
public TrailDrawNodeSharedData Shared;
|
|
||||||
|
|
||||||
public readonly TrailPart[] Parts = new TrailPart[max_sprites];
|
public readonly TrailPart[] Parts = new TrailPart[max_sprites];
|
||||||
public Vector2 Size;
|
public Vector2 Size;
|
||||||
|
|
||||||
|
private readonly VertexBuffer<TexturedTrailVertex> vertexBuffer = new QuadVertexBuffer<TexturedTrailVertex>(max_sprites, BufferUsageHint.DynamicDraw);
|
||||||
|
|
||||||
public TrailDrawNode()
|
public TrailDrawNode()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < max_sprites; i++)
|
for (int i = 0; i < max_sprites; i++)
|
||||||
@ -194,9 +188,6 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
|
|
||||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||||
{
|
{
|
||||||
if (Shared.VertexBuffer == null)
|
|
||||||
Shared.VertexBuffer = new QuadVertexBuffer<TexturedTrailVertex>(max_sprites, BufferUsageHint.DynamicDraw);
|
|
||||||
|
|
||||||
Shader.GetUniform<float>("g_FadeClock").UpdateValue(ref Time);
|
Shader.GetUniform<float>("g_FadeClock").UpdateValue(ref Time);
|
||||||
|
|
||||||
int updateStart = -1, updateEnd = 0;
|
int updateStart = -1, updateEnd = 0;
|
||||||
@ -218,7 +209,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
new Quad(pos.X - Size.X / 2, pos.Y - Size.Y / 2, Size.X, Size.Y),
|
new Quad(pos.X - Size.X / 2, pos.Y - Size.Y / 2, Size.X, Size.Y),
|
||||||
DrawColourInfo.Colour,
|
DrawColourInfo.Colour,
|
||||||
null,
|
null,
|
||||||
v => Shared.VertexBuffer.Vertices[end++] = new TexturedTrailVertex
|
v => vertexBuffer.Vertices[end++] = new TexturedTrailVertex
|
||||||
{
|
{
|
||||||
Position = v.Position,
|
Position = v.Position,
|
||||||
TexturePosition = v.TexturePosition,
|
TexturePosition = v.TexturePosition,
|
||||||
@ -230,24 +221,31 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
}
|
}
|
||||||
else if (updateStart != -1)
|
else if (updateStart != -1)
|
||||||
{
|
{
|
||||||
Shared.VertexBuffer.UpdateRange(updateStart * 4, updateEnd * 4);
|
vertexBuffer.UpdateRange(updateStart * 4, updateEnd * 4);
|
||||||
updateStart = -1;
|
updateStart = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update all remaining vertices that have been changed.
|
// Update all remaining vertices that have been changed.
|
||||||
if (updateStart != -1)
|
if (updateStart != -1)
|
||||||
Shared.VertexBuffer.UpdateRange(updateStart * 4, updateEnd * 4);
|
vertexBuffer.UpdateRange(updateStart * 4, updateEnd * 4);
|
||||||
|
|
||||||
base.Draw(vertexAction);
|
base.Draw(vertexAction);
|
||||||
|
|
||||||
Shader.Bind();
|
Shader.Bind();
|
||||||
|
|
||||||
Texture.TextureGL.Bind();
|
Texture.TextureGL.Bind();
|
||||||
Shared.VertexBuffer.Draw();
|
vertexBuffer.Draw();
|
||||||
|
|
||||||
Shader.Unbind();
|
Shader.Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
vertexBuffer.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
@ -180,8 +180,6 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
|
|
||||||
protected override DrawNode CreateDrawNode() => new TrianglesDrawNode();
|
protected override DrawNode CreateDrawNode() => new TrianglesDrawNode();
|
||||||
|
|
||||||
private readonly TrianglesDrawNodeSharedData sharedData = new TrianglesDrawNodeSharedData();
|
|
||||||
|
|
||||||
protected override void ApplyDrawNode(DrawNode node)
|
protected override void ApplyDrawNode(DrawNode node)
|
||||||
{
|
{
|
||||||
base.ApplyDrawNode(node);
|
base.ApplyDrawNode(node);
|
||||||
@ -191,27 +189,21 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
trianglesNode.Shader = shader;
|
trianglesNode.Shader = shader;
|
||||||
trianglesNode.Texture = texture;
|
trianglesNode.Texture = texture;
|
||||||
trianglesNode.Size = DrawSize;
|
trianglesNode.Size = DrawSize;
|
||||||
trianglesNode.Shared = sharedData;
|
|
||||||
|
|
||||||
trianglesNode.Parts.Clear();
|
trianglesNode.Parts.Clear();
|
||||||
trianglesNode.Parts.AddRange(parts);
|
trianglesNode.Parts.AddRange(parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TrianglesDrawNodeSharedData
|
|
||||||
{
|
|
||||||
public readonly LinearBatch<TexturedVertex2D> VertexBatch = new LinearBatch<TexturedVertex2D>(100 * 3, 10, PrimitiveType.Triangles);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TrianglesDrawNode : DrawNode
|
private class TrianglesDrawNode : DrawNode
|
||||||
{
|
{
|
||||||
public Shader Shader;
|
public Shader Shader;
|
||||||
public Texture Texture;
|
public Texture Texture;
|
||||||
|
|
||||||
public TrianglesDrawNodeSharedData Shared;
|
|
||||||
|
|
||||||
public readonly List<TriangleParticle> Parts = new List<TriangleParticle>();
|
public readonly List<TriangleParticle> Parts = new List<TriangleParticle>();
|
||||||
public Vector2 Size;
|
public Vector2 Size;
|
||||||
|
|
||||||
|
private readonly LinearBatch<TexturedVertex2D> vertexBatch = new LinearBatch<TexturedVertex2D>(100 * 3, 10, PrimitiveType.Triangles);
|
||||||
|
|
||||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||||
{
|
{
|
||||||
base.Draw(vertexAction);
|
base.Draw(vertexAction);
|
||||||
@ -239,12 +231,19 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
triangle,
|
triangle,
|
||||||
colourInfo,
|
colourInfo,
|
||||||
null,
|
null,
|
||||||
Shared.VertexBatch.AddAction,
|
vertexBatch.AddAction,
|
||||||
Vector2.Divide(localInflationAmount, size));
|
Vector2.Divide(localInflationAmount, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader.Unbind();
|
Shader.Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
vertexBatch.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected struct TriangleParticle : IComparable<TriangleParticle>
|
protected struct TriangleParticle : IComparable<TriangleParticle>
|
||||||
|
@ -131,8 +131,6 @@ namespace osu.Game.Screens.Menu
|
|||||||
|
|
||||||
protected override DrawNode CreateDrawNode() => new VisualisationDrawNode();
|
protected override DrawNode CreateDrawNode() => new VisualisationDrawNode();
|
||||||
|
|
||||||
private readonly VisualiserSharedData sharedData = new VisualiserSharedData();
|
|
||||||
|
|
||||||
protected override void ApplyDrawNode(DrawNode node)
|
protected override void ApplyDrawNode(DrawNode node)
|
||||||
{
|
{
|
||||||
base.ApplyDrawNode(node);
|
base.ApplyDrawNode(node);
|
||||||
@ -142,29 +140,23 @@ namespace osu.Game.Screens.Menu
|
|||||||
visNode.Shader = shader;
|
visNode.Shader = shader;
|
||||||
visNode.Texture = texture;
|
visNode.Texture = texture;
|
||||||
visNode.Size = DrawSize.X;
|
visNode.Size = DrawSize.X;
|
||||||
visNode.Shared = sharedData;
|
|
||||||
visNode.Colour = AccentColour;
|
visNode.Colour = AccentColour;
|
||||||
visNode.AudioData = frequencyAmplitudes;
|
visNode.AudioData = frequencyAmplitudes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class VisualiserSharedData
|
|
||||||
{
|
|
||||||
public readonly QuadBatch<TexturedVertex2D> VertexBatch = new QuadBatch<TexturedVertex2D>(100, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class VisualisationDrawNode : DrawNode
|
private class VisualisationDrawNode : DrawNode
|
||||||
{
|
{
|
||||||
public Shader Shader;
|
public Shader Shader;
|
||||||
public Texture Texture;
|
public Texture Texture;
|
||||||
|
|
||||||
public VisualiserSharedData Shared;
|
|
||||||
|
|
||||||
//Asuming the logo is a circle, we don't need a second dimension.
|
//Asuming the logo is a circle, we don't need a second dimension.
|
||||||
public float Size;
|
public float Size;
|
||||||
|
|
||||||
public Color4 Colour;
|
public Color4 Colour;
|
||||||
public float[] AudioData;
|
public float[] AudioData;
|
||||||
|
|
||||||
|
private readonly QuadBatch<TexturedVertex2D> vertexBatch = new QuadBatch<TexturedVertex2D>(100, 10);
|
||||||
|
|
||||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||||
{
|
{
|
||||||
base.Draw(vertexAction);
|
base.Draw(vertexAction);
|
||||||
@ -209,7 +201,7 @@ namespace osu.Game.Screens.Menu
|
|||||||
rectangle,
|
rectangle,
|
||||||
colourInfo,
|
colourInfo,
|
||||||
null,
|
null,
|
||||||
Shared.VertexBatch.AddAction,
|
vertexBatch.AddAction,
|
||||||
//barSize by itself will make it smooth more in the X axis than in the Y axis, this reverts that.
|
//barSize by itself will make it smooth more in the X axis than in the Y axis, this reverts that.
|
||||||
Vector2.Divide(inflation, barSize.Yx));
|
Vector2.Divide(inflation, barSize.Yx));
|
||||||
}
|
}
|
||||||
@ -218,6 +210,13 @@ namespace osu.Game.Screens.Menu
|
|||||||
|
|
||||||
Shader.Unbind();
|
Shader.Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
vertexBatch.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user