1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 18:12:59 +08:00
osu-lazer/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs

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

97 lines
2.8 KiB
C#
Raw Normal View History

2022-11-13 19:59:17 +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.
using osu.Framework.Allocation;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Rendering;
namespace osu.Game.Tests.Visual.Background
{
public partial class TestSceneTriangleBorderShader : OsuTestScene
{
2022-11-21 15:20:35 +08:00
private readonly TriangleBorder border;
2022-11-13 19:59:17 +08:00
public TestSceneTriangleBorderShader()
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.DarkGreen
},
2022-11-21 15:20:35 +08:00
border = new TriangleBorder
2022-11-13 19:59:17 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(100)
}
};
}
2022-11-21 15:20:35 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
AddSliderStep("Thickness", 0f, 1f, 0.02f, t => border.Thickness = t);
}
2022-11-13 19:59:17 +08:00
private partial class TriangleBorder : Sprite
{
2022-11-21 15:20:35 +08:00
private float thickness = 0.02f;
public float Thickness
{
get => thickness;
set
{
thickness = value;
Invalidate(Invalidation.DrawNode);
}
}
2022-11-13 19:59:17 +08:00
[BackgroundDependencyLoader]
private void load(ShaderManager shaders, IRenderer renderer)
{
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "TriangleBorder");
Texture = renderer.WhitePixel;
}
protected override DrawNode CreateDrawNode() => new TriangleBorderDrawNode(this);
private class TriangleBorderDrawNode : SpriteDrawNode
{
2022-11-21 15:20:35 +08:00
public new TriangleBorder Source => (TriangleBorder)base.Source;
2022-11-13 19:59:17 +08:00
public TriangleBorderDrawNode(TriangleBorder source)
: base(source)
{
}
2022-11-21 15:20:35 +08:00
private float thickness;
public override void ApplyState()
{
base.ApplyState();
thickness = Source.thickness;
}
public override void Draw(IRenderer renderer)
{
TextureShader.GetUniform<float>("thickness").UpdateValue(ref thickness);
base.Draw(renderer);
}
2022-11-13 19:59:17 +08:00
protected override bool CanDrawOpaqueInterior => false;
}
}
}
}