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
|
|
|
|
|
{
|
2022-11-26 23:30:10 +08:00
|
|
|
|
public partial class TestSceneTriangleBorderShader : OsuTestScene
|
2022-11-13 19:59:17 +08:00
|
|
|
|
{
|
2023-02-01 15:35:25 +08:00
|
|
|
|
private readonly TestTriangle triangle;
|
2022-11-21 15:20:35 +08:00
|
|
|
|
|
2022-11-13 19:59:17 +08:00
|
|
|
|
public TestSceneTriangleBorderShader()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.DarkGreen
|
|
|
|
|
},
|
2023-02-01 15:35:25 +08:00
|
|
|
|
triangle = new TestTriangle
|
2022-11-13 19:59:17 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2023-02-01 15:35:25 +08:00
|
|
|
|
Size = new Vector2(200)
|
2022-11-13 19:59:17 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 15:20:35 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2023-02-01 15:35:25 +08:00
|
|
|
|
AddSliderStep("Thickness", 0f, 1f, 0.15f, t => triangle.Thickness = t);
|
|
|
|
|
AddSliderStep("Texel size", 0f, 0.1f, 0f, t => triangle.TexelSize = t);
|
2022-11-21 15:20:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-01 15:35:25 +08:00
|
|
|
|
private partial class TestTriangle : Sprite
|
2022-11-13 19:59:17 +08:00
|
|
|
|
{
|
2023-02-01 15:35:25 +08:00
|
|
|
|
private float thickness = 0.15f;
|
2022-11-21 15:20:35 +08:00
|
|
|
|
|
|
|
|
|
public float Thickness
|
|
|
|
|
{
|
|
|
|
|
get => thickness;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
thickness = value;
|
|
|
|
|
Invalidate(Invalidation.DrawNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-01 15:35:25 +08:00
|
|
|
|
private float texelSize;
|
|
|
|
|
|
|
|
|
|
public float TexelSize
|
|
|
|
|
{
|
|
|
|
|
get => texelSize;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
texelSize = 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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-01 15:35:25 +08:00
|
|
|
|
protected override DrawNode CreateDrawNode() => new TriangleDrawNode(this);
|
2022-11-13 19:59:17 +08:00
|
|
|
|
|
2023-02-01 15:35:25 +08:00
|
|
|
|
private class TriangleDrawNode : SpriteDrawNode
|
2022-11-13 19:59:17 +08:00
|
|
|
|
{
|
2023-02-01 15:35:25 +08:00
|
|
|
|
public new TestTriangle Source => (TestTriangle)base.Source;
|
2022-11-21 15:20:35 +08:00
|
|
|
|
|
2023-02-01 15:35:25 +08:00
|
|
|
|
public TriangleDrawNode(TestTriangle source)
|
2022-11-13 19:59:17 +08:00
|
|
|
|
: base(source)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 15:20:35 +08:00
|
|
|
|
private float thickness;
|
2023-02-01 15:35:25 +08:00
|
|
|
|
private float texelSize;
|
2022-11-21 15:20:35 +08:00
|
|
|
|
|
|
|
|
|
public override void ApplyState()
|
|
|
|
|
{
|
|
|
|
|
base.ApplyState();
|
|
|
|
|
|
|
|
|
|
thickness = Source.thickness;
|
2023-02-01 15:35:25 +08:00
|
|
|
|
texelSize = Source.texelSize;
|
2022-11-21 15:20:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Draw(IRenderer renderer)
|
|
|
|
|
{
|
|
|
|
|
TextureShader.GetUniform<float>("thickness").UpdateValue(ref thickness);
|
2023-02-01 15:35:25 +08:00
|
|
|
|
TextureShader.GetUniform<float>("texelSize").UpdateValue(ref texelSize);
|
2022-11-21 15:20:35 +08:00
|
|
|
|
|
|
|
|
|
base.Draw(renderer);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-13 19:59:17 +08:00
|
|
|
|
protected override bool CanDrawOpaqueInterior => false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|