Пример #1
0
        /// <summary>
        /// Infinitely calls the Render task until the overlay closes.
        /// </summary>
        private async Task RunInfiniteLoop(CancellationToken cancellationToken)
        {
            var stopwatch = Stopwatch.StartNew();

            while (window.Exists && !cancellationToken.IsCancellationRequested)
            {
                InputSnapshot snapshot = window.PumpEvents();
                if (!window.Exists)
                {
                    break;
                }

                var deltaSeconds = (float)stopwatch.ElapsedTicks / Stopwatch.Frequency;
                stopwatch.Restart();
                imController.Update(deltaSeconds, snapshot, window.Handle);

                await Render();

                commandList.Begin();
                commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
                commandList.ClearColorTarget(0, new RgbaFloat(0.00f, 0.00f, 0.00f, 0.00f));
                imController.Render(graphicsDevice, commandList);
                commandList.End();
                graphicsDevice.SubmitCommands(commandList);
                graphicsDevice.SwapBuffers(graphicsDevice.MainSwapchain);
            }

            if (window.Exists)
            {
                window.Close();
            }
        }
Пример #2
0
        private void ChangeBackend(GraphicsBackend backend)
        {
            DestroyAllObjects();
            bool syncToVBlank = _gd.SyncToVerticalBlank;

            _gd.Dispose();

            if (_recreateWindow)
            {
                WindowCreateInfo windowCI = new WindowCreateInfo
                {
                    X                  = _window.X,
                    Y                  = _window.Y,
                    WindowWidth        = _window.Width,
                    WindowHeight       = _window.Height,
                    WindowInitialState = _window.WindowState,
                    WindowTitle        = "Veldrid NeoDemo"
                };

                _window.Close();

                _window          = VeldridStartup.CreateWindow(ref windowCI);
                _window.Resized += () => _windowResized = true;
            }

            GraphicsDeviceOptions gdOptions = new GraphicsDeviceOptions(false, null, syncToVBlank);

#if DEBUG
            gdOptions.Debug = true;
#endif
            _gd = VeldridStartup.CreateGraphicsDevice(_window, gdOptions, backend);

            CreateAllObjects();
        }
Пример #3
0
 public void Dispose()
 {
     _gd.WaitForIdle(); // TODO: Shouldn't be necessary, but Vulkan backend trips a validation error (swapchain in use when disposed).
     _sc.Dispose();
     _window.Close();
     _gcHandle.Free();
 }
Пример #4
0
 public void Dispose()
 {
     GD.WaitForIdle();
     _factory.DisposeCollector.DisposeAll();
     GD.Dispose();
     _window?.Close();
 }
Пример #5
0
        private void MainLoop(CancellationToken cancellationToken)
        {
            while (_window.Exists && !cancellationToken.IsCancellationRequested)
            {
                var snapshot = _window.PumpEvents();
                if (!_window.Exists)
                {
                    break;
                }

                _controller.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

                Render();

                _cl.Begin();
                _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
                _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 0.0f));
                _controller.Render(_gd, _cl);
                _cl.End();
                _gd.SubmitCommands(_cl);
                _gd.SwapBuffers(_gd.MainSwapchain);
            }

            if (_window.Exists)
            {
                _window.Close();
            }
        }
Пример #6
0
 public void Dispose()
 {
     _window.Close();
     GD.WaitForIdle();
     _factory.DisposeCollector.DisposeAll();
     if (GD.BackendType != GraphicsBackend.OpenGL)
     {
         GD.Dispose();
     }
 }
Пример #7
0
 public void Shutdown()
 {
     _gd.WaitForIdle();
     _factory.DisposeCollector.DisposeAll();
     _factory = null;
     _gd.Dispose();
     _gd = null;
     _window.Close();
     _window = null;
 }
