diff --git a/osu.Framework.Font.Tests/Visual/BackgroundGridTestSample.cs b/osu.Framework.Font.Tests/Visual/BackgroundGridTestSample.cs index 1ba489c..05d66b8 100644 --- a/osu.Framework.Font.Tests/Visual/BackgroundGridTestSample.cs +++ b/osu.Framework.Font.Tests/Visual/BackgroundGridTestSample.cs @@ -80,8 +80,8 @@ protected BackgroundGridTestSample() protected IShader GetShader(string shaderName) => shaderManager.Load(VertexShaderDescriptor.TEXTURE_2, shaderName); - protected T GetShaderByType() where T : class, ICustomizedShader - => shaderManager.LocalCustomizedShader(); + protected T GetShaderByType() where T : InternalShader + => shaderManager.LocalInternalShader(); protected class DraggableCircle : Circle { diff --git a/osu.Framework.Font/Extensions/ShaderManagerExtensions.cs b/osu.Framework.Font/Extensions/ShaderManagerExtensions.cs index b6377f8..b30c4f1 100644 --- a/osu.Framework.Font/Extensions/ShaderManagerExtensions.cs +++ b/osu.Framework.Font/Extensions/ShaderManagerExtensions.cs @@ -8,18 +8,11 @@ namespace osu.Framework.Extensions { public static class ShaderManagerExtensions { - public static T LocalCustomizedShader(this ShaderManager shaderManager) where T : class, ICustomizedShader + public static T LocalInternalShader(this ShaderManager shaderManager) where T : InternalShader { - var type = typeof(T); - - return type switch - { - Type _ when type == typeof(OutlineShader) => new OutlineShader(shaderManager.Load(VertexShaderDescriptor.TEXTURE_2, OutlineShader.SHADER_NAME)) as T, - Type _ when type == typeof(RainbowShader) => new RainbowShader(shaderManager.Load(VertexShaderDescriptor.TEXTURE_2, RainbowShader.SHADER_NAME)) as T, - Type _ when type == typeof(ShadowShader) => new ShadowShader(shaderManager.Load(VertexShaderDescriptor.TEXTURE_2, ShadowShader.SHADER_NAME)) as T, - Type _ when type == typeof(PixelShader) => new PixelShader(shaderManager.Load(VertexShaderDescriptor.TEXTURE_2, PixelShader.SHADER_NAME)) as T, - _ => throw new NotImplementedException() - }; + var shaderName = ((T)Activator.CreateInstance(typeof(T), default(IShader))).ShaderName; + var shader = shaderManager.Load(VertexShaderDescriptor.TEXTURE_2, shaderName); + return (T)Activator.CreateInstance(typeof(T), shader); } } } diff --git a/osu.Framework.Font/Graphics/Shaders/InternalShader.cs b/osu.Framework.Font/Graphics/Shaders/InternalShader.cs new file mode 100644 index 0000000..bfd6306 --- /dev/null +++ b/osu.Framework.Font/Graphics/Shaders/InternalShader.cs @@ -0,0 +1,15 @@ +// Copyright (c) andy840119 . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Framework.Graphics.Shaders +{ + public abstract class InternalShader : CustomizedShader + { + public abstract string ShaderName { get; } + + protected InternalShader(IShader originShader) + : base(originShader) + { + } + } +} diff --git a/osu.Framework.Font/Graphics/Shaders/OutlineShader.cs b/osu.Framework.Font/Graphics/Shaders/OutlineShader.cs index 893fa2b..6154c6d 100644 --- a/osu.Framework.Font/Graphics/Shaders/OutlineShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/OutlineShader.cs @@ -7,9 +7,10 @@ namespace osu.Framework.Graphics.Shaders { - public class OutlineShader : CustomizedShader + public class OutlineShader : InternalShader { - public const string SHADER_NAME = "Outline"; + public override string ShaderName => "Outline"; + public int Radius { get; set; } public Color4 OutlineColour { get; set; } diff --git a/osu.Framework.Font/Graphics/Shaders/PixelShader.cs b/osu.Framework.Font/Graphics/Shaders/PixelShader.cs index f82a0d3..56ee452 100644 --- a/osu.Framework.Font/Graphics/Shaders/PixelShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/PixelShader.cs @@ -6,9 +6,9 @@ namespace osu.Framework.Graphics.Shaders { - public class PixelShader : CustomizedShader + public class PixelShader : InternalShader { - public const string SHADER_NAME = "Pixel"; + public override string ShaderName => "Pixel"; public Vector2 Size { get; set; } = new Vector2(5); diff --git a/osu.Framework.Font/Graphics/Shaders/RainbowShader.cs b/osu.Framework.Font/Graphics/Shaders/RainbowShader.cs index 3dedc1b..e0a5b85 100644 --- a/osu.Framework.Font/Graphics/Shaders/RainbowShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/RainbowShader.cs @@ -6,9 +6,9 @@ namespace osu.Framework.Graphics.Shaders { - public class RainbowShader : CustomizedShader, IApplicableToCurrentTime + public class RainbowShader : InternalShader, IApplicableToCurrentTime { - public const string SHADER_NAME = "Rainbow"; + public override string ShaderName => "Rainbow"; public Vector2 Uv { get; set; } = new Vector2(0, 1); diff --git a/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs b/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs index 975b582..1f7370f 100644 --- a/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs @@ -7,9 +7,9 @@ namespace osu.Framework.Graphics.Shaders { - public class ShadowShader : CustomizedShader + public class ShadowShader : InternalShader { - public const string SHADER_NAME = "Shadow"; + public override string ShaderName => "Shadow"; public Color4 ShadowColour { get; set; }