From f5fd00993337c5e2304dfb87951e3b3b6f7b1197 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Oct 2021 23:52:20 +0800 Subject: [PATCH] Load internal shader now not need to list all the shader. --- .../Visual/BackgroundGridTestSample.cs | 4 ++-- .../Extensions/ShaderManagerExtensions.cs | 15 ++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) 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); } } }