/// <summary>
        /// Infinite While Loop to render the ImGui.
        /// </summary>
        private void WhileLoop()
        {
            while (window.Exists)
            {
                if (requireResize)
                {
                    Sdl2Native.SDL_SetWindowPosition(window.SdlWindowHandle, (int)futurePos.X, (int)futurePos.Y);
                    Sdl2Native.SDL_SetWindowSize(window.SdlWindowHandle, (int)futureSize.X, (int)futureSize.Y);
                    window.PumpEvents();
                    continue;
                }

                if (!window.Visible)
                {
                    window.PumpEvents();
                    Thread.Sleep(10);
                    continue;
                }

                if (!window.Exists)
                {
                    break;
                }

                imController.InitlizeFrame(1f / myFps);
                this.SubmitUI?.Invoke(this, new EventArgs());
                commandList.Begin();
                commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
                commandList.ClearColorTarget(0, new RgbaFloat(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W));
                imController.Render(graphicsDevice, commandList);
                commandList.End();
                graphicsDevice.SubmitCommands(commandList);
                graphicsDevice.SwapBuffers(graphicsDevice.MainSwapchain);
            }
        }
Пример #2
0
        public void Run()
        {
            Stopwatch s = new Stopwatch();

            s.Start();
            double secs = 0;

            while (Window.Exists)
            {
                InputSnapshot inputSnapshot = Window.PumpEvents();

                if (!Window.Exists)
                {
                    break;
                }

                // ToDo: GameTimer implementieren
                double news = s.Elapsed.TotalSeconds;
                ImGuiRenderer.Update((float)(news - secs), inputSnapshot);
                secs = news;
                UpdateAndDrawGui();

                Cl.Begin();
                Cl.SetFramebuffer(Gd.SwapchainFramebuffer);
                Cl.ClearColorTarget(0, new RgbaFloat(0.45f, 0.55f, 0.6f, 1.0f));

                ImGuiRenderer.Render(Gd, Cl);

                Cl.End();
                Gd.SubmitCommands(Cl);
                Gd.SwapBuffers();
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);
            stopwatch       = new Stopwatch();
            stopwatch.Start();

            CreateResources();

            while (window.Exists)
            {
                time[0] = (float)stopwatch.Elapsed.TotalSeconds;
                _graphicsDevice.UpdateBuffer(_uniformBuffer, 0, time);
                window.PumpEvents();
                Draw();
            }

            DisposeResources();
        }
Пример #4
0
        public void Tick()
        {
            if (!_window.Exists)
            {
                return;
            }

            InputSnapshot snapshot = _window.PumpEvents();

            if (!_window.Exists)
            {
                return;
            }

            double _newTime = _stopWatch.Elapsed.TotalSeconds;
            double deltaT   = _lastTime < 0 ? (1.0 / 60.0) : (_newTime - _lastTime);

            _lastTime = _newTime;

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

            if (OnDrawUI != null)
            {
                OnDrawUI();
            }

            _cl.Begin();
            _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 1f));
            _controller.Render(_gd, _cl);
            _cl.End();
            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers(_gd.MainSwapchain);
        }
Пример #5
0
        static void Main(string[] args)
        {
            AdbManager.Instance.Init();

            bool isWindows = System.Runtime.InteropServices.RuntimeInformation
                             .IsOSPlatform(OSPlatform.Windows);

            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 600, 400, WindowState.Normal, "LogMeow"),
                new GraphicsDeviceOptions(true, null, true),
                isWindows ? GraphicsBackend.Direct3D11 : GraphicsBackend.Metal,
                out window,
                out graphicDevice);

            window.Resized += () =>
            {
                graphicDevice.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);
                guiRender.WindowResized(window.Width, window.Height);
            };
            commandList = graphicDevice.ResourceFactory.CreateCommandList();
            guiRender   = new ImGuiRenderer(graphicDevice, graphicDevice.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height);

            window.Closed += () =>
            {
                Environment.Exit(0);
            };


            assembly = typeof(Program).Assembly;
            string[] names = assembly.GetManifestResourceNames();
            Console.WriteLine(String.Join(Environment.NewLine, names));
            LoadFont();

            // Main application loop
            while (window.Exists)
            {
                InputSnapshot snapshot = window.PumpEvents();
                if (!window.Exists)
                {
                    break;
                }
                guiRender.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

                SubmitUI();
                Singleton <LogMeowWorkspaceView> .Instance.draw();

                commandList.Begin();
                commandList.SetFramebuffer(graphicDevice.MainSwapchain.Framebuffer);
                commandList.ClearColorTarget(0, new RgbaFloat(backgroundColor.X, backgroundColor.Y, backgroundColor.Z, 1f));
                guiRender.Render(graphicDevice, commandList);
                commandList.End();
                graphicDevice.SubmitCommands(commandList);
                graphicDevice.SwapBuffers(graphicDevice.MainSwapchain);
            }

            graphicDevice.WaitForIdle();
            guiRender.Dispose();
            commandList.Dispose();
            graphicDevice.Dispose();
        }
