using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; using Blacklight.Core; using Blacklight.Core.Cameras; using Blacklight.Testbed; using Blacklight.WebGL2; // [JSImport]/[JSExport] require the assembly to be marked browser-targeted, or they won't compile. [assembly: SupportedOSPlatform("browser")] namespace Blacklight.WebGL2.Testbed { internal static class Program { private static WindowHandle windowHandle = null!; private static World world = null!; private static void OnFrame(double timestampMs) { windowHandle.FrameReset(); world.DrawScene(); windowHandle.SubmitDrawCalls(); } private static async Task Main() { await GL.EnsureLoadedAsync(); windowHandle = WebGL2Backend.CreateWindowHandle(); // Matches the desktop testbed's background so the two are visually comparable. windowHandle.BackgroundColor = new Color(0, 0.5, 1.0); var camera = new MicroscopeCamera(windowHandle); world = new World(); world.Bind(windowHandle, camera); var controller = new MicroscopeController { Handle = windowHandle }; var input = new WebGL2Input(WebGL2Backend.DefaultCanvasElementId, controller); GL.StartRenderLoop(OnFrame); // Don't let Main return. The browser drives frames, but the runtime must stay resident. await Task.Delay(Timeout.Infinite); } } }