Skip to content

Commit

Permalink
Merge pull request #70 from andy840119/make-internal-shader-interface
Browse files Browse the repository at this point in the history
Make internal shader has its own class.
  • Loading branch information
andy840119 authored Oct 23, 2021
2 parents 17f5950 + f5fd009 commit 2526e2e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 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);
}
}
}
15 changes: 15 additions & 0 deletions osu.Framework.Font/Graphics/Shaders/InternalShader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) andy840119 <[email protected]>. 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)
{
}
}
}
5 changes: 3 additions & 2 deletions osu.Framework.Font/Graphics/Shaders/OutlineShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework.Font/Graphics/Shaders/PixelShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions osu.Framework.Font/Graphics/Shaders/RainbowShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions osu.Framework.Font/Graphics/Shaders/ShadowShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down

0 comments on commit 2526e2e

Please sign in to comment.