public void Run() { GraphicsDeviceOptions options = new GraphicsDeviceOptions( debug: false, swapchainDepthFormat: PixelFormat.R16_UNorm, syncToVerticalBlank: true, resourceBindingModel: ResourceBindingModel.Improved, preferDepthRangeZeroToOne: true, preferStandardClipSpaceYDirection: true); #if DEBUG options.Debug = true; #endif // construct a graphics device using the default backend. _gd = VeldridStartup.CreateGraphicsDevice(_window, options); // to determine what the default backend is you can run: //VeldridStartup.GetPlatformDefaultBackend() // to specify a specific backend use: //_gd = VeldridStartup.CreateGraphicsDevice(_window, options, GraphicsBackend.Metal); _factory = new DisposeCollectorResourceFactory(_gd.ResourceFactory); GraphicsDeviceCreated?.Invoke(_gd, _factory, _gd.MainSwapchain); Stopwatch sw = Stopwatch.StartNew(); double previousElapsed = sw.Elapsed.TotalSeconds; while (IsWindowOpen()) { double newElapsed = sw.Elapsed.TotalSeconds; float deltaSeconds = (float)(newElapsed - previousElapsed); InputSnapshot inputSnapshot = _window.PumpEvents(); InputTracker.UpdateFrameInput(inputSnapshot); if (_window.Exists) { previousElapsed = newElapsed; if (_windowResized) { _windowResized = false; _gd.ResizeMainWindow((uint)_window.Width, (uint)_window.Height); Resized?.Invoke(); } Rendering?.Invoke(deltaSeconds); } } Shutdown?.Invoke(); _gd.WaitForIdle(); _factory.DisposeCollector.DisposeAll(); _gd.Dispose(); GraphicsDeviceDestroyed?.Invoke(); }
public void Run() { GraphicsDeviceOptions options = new GraphicsDeviceOptions( debug: false, swapchainDepthFormat: PixelFormat.R16_UNorm, syncToVerticalBlank: true, resourceBindingModel: ResourceBindingModel.Improved); #if DEBUG options.Debug = true; #endif _gd = VeldridStartup.CreateGraphicsDevice(_window, options); _factory = new DisposeCollectorResourceFactory(_gd.ResourceFactory); GraphicsDeviceCreated?.Invoke(_gd, _factory, _gd.MainSwapchain); Stopwatch sw = Stopwatch.StartNew(); double previousElapsed = sw.Elapsed.TotalSeconds; while (_window.Exists) { double newElapsed = sw.Elapsed.TotalSeconds; float deltaSeconds = (float)(newElapsed - previousElapsed); InputSnapshot inputSnapshot = _window.PumpEvents(); InputTracker.UpdateFrameInput(inputSnapshot); if (_window.Exists) { previousElapsed = newElapsed; if (_windowResized) { _windowResized = false; _gd.ResizeMainWindow((uint)_window.Width, (uint)_window.Height); Resized?.Invoke(); } Rendering?.Invoke(deltaSeconds); } } _gd.WaitForIdle(); _factory.DisposeCollector.DisposeAll(); _gd.Dispose(); GraphicsDeviceDestroyed?.Invoke(); }
private bool IsWindowOpen() { bool CommandKeyIsPressed = InputTracker.GetKey(Key.WinLeft) || InputTracker.GetKey(Key.WinRight); bool ControlKeyIsPressed = InputTracker.GetKey(Key.ControlLeft) || InputTracker.GetKey(Key.ControlRight); bool WindowExists = _window.Exists; bool WorQWasPressed = InputTracker.GetKey(Key.W) || InputTracker.GetKey(Key.Q); if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { return(WindowExists && !(CommandKeyIsPressed && WorQWasPressed)); } else { return(WindowExists && !(ControlKeyIsPressed && WorQWasPressed)); } }