Пример #6
0
        internal static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDevice = VeldridStartup.CreateGraphicsDevice(window);

            var bootstrapper = new VeldridBootstrap(GraphicsDevice);

            bootstrapper.CreateResources();
            bootstrapper.Draw(0, 0);

            while (window.Exists)
            {
                var events = window.PumpEvents();
                if (events.IsMouseDown(MouseButton.Left) && window.Exists)
                {
                    bootstrapper.Draw(events.MousePosition.X, events.MousePosition.Y);
                }
            }

            bootstrapper.DisposeResources();
        }
Пример #7
0
        public static void Run()
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };

            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true,
            };

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, options);

            window.Resized += () => _graphicsDevice.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();
                Draw();
            }

            DisposeResources();
        }
Пример #8
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();
            }
        }
Пример #9
0
        public void Run()
        {
            long      previousFrameTicks = 0;
            Stopwatch sw = new Stopwatch();

            sw.Start();
            while (_window.Exists)
            {
                long   currentFrameTicks = sw.ElapsedTicks;
                double deltaSeconds      = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency;

                while (_limitFrameRate && deltaSeconds < _desiredFrameLengthSeconds)
                {
                    currentFrameTicks = sw.ElapsedTicks;
                    deltaSeconds      = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency;
                }

                previousFrameTicks = currentFrameTicks;

                InputSnapshot snapshot = null;
                Sdl2Events.ProcessEvents();
                snapshot = _window.PumpEvents();
                InputTracker.UpdateFrameInput(snapshot, _window);
                Update((float)deltaSeconds);
                if (!_window.Exists)
                {
                    break;
                }

                Draw();
            }

            DestroyAllObjects();
            _gd.Dispose();
        }
Пример #10
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true
            };

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, options, GraphicsBackend.Metal);

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();

                if (window.Exists)
                {
                    Draw();
                }
            }

            DisposeResources();
        }
Пример #11
0
        public void RunGameLoop()
        {
            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)
                    {
                        _renderer.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);
                        HandleWindowResize();
                    }

                    ProcessInput();
                    Draw(deltaSeconds);
                }
            }

            _renderer.Dispose();
        }
Пример #12
0
        public void Tick()
        {
            if (!_window.Exists)
            {
                _runner.Shutdown();
                return;
            }

            _cl.Begin();

            _cl.SetFramebuffer(MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);
            _cl.SetPipeline(_pipeline);

            LastInput = _window.PumpEvents();
            if (_windowResized)
            {
                _windowResized = false;
                _gd.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);
            }

            Render?.Invoke(_gd, _cl);

            _cl.End();
            GraphicsDevice.SubmitCommands(_cl);
            GraphicsDevice.SwapBuffers(MainSwapchain);
            GraphicsDevice.WaitForIdle();
        }
Пример #13
0
    public void PumpEvents(double deltaSeconds)
    {
        SetTitle();
        Sdl2Events.ProcessEvents();
        var snapshot = _window.PumpEvents();

        if (_window != null)
        {
            if (_pendingCursorUpdate.HasValue && _window.Focused)
            {
                using (PerfTracker.FrameEvent("3 Warping mouse"))
                {
                    Sdl2Native.SDL_WarpMouseInWindow(
                        _window.SdlWindowHandle,
                        (int)_pendingCursorUpdate.Value.X,
                        (int)_pendingCursorUpdate.Value.Y);

                    _pendingCursorUpdate = null;
                }
            }

            using (PerfTracker.FrameEvent("4 Raising input event"))
                Raise(new InputEvent(deltaSeconds, snapshot, _window.MouseDelta));
        }
    }
Пример #14
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();

                if (window.Exists)
                {
                    Draw();
                }
            }

            DisposeResources();
        }