Пример #8
0
        private static void Update()
        {
            if (inputSnapshot.KeyEvents.Any(ke => ke.Key == Key.Escape && ke.Down))
            {
                window.Close();
            }
            if (inputSnapshot.KeyEvents.Any(ke => ke.Key == Key.Up && ke.Down))
            {
                fontSize += 0.5f;
                UpdateFont();
            }
            if (inputSnapshot.KeyEvents.Any(ke => ke.Key == Key.Down && ke.Down))
            {
                fontSize -= 0.5f;
                UpdateFont();
            }
            if (inputSnapshot.KeyEvents.Any(ke => ke.Key == Key.Left && ke.Down))
            {
                letterSpacing -= 0.01f;
            }
            if (inputSnapshot.KeyEvents.Any(ke => ke.Key == Key.Right && ke.Down))
            {
                letterSpacing += 0.01f;
            }
            if (inputSnapshot.KeyEvents.Any(ke => ke.Key == Key.Enter && ke.Down))
            {
                currentFontIndex = (currentFontIndex + 1) % fonts.Length;
                UpdateFont();
            }
            if (inputSnapshot.KeyEvents.Any(ke => ke.Key == Key.Space && ke.Down))
            {
                currentColorIndex = (currentColorIndex + 1) % colors.Length;
            }

            infoTextRenderer.Update();
            demoTextRenderer.Update();

            var         xAccumulated = 0f;
            const float xInset       = 10;
            const float lineSpacing  = 5;

            infoTextRenderer.DrawText("Debug Controls:", new Vector2(xInset, xAccumulated += xInset), colors[0]);
            infoTextRenderer.DrawText("Up/Down = Increase/Decrease Font Size", new Vector2(xInset, xAccumulated         += lineSpacing + infoFont.FontSizeInPixels), colors[0]);
            infoTextRenderer.DrawText("Right/Left = Increase/Decrease Letter Spacing", new Vector2(xInset, xAccumulated += lineSpacing + infoFont.FontSizeInPixels), colors[0]);
            infoTextRenderer.DrawText("Enter = Change Font", new Vector2(xInset, xAccumulated            += lineSpacing + infoFont.FontSizeInPixels), colors[0]);
            infoTextRenderer.DrawText("Space = Change Colorm", new Vector2(xInset, xAccumulated          += lineSpacing + infoFont.FontSizeInPixels), colors[0]);
            infoTextRenderer.DrawText($"Current Font: {demoFont.Name}", new Vector2(xInset, xAccumulated += lineSpacing + infoFont.FontSizeInPixels), colors[0]);

            demoTextRenderer.DrawText("Sixty zippers were quickly picked from the woven jute bag.", new Vector2(xInset, xAccumulated += (lineSpacing * 5) + infoFont.FontSizeInPixels), colors[currentColorIndex], letterSpacing);
            demoTextRenderer.DrawText("The quick brown fox jumps over the lazy dog", new Vector2(xInset, xAccumulated += lineSpacing + demoFont.FontSizeInPixels), colors[(currentColorIndex + 1) % colors.Length], letterSpacing);
            demoTextRenderer.DrawText("How vexingly quick daft zebras jump!", new Vector2(xInset, xAccumulated        += lineSpacing + demoFont.FontSizeInPixels), colors[(currentColorIndex + 2) % colors.Length], letterSpacing);
        }
Пример #9
0
 /// <summary>
 /// Disposes of all elements in _sceneResources
 /// </summary>
 public virtual void Dispose()
 {
     _frameTimer.Cancel();
     _graphicsDevice.WaitForIdle();
     foreach (var child in _allChildren)
     {
         child.Dispose();
     }
     _allChildren.Clear();
     _frameTimer.Dispose();
     _factory.DisposeCollector.DisposeAll();
     _graphicsDevice.WaitForIdle();
     _graphicsDevice.Dispose();
     _contextWindow.Close();
 }
Пример #10
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             window.Close();
             EventCallback = null;
             swapchain.Framebuffer.Dispose();
             swapchain.Dispose();
             GcHandle.Free();
         }
         disposed = true;
     }
 }
Пример #11
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCi = new WindowCreateInfo()
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 800,
                WindowHeight       = 600,
                WindowTitle        = "Pentagonal Hexecontahedron",
                WindowInitialState = WindowState.Normal
            };
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                true,
                PixelFormat.R16_UNorm,
                true,
                ResourceBindingModel.Improved,
                true,
                true);

            _window          = VeldridStartup.CreateWindow(ref windowCi);
            _window.Resized += () => { _isResized = true; };

            _window.KeyUp += keyArg =>
            {
                if (keyArg.Key == Key.Escape)
                {
                    _window.Close();
                }
            };
            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_window, options, GraphicsBackend.Vulkan);

            CreateResources();

            while (_window.Exists)
            {
                InputSnapshot snapshot = _window.PumpEvents();
                if (snapshot.IsMouseDown(MouseButton.Left))
                {
                    _rotate += 0.01f;
                    ViewProjectionUpdate();
                }
                Draw();
            }

            DisposeResources();
        }
