Skip to content

Commit

Permalink
Load internal shader now not need to list all the shader.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Oct 23, 2021
1 parent a1b2055 commit f5fd009
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
4 changes: 2 additions & 2 deletions osu.Framework.Font.Tests/Visual/BackgroundGridTestSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ protected BackgroundGridTestSample()
protected IShader GetShader(string shaderName)
=> shaderManager.Load(VertexShaderDescriptor.TEXTURE_2, shaderName);

protected T GetShaderByType<T>() where T : class, ICustomizedShader
=> shaderManager.LocalCustomizedShader<T>();
protected T GetShaderByType<T>() where T : InternalShader
=> shaderManager.LocalInternalShader<T>();

protected class DraggableCircle : Circle
{
Expand Down
15 changes: 4 additions & 11 deletions osu.Framework.Font/Extensions/ShaderManagerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ namespace osu.Framework.Extensions
{
public static class ShaderManagerExtensions
{
public static T LocalCustomizedShader<T>(this ShaderManager shaderManager) where T : class, ICustomizedShader
public static T LocalInternalShader<T>(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);
}
}
}

0 comments on commit f5fd009

Please sign in to comment.