Пример #15
0
        static void Main(string[] args)
        {
            //var sonic06File = new Sonic06XnoReader("C:/Users/playmer/AppData/Local/Hyper_Development_Team/Sonic '06 Toolkit/Archives/68236/0tiors2s.003/enemy/win32/enemy/eBomber/en_eBomber.xno");

            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            var renderer = new Renderer(window);

            renderer.CreateResources();

            while (window.Exists)
            {
                var snapShot = window.PumpEvents();
                renderer.mImguiRenderer.Update(1f / 60f, snapShot); // [2]

                if (window.Exists)
                {
                    renderer.Transform();
                    renderer.Draw();
                }
            }
        }
Пример #16
0
        public static void Main()
        {
            uiManager = new UiManager();

            window = VeldridStartup.CreateWindow(new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, $"ImageSharp.Textures.InteractiveTest"));
            ApplicationManager.GraphicsDevice = VeldridStartup.CreateGraphicsDevice(window, GraphicsBackend.OpenGL);

            window.Resized += Window_Resized;

            ApplicationManager.CommandList = ApplicationManager.GraphicsDevice.ResourceFactory.CreateCommandList();
            ApplicationManager.Controller  = new ImGuiRenderer(ApplicationManager.GraphicsDevice, ApplicationManager.GraphicsDevice.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height);

            ImGui.StyleColorsDark();

            // Main application loop
            while (window.Exists)
            {
                InputSnapshot snapshot = window.PumpEvents();
                if (!window.Exists)
                {
                    break;
                }

                DateTime curUpdateTime = DateTime.Now;
                if (prevUpdateTime.Ticks == 0)
                {
                    prevUpdateTime = curUpdateTime;
                }
                float dt = (float)(curUpdateTime - prevUpdateTime).TotalSeconds;
                if (dt <= 0)
                {
                    dt = float.Epsilon;
                }
                prevUpdateTime = curUpdateTime;

                ApplicationManager.Controller.Update(dt, snapshot);

                SubmitUi();

                ApplicationManager.CommandList.Begin();
                ApplicationManager.CommandList.SetFramebuffer(ApplicationManager.GraphicsDevice.MainSwapchain.Framebuffer);
                ApplicationManager.CommandList.ClearColorTarget(0, new RgbaFloat(0.5f, 0.5f, 0.5f, 1f));
                try
                {
                    ApplicationManager.Controller.Render(ApplicationManager.GraphicsDevice, ApplicationManager.CommandList);
                }
                catch (Exception)
                {
                    // do nothing
                }
                ApplicationManager.CommandList.End();
                ApplicationManager.GraphicsDevice.SubmitCommands(ApplicationManager.CommandList);
                ApplicationManager.GraphicsDevice.SwapBuffers(ApplicationManager.GraphicsDevice.MainSwapchain);
            }

            ApplicationManager.GraphicsDevice.WaitForIdle();
            ApplicationManager.Controller.Dispose();
            ApplicationManager.CommandList.Dispose();
            ApplicationManager.GraphicsDevice.Dispose();
        }
Пример #17
0
        public void Run()
        {
            m_factory = new DisposeCollectorResourceFactory(m_gd.ResourceFactory);
            GraphicsDeviceCreated?.Invoke(m_gd, m_factory, m_gd.MainSwapchain);

            Stopwatch sw = Stopwatch.StartNew();
            double    previousElapsed = sw.Elapsed.TotalSeconds;

            while (m_window.Exists)
            {
                double newElapsed   = sw.Elapsed.TotalSeconds;
                float  deltaSeconds = (float)(newElapsed - previousElapsed);

                InputSnapshot inputSnapshot = m_window.PumpEvents();
                InputTracker.UpdateFrameInput(inputSnapshot);

                if (m_window.Exists)
                {
                    previousElapsed = newElapsed;
                    if (m_windowResized)
                    {
                        m_windowResized = false;
                        m_gd.ResizeMainWindow((uint)m_window.Width, (uint)m_window.Height);
                        Resized?.Invoke();
                    }

                    Rendering?.Invoke(deltaSeconds);
                }
            }

            m_gd.WaitForIdle();
            m_factory.DisposeCollector.DisposeAll();
            m_gd.Dispose();
            GraphicsDeviceDestroyed?.Invoke();
        }
Пример #18
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (!_window.Exists)
            {
                Exit();
                return;
            }

            var inputSnapshot = _window.PumpEvents();

            ProcessInput(InputSnapshotConverter.Mouse(inputSnapshot, MouseState),
                         InputSnapshotConverter.Keyboard(inputSnapshot));

            if (KeyboardState.IsKeyDown(Key.Escape))
            {
                Exit();
            }

            base.Update(gameTime);

            if (DebugMode)
            {
                var frameTime = Math.Round(gameTime.ElapsedGameTime.TotalMilliseconds, 1);
                _window.Title = $"Utility Grid - {frameTime} ms - {FramesPerSecond} fps";
            }
        }
