using AcDream.App; using AcDream.App.Composition; using Silk.NET.Core.Contexts; using Silk.NET.OpenGL; namespace AcDream.App.Tests.Composition; /// /// Campaign V slice V6h: the graphics handle composition tests hand to a phase. /// /// The phases now select their backend arm from /// rather than from a bare GL reference, /// so a test that means "compose the OpenGL arm" has to say so. The GL instance /// is never called: every composition test supplies a stub factory that ignores /// its context argument, and the loader below would fault if anything did — which /// is the point. It is a token identifying the arm, not a driver. /// internal sealed class TestGameWindowGraphics : GameWindowGraphics { private readonly GL? _gl; private TestGameWindowGraphics(RenderBackendKind backend, GL? gl) { Backend = backend; _gl = gl; } /// Selects the OpenGL arm, with a context token no test dereferences. public static TestGameWindowGraphics OpenGl { get; } = new(RenderBackendKind.Gl, new GL(new UnusableNativeContext())); /// Selects the Vulkan arm: no GL context exists. public static TestGameWindowGraphics Vulkan { get; } = new(RenderBackendKind.Vulkan, null); public override RenderBackendKind Backend { get; } public override GL? Gl => _gl; public override void Dispose() { } private sealed class UnusableNativeContext : INativeContext { public nint GetProcAddress(string proc, int? slot = null) => throw new InvalidOperationException( $"A composition test called GL entry point '{proc}'. " + "Test graphics are a backend token, not a driver."); public bool TryGetProcAddress(string proc, out nint addr, int? slot = null) { addr = 0; return false; } public void Dispose() { } } }