Пример #12
0
        public void Dispose()
        {
            if (m_IsDisposed)
            {
                return;
            }

            m_UiRenderers.Clear();
            m_GraphicsDevice?.WaitForIdle();
            m_ImguiManager?.Dispose();
            m_CommandList?.Dispose();
            m_GraphicsDevice?.Dispose();
            if (m_Window != null)
            {
                m_Window.Resized -= OnWindowResize;
                m_Window.Close();
            }
            m_IsDisposed = true;
        }
        /// <summary>
        /// Free all resources acquired by the overlay
        /// </summary>
        public void Dispose()
        {
            window.Close();
            while (!isClosed)
            {
                Thread.Sleep(10);
            }

            uiThread.Join();
            graphicsDevice.WaitForIdle();
            imController.Dispose();
            commandList.Dispose();
            graphicsDevice.Dispose();
            hookController.Dispose();
            NativeMethods.ShowConsoleWindow();
            this.SubmitUI = null;
            Console.WriteLine("All Overlay resources are cleared.");
            Application.Exit();
        }
Пример #14
0
        private void UpdateAndDrawGui()
        {
            ImGui.SetNextWindowPos(Vector2.Zero, ImGuiCond.Always, Vector2.Zero);
            ImGui.SetNextWindowSize(new Vector2(Window.Width, Window.Height), ImGuiCond.Always);

            ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0);

            if (ImGui.BeginMainMenuBar())
            {
                if (ImGui.BeginMenu("File"))
                {
                    if (ImGui.MenuItem("Exit"))
                    {
                        Window.Close();
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu($"Change Screen ({Screens[CurrentScreen].Title})"))
                {
                    if (ImGui.MenuItem("ALF-Browser") && CurrentScreen != 0)
                    {
                        CurrentScreen = 0;
                    }

                    if (ImGui.MenuItem("Level Browser") && CurrentScreen != 1)
                    {
                        CurrentScreen = 1;
                    }

                    ImGui.EndMenu();
                }

                ImGui.EndMainMenuBar();
            }

            Screens[CurrentScreen]?.Update(1.0f / 60.0f);
            Screens[CurrentScreen]?.Render(Window, Gd, ImGuiRenderer);

            ImGui.PopStyleVar();
        }
Пример #15
0
        public void Ctor_SetsProperties(PixelFormat?depthFormat, bool syncToVerticalBlank)
        {
            Sdl2Window           window        = new Sdl2Window("SwapchainTestWindow", 0, 0, 100, 100, SDL_WindowFlags.Hidden, false);
            SwapchainSource      source        = VeldridStartup.GetSwapchainSource(window);
            SwapchainDescription swapchainDesc = new SwapchainDescription(source, 100, 100, depthFormat, syncToVerticalBlank);
            Swapchain            swapchain     = RF.CreateSwapchain(ref swapchainDesc);

            if (depthFormat == null)
            {
                Assert.Null(swapchain.Framebuffer.DepthTarget);
            }
            else
            {
                Assert.NotNull(swapchain.Framebuffer.DepthTarget);
                Assert.Equal(depthFormat, swapchain.Framebuffer.DepthTarget.Value.Target.Format);
            }

            Assert.Equal(syncToVerticalBlank, swapchain.SyncToVerticalBlank);

            window.Close();
        }