Пример #19
0
        private void Update(float deltaSeconds)
        {
            if (!_window.Exists)
            {
                return;
            }

            if (_resized)
            {
                _resized = false;

                WindowOnResized();
            }

            var input = _window.PumpEvents();

            ImGuiRenderer.Update(deltaSeconds, input);

            _commandList.Begin();
            _commandList.SetFramebuffer(_framebuffer);
            _commandList.ClearColorTarget(0, RgbaFloat.Black);

            Draw?.Invoke();

            ImGuiRenderer.Render(_graphicsDevice, _commandList);

            _commandList.End();

            _graphicsDevice.SubmitCommands(_commandList);
            _graphicsDevice.SwapBuffers();
        }
Пример #20
0
        public static void Render(this Sdl2Window window, GraphicsDevice device, params Action <GraphicsDevice, CommandList, long>[] renderFuncs)
        {
            var  stopwatch       = new Stopwatch();
            long elapsedTime     = 0;
            long lastUpdateTime  = stopwatch.ElapsedMilliseconds;
            long gameTime        = 0;
            var  commandListPool = new Pool <CommandList>(generator: () => device.ResourceFactory.CreateCommandList());

            while (window.Exists)
            {
                window.PumpEvents();
                gameTime    = stopwatch.ElapsedMilliseconds;
                elapsedTime = lastUpdateTime - gameTime;

                using (var clDisposable = commandListPool.Take())
                    foreach (var renderFunc in renderFuncs)
                    {
                        renderFunc(device, clDisposable.Value, elapsedTime);
                    }

                device.SwapBuffers();

                lastUpdateTime = gameTime;
            }
        }
Пример #21
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowHeight = 540,
                WindowWidth  = 960,
                WindowTitle  = "Hello World"
            };

            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);

            _shaderResourceManager = new ShaderResourceManager(_graphicsDevice);

            CreateResources();

            _stopWatch = Stopwatch.StartNew();

            while (window.Exists)
            {
                window.PumpEvents();
                Draw();
                Console.WriteLine($"{_stopWatch.ElapsedMilliseconds / 1000}s");
            }
            _stopWatch.Stop();

            DisposeResources();
        }
Пример #22
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();
            }
        }
Пример #23
0
        public void MainLoop()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            while (!_quit)
            {
                _currentFrameTime = stopwatch.ElapsedTicks;
                DeltaTime         = (float)(_currentFrameTime - _previousFrameTime) / Stopwatch.Frequency;

                var snapshot = _window.PumpEvents();
                Input.Update(snapshot, _window);
                //TODO: Handle resize events
                //TODO: Handle quit events

                Scene?.Update();
                Scene?.PreDraw();
                Renderer.Draw();
                Scene?.LateUpdate();

                _previousFrameTime = _currentFrameTime;

                // Framerate limiter
                while (MaxFps != -1 && stopwatch.ElapsedTicks - _currentFrameTime < Stopwatch.Frequency / MaxFps)
                {
                }
            }

            Scene?.Destroy();
            Renderer.Exit();
        }
Пример #24
0
        public void Run()
        {
            _factory = new DisposeCollectorResourceFactory(_gd.ResourceFactory);
            CreateResources(_factory);

            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)
                    {
                        _gd.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);
                        HandleWindowResize();
                    }

                    Draw(deltaSeconds);
                }
            }

            _gd.WaitForIdle();
            _factory.DisposeCollector.DisposeAll();
            _gd.Dispose();
        }
Пример #25
0
        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();
        }
