1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-29 17:47:26 +08:00
osu-lazer/osu.Game/Graphics/Sprites/LogoAnimation.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
4.6 KiB
C#
Raw Normal View History

2020-06-24 20:11:38 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
2023-03-17 19:37:05 +08:00
using System;
2023-02-25 00:21:37 +08:00
using System.Runtime.InteropServices;
2020-06-24 20:11:38 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
2022-07-29 21:33:34 +08:00
using osu.Framework.Graphics.Rendering;
2023-03-17 19:37:05 +08:00
using osu.Framework.Graphics.Rendering.Vertices;
2020-06-24 20:11:38 +08:00
using osu.Framework.Graphics.Shaders;
2023-02-25 00:21:37 +08:00
using osu.Framework.Graphics.Shaders.Types;
2020-06-24 20:11:38 +08:00
using osu.Framework.Graphics.Sprites;
2023-03-17 19:37:05 +08:00
using osuTK;
using osuTK.Graphics;
using osuTK.Graphics.ES30;
2020-06-24 20:11:38 +08:00
namespace osu.Game.Graphics.Sprites
{
2020-07-23 04:10:59 +08:00
public partial class LogoAnimation : Sprite
2020-06-24 20:11:38 +08:00
{
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load(ShaderManager shaders)
2020-06-24 20:11:38 +08:00
{
TextureShader = shaders.Load(@"LogoAnimation", @"LogoAnimation");
2020-06-24 20:11:38 +08:00
}
private float animationProgress;
public float AnimationProgress
{
get => animationProgress;
set
{
if (animationProgress == value) return;
animationProgress = value;
Invalidate(Invalidation.DrawInfo);
}
}
public override bool IsPresent => true;
2020-07-23 04:10:59 +08:00
protected override DrawNode CreateDrawNode() => new LogoAnimationDrawNode(this);
2020-06-24 20:11:38 +08:00
2020-07-23 04:10:59 +08:00
private class LogoAnimationDrawNode : SpriteDrawNode
2020-06-24 20:11:38 +08:00
{
2020-07-23 04:10:59 +08:00
private LogoAnimation source => (LogoAnimation)Source;
2020-06-24 20:11:38 +08:00
2023-03-17 19:37:05 +08:00
private readonly Action<TexturedVertex2D> addVertexAction;
2020-06-24 20:11:38 +08:00
private float progress;
2020-07-23 04:10:59 +08:00
public LogoAnimationDrawNode(LogoAnimation source)
2020-06-24 20:11:38 +08:00
: base(source)
{
2023-03-17 19:37:05 +08:00
addVertexAction = v =>
{
animationVertexBatch!.Add(new LogoAnimationVertex
{
Position = v.Position,
Colour = v.Colour,
TexturePosition = v.TexturePosition,
});
};
2020-06-24 20:11:38 +08:00
}
public override void ApplyState()
{
base.ApplyState();
2020-06-25 06:59:12 +08:00
progress = source.animationProgress;
2020-06-24 20:11:38 +08:00
}
2023-02-25 00:21:37 +08:00
private IUniformBuffer<AnimationData> animationDataBuffer;
2023-03-17 19:37:05 +08:00
private IVertexBatch<LogoAnimationVertex> animationVertexBatch;
2023-02-25 00:21:37 +08:00
protected override void BindUniformResources(IShader shader, IRenderer renderer)
2020-06-24 20:11:38 +08:00
{
base.BindUniformResources(shader, renderer);
2023-02-25 00:21:37 +08:00
animationDataBuffer ??= renderer.CreateUniformBuffer<AnimationData>();
2023-03-17 19:37:05 +08:00
animationVertexBatch ??= renderer.CreateQuadBatch<LogoAnimationVertex>(1, 2);
2023-02-25 00:21:37 +08:00
animationDataBuffer.Data = animationDataBuffer.Data with { Progress = progress };
shader.BindUniformBlock(@"m_AnimationData", animationDataBuffer);
2020-06-24 20:11:38 +08:00
}
protected override void Blit(IRenderer renderer)
{
if (DrawRectangle.Width == 0 || DrawRectangle.Height == 0)
return;
base.Blit(renderer);
2020-06-24 20:11:38 +08:00
2023-03-17 19:47:11 +08:00
renderer.DrawQuad(
Texture,
ScreenSpaceDrawQuad,
DrawColourInfo.Colour,
inflationPercentage: new Vector2(InflationAmount.X / DrawRectangle.Width, InflationAmount.Y / DrawRectangle.Height),
textureCoords: TextureCoords,
vertexAction: addVertexAction);
2020-06-24 20:11:38 +08:00
}
protected override bool CanDrawOpaqueInterior => false;
2023-02-25 00:21:37 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
animationDataBuffer?.Dispose();
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private record struct AnimationData
{
public UniformFloat Progress;
private readonly UniformPadding12 pad1;
}
2023-03-17 19:37:05 +08:00
[StructLayout(LayoutKind.Sequential)]
private struct LogoAnimationVertex : IEquatable<LogoAnimationVertex>, IVertex
{
[VertexMember(2, VertexAttribPointerType.Float)]
public Vector2 Position;
[VertexMember(4, VertexAttribPointerType.Float)]
public Color4 Colour;
[VertexMember(2, VertexAttribPointerType.Float)]
public Vector2 TexturePosition;
public readonly bool Equals(LogoAnimationVertex other) =>
Position.Equals(other.Position)
&& TexturePosition.Equals(other.TexturePosition)
&& Colour.Equals(other.Colour);
}
2020-06-24 20:11:38 +08:00
}
}
}