Пример #16
0
        private void ChangeRenderContext(GraphicsBackend backend)
        {
            _sc.DestroyDeviceObjects();
            _scene.DestroyAllDeviceObjects();
            CommonMaterials.DestroyAllDeviceObjects();

            _rc.Dispose();

            if (_recreateWindow)
            {
                WindowCreateInfo windowCI = new WindowCreateInfo
                {
                    X                  = _window.X,
                    Y                  = _window.Y,
                    WindowWidth        = _window.Width,
                    WindowHeight       = _window.Height,
                    WindowInitialState = _window.WindowState,
                    WindowTitle        = "Veldrid NeoDemo"
                };

                _window.Close();

                _window          = VeldridStartup.CreateWindow(ref windowCI);
                _window.Resized += () => _windowResized = true;
            }

            RenderContextCreateInfo rcCI = new RenderContextCreateInfo
            {
                Backend = backend
            };

            _rc = VeldridStartup.CreateRenderContext(ref rcCI, _window);

            _sc.CreateDeviceObjects(_rc);
            _scene.CreateAllDeviceObjects(_rc);
            CommonMaterials.CreateAllDeviceObjects(_rc);
        }
Пример #17
0
        private void ChangeBackend(GraphicsBackend backend)
        {
            DestroyAllObjects();

            _gd.Dispose();

            if (_recreateWindow)
            {
                WindowCreateInfo windowCI = new WindowCreateInfo
                {
                    X                  = _window.X,
                    Y                  = _window.Y,
                    WindowWidth        = _window.Width,
                    WindowHeight       = _window.Height,
                    WindowInitialState = _window.WindowState,
                    WindowTitle        = "Veldrid NeoDemo"
                };

                _window.Close();

                _window          = VeldridStartup.CreateWindow(ref windowCI);
                _window.Resized += () => _windowResized = true;
            }

            GraphicsDeviceCreateInfo rcCI = new GraphicsDeviceCreateInfo
            {
                Backend = backend,
#if DEBUG
                DebugDevice = true
#endif
            };

            _gd = VeldridStartup.CreateGraphicsDevice(ref rcCI, _window);

            CreateAllObjects();
        }
Пример #18
0
 public void Close()
 {
     _window.Close();
 }
Пример #19
0
 public void Dispose() => _window.Close();
Пример #20
0
 public void Close() => _window.Close();
Пример #21
0
 public void Quit()
 {
     window.Close();
 }
Пример #22
0
 public static void Close()
 {
     window.Close();
 }
Пример #23
0
 public void Dispose()
 {
     _sc.Dispose();
     _window.Close();
     _gcHandle.Free();
 }
Пример #24
0
        private static void Main()
        {
            try
            {
                canceller = new CancellationTokenSource();

                window = new Sdl2Window(
                    "Veldrid - Console",
                    100, 100,
                    1280, 720,
                    SDL_WindowFlags.AllowHighDpi | SDL_WindowFlags.OpenGL | SDL_WindowFlags.Shown,
                    true);

                using var device = VeldridStartup.CreateGraphicsDevice(
                          window,
                          new GraphicsDeviceOptions
                {
                    SwapchainDepthFormat              = PixelFormat.D24_UNorm_S8_UInt,
                    ResourceBindingModel              = ResourceBindingModel.Improved,
                    SwapchainSrgbFormat               = false,
                    SyncToVerticalBlank               = true,
                    PreferDepthRangeZeroToOne         = true,
                    PreferStandardClipSpaceYDirection = true,
                },
                          GraphicsBackend.Vulkan);

                keys = new Win32KeyEventSource(canceller.Token);
                keys.AddKeyAlias("up", Keys.Up);
                keys.AddKeyAlias("down", Keys.Down);
                keys.AddKeyAlias("left", Keys.Left);
                keys.AddKeyAlias("right", Keys.Right);
                keys.AddKeyAlias("quit", Keys.Escape);
                keys.DefineAxis("horizontal", "left", "right");
                keys.DefineAxis("forward", "up", "down");

                mouse        = new Win32MouseMoveEventSource(canceller.Token);
                mouse.Moved += Mouse_Moved;

                demo = new VeldridDemoProgram(
                    device,
                    canceller.Token);
                demo.Error  += Demo_Error;;
                demo.Update += Demo_Update;

                keys.Start();
                mouse.Start();
                demo.Start();

                while (!canceller.IsCancellationRequested)
                {
                    _ = window.PumpEvents();
                }

                mouse.Quit();
                keys.Quit();
                demo.Quit();
                demo.Dispose();
                window.Close();
            }
            catch (Exception exp)
            {
                Console.Error.WriteLine(exp.Unroll());
            }
        }
Пример #25
0
 public void Shutdown()
 {
     _window.Close();
 }