Пример #26
0
        public void Run()
        {
            SetupCSharpDefaults();
            SetupParamStudioConfig();
            //new StudioServer();
            long      previousFrameTicks = 0;
            Stopwatch sw = new Stopwatch();

            sw.Start();
            while (_window.Exists)
            {
                bool focused = _window.Focused;
                if (!focused)
                {
                    _desiredFrameLengthSeconds = 1.0 / 20.0f;
                }
                else
                {
                    _desiredFrameLengthSeconds = 1.0 / 60.0f;
                }
                long   currentFrameTicks = sw.ElapsedTicks;
                double deltaSeconds      = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency;

                while (_limitFrameRate && deltaSeconds < _desiredFrameLengthSeconds)
                {
                    currentFrameTicks = sw.ElapsedTicks;
                    deltaSeconds      = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency;
                    System.Threading.Thread.Sleep(focused ? 0 : 1);
                }

                previousFrameTicks = currentFrameTicks;

                InputSnapshot snapshot = null;
                Sdl2Events.ProcessEvents();
                snapshot = _window.PumpEvents();
                InputTracker.UpdateFrameInput(snapshot, _window);
                Update((float)deltaSeconds);
                if (!_window.Exists)
                {
                    break;
                }

                if (_window.Focused)
                {
                    Draw();
                }
                else
                {
                    // Flush the background queues
                    Renderer.Frame(null, true);
                }
            }

            //DestroyAllObjects();
            _gd.Dispose();
            SaveParamStudioConfig();
            CFG.Save();
            System.Windows.Forms.Application.Exit();
        }
        public static void Main()
        {
            Sdl2Window window = WindowingSystem.CreateNewWindow("Veldrid test", width: 500, height: 500);

            GraphicsDeviceOptions gdOptions = new GraphicsDeviceOptions(false,
                                                                        null,
                                                                        false,
                                                                        ResourceBindingModel.Improved,
                                                                        true,
                                                                        true,
                                                                        true);

            var graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, gdOptions);

            ImGuiRenderer imguiRenderer = new ImGuiRenderer(
                graphicsDevice, graphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
                (int)graphicsDevice.MainSwapchain.Framebuffer.Width, (int)graphicsDevice.MainSwapchain.Framebuffer.Height);

            var cl = graphicsDevice.ResourceFactory.CreateCommandList();

            window.Resized += () => imguiRenderer.WindowResized(window.Width, window.Height);
            window.Resized += () => graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);

            ImGui.StyleColorsClassic();

            int       optimalFrameTimeMS = 16;
            bool      showMore           = false;
            Stopwatch stopwatch          = new Stopwatch();

            stopwatch.Start();
            while (window.Exists)
            {
                Thread.Sleep(optimalFrameTimeMS);

                var input = window.PumpEvents();
                if (!window.Exists)
                {
                    break;
                }
                imguiRenderer.Update((float)stopwatch.Elapsed.TotalSeconds, input);                 // Compute actual value for deltaSeconds.

                // Draw stuff
                ImGui.Begin("Hierarchy");
                {
                } ImGui.End();

                cl.Begin();
                cl.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
                cl.ClearColorTarget(0, RgbaFloat.Black);
                imguiRenderer.Render(graphicsDevice, cl);
                cl.End();
                graphicsDevice.SubmitCommands(cl);
                graphicsDevice.SwapBuffers(graphicsDevice.MainSwapchain);

                stopwatch.Restart();
            }
        }
Пример #28
0
        private void Update(float deltaTime)
        {
            InputSnapshot inputSnapshot = window.PumpEvents();

            runtimeData.Update(window, inputSnapshot, deltaTime);

            imGuiRenderer.Update(deltaTime, inputSnapshot);
            SubmitImGui(deltaTime, inputSnapshot);
        }
Пример #29
0
 public void Run()
 {
     while (_window.Exists)
     {
         InputTracker.UpdateFrameInput(_window.PumpEvents());
         Update(1f / 60f);
         Draw();
     }
 }
Пример #30
0
        public void Run()
        {
            var options = new GraphicsDeviceOptions(
                false,
                PixelFormat.R16_UNorm,
                true,
                ResourceBindingModel.Improved,
                true,
                true);

#if DEBUG
            options.Debug = true;
#endif
            GraphicsDevice gd;
            if (_options.GraphicsBackend.HasValue)
            {
                gd = VeldridStartup.CreateGraphicsDevice(_window, options, _options.GraphicsBackend.Value);
            }
            else
            {
                gd = VeldridStartup.CreateGraphicsDevice(_window, options);
            }
            var factory = new DisposeCollectorResourceFactory(gd.ResourceFactory);

            _veldrid = new VeldridContext(gd, factory, gd.MainSwapchain);
            GraphicsDeviceCreated?.Invoke(_veldrid);

            var sw = Stopwatch.StartNew();
            var previousElapsed = sw.Elapsed.TotalSeconds;

            while (_window.Exists)
            {
                var newElapsed   = sw.Elapsed.TotalSeconds;
                var deltaSeconds = (float)(newElapsed - previousElapsed);

                var inputSnapshot = _window.PumpEvents();

                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();
        }