Apply changes to custom ShaderManager

This commit is contained in:
Dan Balasescu 2023-04-18 11:31:56 +09:00
parent 7aeab174eb
commit c0a25144cf
3 changed files with 6 additions and 22 deletions

View File

@ -164,7 +164,7 @@ public TestShaderManager(IRenderer renderer, ShaderManager parentManager)
this.parentManager = parentManager;
}
public override byte[] LoadRaw(string name) => parentManager.LoadRaw(name);
public override byte[] GetRawData(string fileName) => parentManager.GetRawData(fileName);
public bool IsDisposed { get; private set; }

View File

@ -51,8 +51,8 @@ public void TestRetrieveShader()
{
AddStep("ruleset shaders retrieved without error", () =>
{
Dependencies.Get<ShaderManager>().LoadRaw(@"sh_TestVertex.vs");
Dependencies.Get<ShaderManager>().LoadRaw(@"sh_TestFragment.fs");
Dependencies.Get<ShaderManager>().GetRawData(@"sh_TestVertex.vs");
Dependencies.Get<ShaderManager>().GetRawData(@"sh_TestFragment.fs");
});
}

View File

@ -206,27 +206,11 @@ public RulesetShaderManager(IRenderer renderer, NamespacedResourceStore<byte[]>
this.parent = parent;
}
// When the debugger is attached, exceptions are expensive.
// Manually work around this by caching failed lookups and falling back straight to parent.
private readonly HashSet<(string, string)> failedLookups = new HashSet<(string, string)>();
public override IShader? GetCachedShader(string vertex, string fragment) => base.GetCachedShader(vertex, fragment) ?? parent.GetCachedShader(vertex, fragment);
public override IShader Load(string vertex, string fragment)
{
if (!failedLookups.Contains((vertex, fragment)))
{
try
{
return base.Load(vertex, fragment);
}
catch
{
// Shader lookup is very non-standard. Rather than returning null on missing shaders, exceptions are thrown.
failedLookups.Add((vertex, fragment));
}
}
public override IShaderPart? GetCachedShaderPart(string name) => base.GetCachedShaderPart(name) ?? parent.GetCachedShaderPart(name);
return parent.Load(vertex, fragment);
}
public override byte[]? GetRawData(string fileName) => base.GetRawData(fileName) ?? parent.GetRawData(fileName);
}
}
}