Example #1
0
        public DeveloperModeView(Game game)
        {
            _game = game;

            var window = game.Window;

            _imGuiRenderer = AddDisposable(new ImGuiRenderer(
                                               window.GraphicsDevice,
                                               window.GraphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
                                               window.ClientBounds.Width,
                                               window.ClientBounds.Height));

            void OnWindowSizeChanged(object sender, EventArgs e)
            {
                _imGuiRenderer.WindowResized(window.ClientBounds.Width, window.ClientBounds.Height);
            }

            window.ClientSizeChanged += OnWindowSizeChanged;

            AddDisposeAction(() => window.ClientSizeChanged -= OnWindowSizeChanged);

            _commandList = AddDisposable(window.GraphicsDevice.ResourceFactory.CreateCommandList());

            _mainView = AddDisposable(new MainView(new DiagnosticViewContext(game, _imGuiRenderer)));
            ImGuiUtility.SetupDocking();
        }
Example #2
0
 /// <summary>
 /// 窗口发生变化时停止给场景的Camera对象
 /// </summary>
 protected virtual void HandleWindowResize()
 {
     _scene.Camera.WindowResized(Window.Width, Window.Height);
     _controller.WindowResized((int)Window.Width, (int)Window.Height);
     //调整UI界面的大小
     _browHost.ResizeWindow(Window.Width, Window.Height);
 }
Example #3
0
        public MainScreen()
        {
            var windowCreateInfo = new WindowCreateInfo
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 800,
                WindowHeight       = 600,
                WindowInitialState = WindowState.Maximized,
                WindowTitle        = "OpenShadows - Workbench"
            };

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

            VeldridStartup.CreateWindowAndGraphicsDevice(windowCreateInfo, graphicsDeviceOptions, GraphicsBackend.Direct3D11, out Window, out Gd);

            Cl = Gd.ResourceFactory.CreateCommandList();

            ImGuiRenderer = new ImGuiRenderer(Gd, Gd.MainSwapchain.Framebuffer.OutputDescription, 800, 600, ColorSpaceHandling.Linear);
            ImGuiHelper.DeactivateIniFile();
            ImGui.StyleColorsLight();

            Window.Resized += () =>
            {
                Gd.MainSwapchain.Resize((uint)Window.Width, (uint)Window.Height);
                ImGuiRenderer.WindowResized(Window.Width, Window.Height);
            };

            Screens.Add(new AlfBrowserScreen());
            Screens.Add(new LevelBrowserScreen());
        }
Example #4
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();
        }
Example #5
0
 public DebugGuiRenderer(IFramebufferHolder framebuffer)
 {
     _framebuffer = framebuffer;
     On <InputEvent>(e => _imguiRenderer?.Update((float)e.DeltaSeconds, e.Snapshot));
     On <WindowResizedEvent>(e => _imguiRenderer?.WindowResized(e.Width, e.Height));
     On <DeviceCreatedEvent>(_ => Dirty());
     On <DestroyDeviceObjectsEvent>(_ => Dispose());
 }
        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();
            }
        }
Example #7
0
        private VxContext(GraphicsDevice gd, Sdl2Window window)
        {
            Device  = gd;
            Window  = window;
            Factory = new DisposeCollectorResourceFactory(gd.ResourceFactory);
            _cl     = Factory.CreateCommandList();

            Window.Resized += () =>
            {
                Device.MainSwapchain.Resize((uint)Window.Width, (uint)Window.Height);
                _imguiRenderer.WindowResized(Window.Width, Window.Height);
            };

            ShaderSetDescription meshShaderSet = new ShaderSetDescription(
                new[]
            {
                new VertexLayoutDescription(
                    new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float3),
                    new VertexElementDescription("Normal", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float3))
            },
                ShaderHelpers.LoadSet(Device, Factory, "Model"));

            ResourceLayout viewProjLayout = Factory.CreateResourceLayout(new ResourceLayoutDescription(
                                                                             new ResourceLayoutElementDescription("ViewProjection", ResourceKind.UniformBuffer, ShaderStages.Vertex),
                                                                             new ResourceLayoutElementDescription("SceneInfo", ResourceKind.UniformBuffer, ShaderStages.Fragment)));
            ResourceLayout worldLayout = Factory.CreateResourceLayout(new ResourceLayoutDescription(
                                                                          new ResourceLayoutElementDescription("World", ResourceKind.UniformBuffer, ShaderStages.Vertex)));
            ResourceLayout modelParamsLayout = Factory.CreateResourceLayout(new ResourceLayoutDescription(
                                                                                new ResourceLayoutElementDescription("ModelParams", ResourceKind.UniformBuffer, ShaderStages.Fragment)));

            GraphicsPipelineDescription meshPipelineDescription = new GraphicsPipelineDescription(
                BlendStateDescription.SingleOverrideBlend,
                DepthStencilStateDescription.DepthOnlyGreaterEqual,
                RasterizerStateDescription.Default,
                PrimitiveTopology.TriangleList,
                meshShaderSet,
                new[] { viewProjLayout, worldLayout, modelParamsLayout },
                Device.MainSwapchain.Framebuffer.OutputDescription);

            _modelPipeline = Factory.CreateGraphicsPipeline(meshPipelineDescription);

            _viewProjectionBuffer = Factory.CreateBufferFor <Matrix4x4>(BufferUsage.Dynamic | BufferUsage.UniformBuffer);
            _sceneInfoBuffer      = Factory.CreateBufferFor <SceneInfo>(BufferUsage.Dynamic | BufferUsage.UniformBuffer);
            _viewProjectionSet    = Factory.CreateResourceSet(new ResourceSetDescription(viewProjLayout, _viewProjectionBuffer, _sceneInfoBuffer));

            _worldBuffer = Factory.CreateBuffer(new BufferDescription(128, BufferUsage.Dynamic | BufferUsage.UniformBuffer));
            _worldSet    = Factory.CreateResourceSet(new ResourceSetDescription(worldLayout, _worldBuffer));

            _modelParamsBuffer = Factory.CreateBufferFor <Vector4>(BufferUsage.Dynamic | BufferUsage.UniformBuffer);
            _modelParamsSet    = Factory.CreateResourceSet(new ResourceSetDescription(modelParamsLayout, _modelParamsBuffer));

            _imguiRenderer = new ImGuiRenderer(Device, Device.MainSwapchain.Framebuffer.OutputDescription, Window.Width, Window.Height);

            _sw = Stopwatch.StartNew();
        }
Example #8
0
 protected override void OnInitialize()
 {
     commandList = GraphicsDevice.ResourceFactory.CreateCommandList();
     CommandLists.Add(commandList);
     imGuiRenderer = new ImGuiRenderer(
         GraphicsDevice,
         GraphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
         WIDTH,
         HEIGHT
         );
     Window.Resized += () => imGuiRenderer.WindowResized(Window.Width, Window.Height);
 }
Example #9
0
        static void Resize()
        {
            Logic.State.screen_size = ScreenSize;
            imGuiRenderer.WindowResized(window.Width, window.Height);
            device.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);
            Texture newTarget = MakeTexture(Round(window.Width, Logic.GroupSize), Round(window.Height, Logic.GroupSize));

            compute["result"]   = newTarget;
            renderer["texture"] = newTarget;
            compute.Update(factory);
            renderer.Update(factory);
        }
Example #10
0
        public void Draw()
        {
            double newElapsed   = mClock.Elapsed.TotalSeconds;
            float  deltaSeconds = (float)(newElapsed - mPreviousElapsed);

            mCommandList.Begin();

            mCommandList.UpdateBuffer(mProjectionBuffer, 0, Matrix4x4.CreatePerspectiveFieldOfView(
                                          1.0f,
                                          (float)mWindow.Width / mWindow.Height,
                                          0.5f,
                                          100f));

            mCommandList.UpdateBuffer(mViewBuffer, 0, Matrix4x4.CreateLookAt(Vector3.UnitZ * 2.5f, Vector3.Zero, Vector3.UnitY));

            Matrix4x4 rotation = Matrix4x4.CreateScale(mScale)
                                 * Matrix4x4.CreateFromAxisAngle(Vector3.UnitZ, mRotation.Z)
                                 * Matrix4x4.CreateFromAxisAngle(Vector3.UnitY, mRotation.Y)
                                 * Matrix4x4.CreateFromAxisAngle(Vector3.UnitX, mRotation.X)
                                 * Matrix4x4.CreateTranslation(mTranslation);

            mCommandList.UpdateBuffer(mWorldBuffer, 0, ref rotation);

            mCommandList.SetFramebuffer(mSwapchain.Framebuffer);
            mCommandList.ClearColorTarget(0, RgbaFloat.Black);
            mCommandList.ClearDepthStencil(1f);
            mCommandList.SetPipeline(mPipeline);
            mCommandList.SetVertexBuffer(0, mVertexBuffer);
            mCommandList.SetIndexBuffer(mIndexBuffer, IndexFormat.UInt16);
            mCommandList.SetGraphicsResourceSet(0, mProjViewSet);
            mCommandList.SetGraphicsResourceSet(1, mWorldTextureSet);
            mCommandList.DrawIndexed(36, 1, 0, 0, 0);

            mImguiRenderer.Render(mGraphicsDevice, mCommandList); // [3]
            mCommandList.End();
            mGraphicsDevice.SubmitCommands(mCommandList);
            mGraphicsDevice.SwapBuffers(mSwapchain);
            mGraphicsDevice.WaitForIdle();

            if (mWindowResized)
            {
                mWindowResized = false;
                mGraphicsDevice.ResizeMainWindow((uint)mWindow.Width, (uint)mWindow.Height);
                mImguiRenderer.WindowResized(mWindow.Width, mWindow.Height);
            }
        }
Example #11
0
        public DeveloperModeView(Game game, GameWindow window)
        {
            _game   = game;
            _window = window;

            _imGuiRenderer = AddDisposable(new ImGuiRenderer(
                                               game.GraphicsDevice,
                                               game.GraphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
                                               window.ClientBounds.Width,
                                               window.ClientBounds.Height));

            void OnWindowSizeChanged(object sender, EventArgs e)
            {
                _imGuiRenderer.WindowResized(window.ClientBounds.Width, window.ClientBounds.Height);
            }

            window.ClientSizeChanged += OnWindowSizeChanged;

            AddDisposeAction(() => window.ClientSizeChanged -= OnWindowSizeChanged);

            var inputMessageHandler = new CallbackMessageHandler(
                HandlingPriority.Window,
                message =>
            {
                if (_isGameViewFocused && message.MessageType == InputMessageType.KeyDown && message.Value.Key == Key.Escape)
                {
                    _isGameViewFocused = false;
                    return(InputMessageResult.Handled);
                }

                return(InputMessageResult.NotHandled);
            });

            game.InputMessageBuffer.Handlers.Add(inputMessageHandler);

            AddDisposeAction(() => game.InputMessageBuffer.Handlers.Remove(inputMessageHandler));

            _commandList = AddDisposable(game.GraphicsDevice.ResourceFactory.CreateCommandList());

            ImGuiUtility.SetupDocking();

            _mainView = AddDisposable(new MainView(new DiagnosticViewContext(game, window, _imGuiRenderer)));
        }
Example #12
0
        public GuiVisual()
        {
            var window = IoC.Resolve <Sdl2Window>();

            graphicsDevice = IoC.Resolve <GraphicsDevice>();
            imGuiRenderer  = new ImGuiRenderer(graphicsDevice, graphicsDevice.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height);
            var style = ImGui.GetStyle();

            style.FrameBorderSize  = 1f;
            style.WindowBorderSize = 3f;

            var io = ImGui.GetIO();

            io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard;
            io.ConfigWindowsResizeFromEdges = true;

            var fonts = io.Fonts;

            //fonts.ClearFonts();
            //var config = new ImFontConfig
            //{
            //	OversampleH = 2,
            //	OversampleV = 2,
            //};
            //IntPtr unmanagedAddr = Marshal.AllocHGlobal(Marshal.SizeOf(config));
            //Marshal.StructureToPtr(config, unmanagedAddr, true);

            font = fonts.AddFontFromFileTTF("Content/DroidSans.ttf", 32);
            //font.ConfigDataCount = 1;
            //var i = font.ConfigDataCount;
            //font = fonts.AddFontFromFileTTF(@"D:\arial.ttf", 26, new ImFontConfigPtr(unmanagedAddr));
            //io.FontDefault = font;
            imGuiRenderer.RecreateFontDeviceTexture();

            window.Resized += () =>
            {
                imGuiRenderer.WindowResized(window.Width, window.Height);
            };
        }
Example #13
0
        public void Init(string name, int width, int height)
        {
            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, width, height, WindowState.Normal, name),
                out _window,
                out _gd);

            _cl = _gd.ResourceFactory.CreateCommandList();

            _ren = new ImGuiRenderer(
                _gd,
                _gd.MainSwapchain.Framebuffer.OutputDescription,
                _window.Width,
                _window.Height);

            _window.Resized += () =>
            {
                _ren.WindowResized(_window.Width, _window.Height);
                _gd.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height);
            };

            Preload();

            while (_window.Exists)
            {
                var snapshot = _window.PumpEvents();
                _ren.Update(1f / 60f, snapshot);

                SubmitUI();

                _cl.Begin();
                _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
                _cl.ClearColorTarget(0, new RgbaFloat(0, 0, 0.2f, 1f));
                _ren.Render(_gd, _cl);
                _cl.End();
                _gd.SubmitCommands(_cl);
                _gd.SwapBuffers(_gd.MainSwapchain);
            }
        }
Example #14
0
        /// <summary>
        /// Creates a new ImGUI Render Layer
        /// </summary>
        /// <param name="graphicsDevice">The graphics device ImGUI will draw with</param>
        public ImGUILayer(GraphicsDevice graphicsDevice) : base()
        {
            Graphics = graphicsDevice;

            // Create an ImGUI renderer
            ImGuiRenderer = new ImGuiRenderer(
                graphicsDevice.veldridGraphicsDevice,
                graphicsDevice.veldridGraphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
                VesselEngine.Instance.Window.Width,
                VesselEngine.Instance.Window.Height);

            // Viewport support veldrid pls 🙏
            io              = ImGui.GetIO();
            io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable;

            // Resizing callbacks
            VesselEngine.Instance.Window.Resized += () =>
            {
                ImGuiRenderer.WindowResized(
                    VesselEngine.Instance.Window.Width,
                    VesselEngine.Instance.Window.Height);
            };
        }
Example #15
0
 private void _window_Resized()
 {
     _viewport.WindowChanged(_window.Width, _window.Height);
     _imGuiRenderer.WindowResized(_window.Width, _window.Height);
 }
Example #16
0
        public Task Start(WindowCreateInfo wci, GraphicsDeviceOptions graphicsDeviceOptions)
        {
            //return Task.Factory.StartNew(() =>
            //{
            AddRenderer(new Renderer()
            {
                RenderWireframes = false
            });

            _window = VeldridStartup.CreateWindow(ref wci);
            //Window.CursorVisible = false;
            //Window.SetMousePosition(Window.Width / 2, Window.Height / 2);
            _window.Resized += () => _windowResized = true;
            _graphicsDevice  = VeldridStartup.CreateGraphicsDevice(_window, graphicsDeviceOptions);
            _commandList     = _graphicsDevice.ResourceFactory.CreateCommandList();
            _renderers.ForEach(r => r.Initialize(_graphicsDevice, _commandList, _window.Width, _window.Height));
            var imGuiRenderer = new ImGuiRenderer(_graphicsDevice, _graphicsDevice.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height);

            Started?.Invoke();
            var frameWatch      = Stopwatch.StartNew();
            var targetFrameTime = 0.13f;

            while (_window.Exists)
            {
                var inputSnapshot = _window.PumpEvents();

                if (!_window.Exists)
                {
                    break;
                }

                InputTracker.UpdateFrameInput(_window, inputSnapshot);

                if (InputTracker.WasKeyDowned(Key.Escape))
                {
                    break;
                }
                if (InputTracker.WasKeyDowned(Key.Tilde))
                {
                    InputTracker.LockMouse = !InputTracker.LockMouse;
                }
                if (InputTracker.WasKeyDowned(Key.T))
                {
                    StackedTiming.Enabled = !StackedTiming.Enabled; Timing.Enabled = !Timing.Enabled;
                }

                if (_windowResized)
                {
                    _windowResized = false;
                    _graphicsDevice.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);
                    _renderers.ForEach(r => r.WindowResized(_window.Width, _window.Height));
                    imGuiRenderer.WindowResized(_window.Width, _window.Height);
                }

                var frameTime = (float)frameWatch.Elapsed.TotalSeconds;
                frameWatch.Restart();

                imGuiRenderer.Update(frameTime, InputTracker.LockMouse ? new EmptyInputSnapshot() : InputTracker.FrameSnapshot);

                Tick?.Invoke();
                if (NextScene != null)
                {
                    if (CurrentScene != null)
                    {
                        CurrentScene.SceneStopped();
                    }
                    CurrentScene = NextScene;
                    NextScene    = null;
                    CurrentScene.SceneStarted(this);
                }
                if (CurrentScene != null)
                {
                    StackedTiming.PushFrameTimer("Scene Update");
                    CurrentScene.Update(frameTime);
                    StackedTiming.PopFrameTimer();
                }

                _commandList.Begin();

                _commandList.SetFramebuffer(_graphicsDevice.MainSwapchain.Framebuffer);
                //commandList.ClearColorTarget(0, new RgbaFloat(25f / 255, 25f / 255, 112f / 255, 1.0f));
                _commandList.ClearColorTarget(0, RgbaFloat.CornflowerBlue);
                _commandList.ClearDepthStencil(1f);

                StackedTiming.PushFrameTimer("Render");
                if (Camera != null)
                {
                    _renderers.ForEach(r => r.Render(Camera, _graphicsDevice, _commandList, RenderWireframes.SOLID));
                }
                StackedTiming.PopFrameTimer();

                StackedTiming.Render(frameTime);
                Timing.Render(frameTime);

                imGuiRenderer.Render(_graphicsDevice, _commandList);

                _commandList.End();
                _graphicsDevice.SubmitCommands(_commandList);
                _graphicsDevice.SwapBuffers(_graphicsDevice.MainSwapchain);
                _graphicsDevice.WaitForIdle();

                bool jobsRemain = true;
                while (jobsRemain && frameWatch.Elapsed.TotalSeconds < targetFrameTime)
                {
                    jobsRemain = BestEffortFrameQueue.ConsumeActions(1);
                }
            }
            //}, TaskCreationOptions.LongRunning);
            return(Task.CompletedTask);
        }
Example #17
0
        static void Main(string[] args)
        {
            _useOculus = true;
            if (!VRContext.IsOculusSupported())
            {
                _useOculus = false;
                if (!VRContext.IsOpenVRSupported())
                {
                    Console.WriteLine("This sample requires an Oculus or OpenVR-capable headset.");
                    return;
                }
            }

            Sdl2Window window = VeldridStartup.CreateWindow(
                new WindowCreateInfo(
                    Sdl2Native.SDL_WINDOWPOS_CENTERED, Sdl2Native.SDL_WINDOWPOS_CENTERED,
                    1280, 720,
                    WindowState.Normal,
                    "Veldrid.VirtualReality Sample"));

            VRContextOptions options = new VRContextOptions
            {
                EyeFramebufferSampleCount = TextureSampleCount.Count4
            };
            VRContext vrContext = _useOculus ? VRContext.CreateOculus(options) : VRContext.CreateOpenVR(options);

            GraphicsBackend backend = GraphicsBackend.Direct3D11;

            bool debug = false;

#if DEBUG
            debug = true;
#endif

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

            if (backend == GraphicsBackend.Vulkan)
            {
                // Oculus runtime causes validation errors.
                gdo.Debug = false;
            }

            (GraphicsDevice gd, Swapchain sc) = CreateDeviceAndSwapchain(window, vrContext, backend, gdo);
            window.Resized += () => sc.Resize((uint)window.Width, (uint)window.Height);

            vrContext.Initialize(gd);

            ImGuiRenderer igr = new ImGuiRenderer(gd, sc.Framebuffer.OutputDescription, window.Width, window.Height, ColorSpaceHandling.Linear);
            window.Resized += () => igr.WindowResized(window.Width, window.Height);

            AssimpMesh mesh = new AssimpMesh(
                gd,
                vrContext.LeftEyeFramebuffer.OutputDescription,
                Path.Combine(AppContext.BaseDirectory, "cat", "cat.obj"),
                Path.Combine(AppContext.BaseDirectory, "cat", "cat_diff.png"));

            Skybox skybox = new Skybox(
                Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, "skybox", "miramar_ft.png")),
                Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, "skybox", "miramar_bk.png")),
                Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, "skybox", "miramar_lf.png")),
                Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, "skybox", "miramar_rt.png")),
                Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, "skybox", "miramar_up.png")),
                Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, "skybox", "miramar_dn.png")));
            skybox.CreateDeviceObjects(gd, vrContext.LeftEyeFramebuffer.OutputDescription);

            CommandList windowCL = gd.ResourceFactory.CreateCommandList();
            CommandList eyesCL   = gd.ResourceFactory.CreateCommandList();

            MirrorTextureEyeSource eyeSource = MirrorTextureEyeSource.BothEyes;

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

            while (window.Exists)
            {
                double newFrameTime = sw.Elapsed.TotalSeconds;
                double deltaSeconds = newFrameTime - lastFrameTime;
                lastFrameTime = newFrameTime;

                InputSnapshot snapshot = window.PumpEvents();
                if (!window.Exists)
                {
                    break;
                }
                InputTracker.UpdateFrameInput(snapshot, window);
                HandleInputs(deltaSeconds);

                igr.Update(1f / 60f, snapshot);

                if (ImGui.BeginMainMenuBar())
                {
                    if (ImGui.BeginMenu("Settings"))
                    {
                        if (ImGui.BeginMenu("Mirror Texture"))
                        {
                            if (ImGui.MenuItem("Both Eyes", null, eyeSource == MirrorTextureEyeSource.BothEyes))
                            {
                                eyeSource = MirrorTextureEyeSource.BothEyes;
                            }
                            if (ImGui.MenuItem("Left Eye", null, eyeSource == MirrorTextureEyeSource.LeftEye))
                            {
                                eyeSource = MirrorTextureEyeSource.LeftEye;
                            }
                            if (ImGui.MenuItem("Right Eye", null, eyeSource == MirrorTextureEyeSource.RightEye))
                            {
                                eyeSource = MirrorTextureEyeSource.RightEye;
                            }

                            ImGui.EndMenu();
                        }

                        if (ImGui.BeginMenu("VR API"))
                        {
                            if (ImGui.MenuItem("Oculus", null, _useOculus) && !_useOculus)
                            {
                                _useOculus       = true;
                                _switchVRContext = true;
                            }
                            if (ImGui.MenuItem("OpenVR", null, !_useOculus) && _useOculus)
                            {
                                _useOculus       = false;
                                _switchVRContext = true;
                            }

                            ImGui.EndMenu();
                        }

                        ImGui.EndMenu();
                    }

                    ImGui.EndMainMenuBar();
                }

                windowCL.Begin();
                windowCL.SetFramebuffer(sc.Framebuffer);
                windowCL.ClearColorTarget(0, new RgbaFloat(0f, 0f, 0.2f, 1f));
                vrContext.RenderMirrorTexture(windowCL, sc.Framebuffer, eyeSource);
                igr.Render(gd, windowCL);
                windowCL.End();
                gd.SubmitCommands(windowCL);
                gd.SwapBuffers(sc);

                HmdPoseState poses = vrContext.WaitForPoses();

                // Render Eyes
                eyesCL.Begin();

                eyesCL.PushDebugGroup("Left Eye");
                Matrix4x4 leftView = poses.CreateView(VREye.Left, _userPosition, -Vector3.UnitZ, Vector3.UnitY);
                RenderEye(eyesCL, vrContext.LeftEyeFramebuffer, mesh, skybox, poses.LeftEyeProjection, leftView);
                eyesCL.PopDebugGroup();

                eyesCL.PushDebugGroup("Right Eye");
                Matrix4x4 rightView = poses.CreateView(VREye.Right, _userPosition, -Vector3.UnitZ, Vector3.UnitY);
                RenderEye(eyesCL, vrContext.RightEyeFramebuffer, mesh, skybox, poses.RightEyeProjection, rightView);
                eyesCL.PopDebugGroup();

                eyesCL.End();
                gd.SubmitCommands(eyesCL);

                vrContext.SubmitFrame();

                if (_switchVRContext)
                {
                    _switchVRContext = false;
                    vrContext.Dispose();
                    vrContext = _useOculus ? VRContext.CreateOculus() : VRContext.CreateOpenVR();
                    vrContext.Initialize(gd);
                }
            }

            vrContext.Dispose();
            gd.Dispose();
        }
Example #18
0
 public void WindowResized(int width, int height) => _imguiRenderer.WindowResized(width, height);
Example #19
0
 static void _window_Resized()
 {
     _gd.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height);
     _controller.WindowResized(_window.Width, _window.Height);
 }
Example #20
0
 public DebugGuiRenderer()
 {
     On <RenderEvent>(e => e.Add(this));
     On <InputEvent>(e => _imguiRenderer.Update((float)e.DeltaSeconds, e.Snapshot));
     On <WindowResizedEvent>(e => _imguiRenderer.WindowResized(e.Width, e.Height));
 }
Example #21
0
 private void Resize()
 {
     windowResized = false;
     graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);
     imGuiRenderer.WindowResized(window.Width, window.Height);
 }
Example #22
0
        static void MainImGui(string[] args)
        {
            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 1920, 1080, WindowState.Normal, "ImGui Test"),
                out var window,
                out var gd);

            var cl = gd.ResourceFactory.CreateCommandList();

            // [1]
            var imguiRenderer = new ImGuiRenderer(
                gd,
                gd.MainSwapchain.Framebuffer.OutputDescription,
                window.Width,
                window.Height);

            var io = ImGui.GetIO();
//
//            var data = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ushort)) * 3);
//            var ranges = new ImVector<ushort>(3, 3, data);
//            ranges[0] = 0xf000;
//            ranges[1] = 0xf3ff;
//            ranges[2] = 0;
//
            var font = io.Fonts.AddFontFromFileTTF("Inconsolata-Regular.ttf", 16);

//            io.Fonts.Build();
            imguiRenderer.RecreateFontDeviceTexture();
            if (!font.IsLoaded())
            {
                throw new Exception("Could not load font");
            }

            var field = typeof(ImGuiRenderer).GetField("_scaleFactor", BindingFlags.Instance | BindingFlags.NonPublic);

            field.SetValue(imguiRenderer, new Vector2(2.5f, 2.5f));

            window.Resized += () =>
            {
                imguiRenderer.WindowResized(window.Width, window.Height);
                gd.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);
            };

            var buffer = new StringBuilder("[ryan@manjaro-xfce-vm-laptop ~]$ ");
//            for (int i = 127; i < 256 + 128; i++)
//                buffer.AppendLine($"{i}: {(char)i}");

            var  nextToggle = DateTime.UtcNow.AddMilliseconds(750);
            bool visible    = true;

            while (window.Exists)
            {
                var snapshot = new InputSnapshotWrapper(window.PumpEvents(), new Vector2(2.5f, 2.5f));
                imguiRenderer.Update(1f / 60f, snapshot); // [2]

                bool scrollToBottom = false;
                foreach (var c in snapshot.KeyCharPresses)
                {
                    buffer.Append(c);
                    scrollToBottom = true;
                }

                foreach (var k in snapshot.KeyEvents)
                {
                    if (k.Down && k.Key == Key.Enter)
                    {
                        buffer.AppendLine();
                        scrollToBottom = true;
                    }
                }

                if (DateTime.UtcNow >= nextToggle)
                {
                    visible    = !visible;
                    nextToggle = nextToggle.AddMilliseconds(750);
                }

                // Draw whatever you want here.
                ImGui.Begin("Test Window", ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoNav);
                ImGui.SetWindowPos(new Vector2(0, 0));
                ImGui.SetWindowSize(new Vector2(window.Width / 2.5f, window.Height / 2.5f));
                {
                    ImGui.PushFont(font);

                    ImGui.TextWrapped(buffer.ToString() + (visible ? '_' : ' '));
                    if (scrollToBottom)
                    {
                        ImGui.SetScrollHereY(1);
                    }
                }

                cl.Begin();
                cl.SetFramebuffer(gd.MainSwapchain.Framebuffer);
                cl.ClearColorTarget(0, new RgbaFloat(0, 0, 0.2f, 1f));
                imguiRenderer.Render(gd, cl); // [3]
                cl.End();
                gd.SubmitCommands(cl);
                gd.SwapBuffers(gd.MainSwapchain);
            }
        }
Example #23
0
        public static void Run(Options opts)
        {
            GraphicsBackend?preferredBackend = null;

            if (opts.Renderer != Renderer.Default)
            {
                preferredBackend = (GraphicsBackend)opts.Renderer;
            }

            Platform.Start();

            const int initialWidth  = 1024;
            const int initialHeight = 768;

            using (var window = new GameWindow("OpenSAGE Viewer", 100, 100, initialWidth, initialHeight, preferredBackend))
                using (var commandList = window.GraphicsDevice.ResourceFactory.CreateCommandList())
                    using (var imGuiRenderer = new ImGuiRenderer(window.GraphicsDevice, window.GraphicsDevice.MainSwapchain.Framebuffer.OutputDescription, initialWidth, initialHeight))
                        using (var gameTimer = new GameTimer())
                        {
                            window.ClientSizeChanged += (sender, e) =>
                            {
                                imGuiRenderer.WindowResized(window.ClientBounds.Width, window.ClientBounds.Height);
                            };

                            gameTimer.Start();

                            using (var mainForm = new MainForm(window, imGuiRenderer))
                            {
                                var emptyInputSnapshot = new EmptyInputSnapshot();
                                var isGameViewFocused  = false;

                                while (true)
                                {
                                    commandList.Begin();

                                    gameTimer.Update();

                                    if (!window.PumpEvents())
                                    {
                                        break;
                                    }

                                    commandList.SetFramebuffer(window.GraphicsDevice.MainSwapchain.Framebuffer);

                                    commandList.ClearColorTarget(0, RgbaFloat.Clear);

                                    if (isGameViewFocused)
                                    {
                                        if (window.CurrentInputSnapshot.KeyEvents.Any(x => x.Down && x.Key == Key.Escape))
                                        {
                                            isGameViewFocused = false;
                                        }
                                    }

                                    var inputSnapshot = isGameViewFocused
                            ? emptyInputSnapshot
                            : window.CurrentInputSnapshot;

                                    imGuiRenderer.Update(
                                        (float)gameTimer.CurrentGameTime.ElapsedGameTime.TotalSeconds,
                                        inputSnapshot);

                                    mainForm.Draw(ref isGameViewFocused);

                                    imGuiRenderer.Render(window.GraphicsDevice, commandList);

                                    commandList.End();

                                    window.GraphicsDevice.SubmitCommands(commandList);

                                    window.GraphicsDevice.SwapBuffers();
                                }
                            }
                        }

            Platform.Stop();
        }
Example #24
0
        static void Main(string[] args)
        {
            Platform.Start();

            const int initialWidth  = 1024;
            const int initialHeight = 768;

            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(100, 100, initialWidth, initialHeight, WindowState.Normal, "OpenSAGE Big Editor"),
                out var window,
                out var graphicsDevice);

            graphicsDevice.SyncToVerticalBlank = true;

            using (var commandList = graphicsDevice.ResourceFactory.CreateCommandList())
                using (var imGuiRenderer = new ImGuiRenderer(graphicsDevice, graphicsDevice.MainSwapchain.Framebuffer.OutputDescription, initialWidth, initialHeight))
                    using (var gameTimer = new GameTimer())
                    {
                        window.Resized += () =>
                        {
                            graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);
                            imGuiRenderer.WindowResized(window.Width, window.Height);
                        };

                        var windowOpen = true;
                        window.Closed += () => windowOpen = false;

                        gameTimer.Start();

                        using (var mainForm = new MainForm())
                        {
                            while (windowOpen)
                            {
                                commandList.Begin();

                                gameTimer.Update();

                                var inputSnapshot = window.PumpEvents();

                                commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);

                                commandList.ClearColorTarget(0, RgbaFloat.Clear);

                                imGuiRenderer.Update(
                                    (float)gameTimer.CurrentGameTime.ElapsedGameTime.TotalSeconds,
                                    inputSnapshot);

                                mainForm.Draw(window);

                                imGuiRenderer.Render(graphicsDevice, commandList);

                                commandList.End();

                                graphicsDevice.SubmitCommands(commandList);

                                graphicsDevice.SwapBuffers();
                            }
                        }
                    }

            graphicsDevice.Dispose();

            Platform.Stop();
        }
Example #25
0
        public Task Start(WindowCreateInfo wci, GraphicsDeviceOptions graphicsDeviceOptions)
        {
            return(Task.Factory.StartNew(() =>
            {
                _window = VeldridStartup.CreateWindow(ref wci);
                //Window.CursorVisible = false;
                //Window.SetMousePosition(Window.Width / 2, Window.Height / 2);
                _window.Resized += () => _windowResized = true;
                GraphicsDevice = VeldridStartup.CreateGraphicsDevice(_window, graphicsDeviceOptions, GraphicsBackend.Vulkan);
                CommandList = GraphicsDevice.ResourceFactory.CreateCommandList();

                CreateFramebuffer();

                Initialize();

                var imGuiRenderer = new ImGuiRenderer(GraphicsDevice, MainSceneFramebuffer.OutputDescription, _window.Width, _window.Height);

                _windowResized = true;

                Started?.Invoke();

                var frameWatch = Stopwatch.StartNew();

                while (_window.Exists)
                {
                    var inputSnapshot = _window.PumpEvents();

                    if (!_window.Exists)
                    {
                        break;
                    }

                    InputTracker.UpdateFrameInput(_window, inputSnapshot);

                    if (InputTracker.WasKeyDowned(Key.Tilde))
                    {
                        InputTracker.LockMouse = !InputTracker.LockMouse;
                    }
                    //if (InputTracker.WasKeyDowned(Key.T)) { StackedTiming.Enabled = !StackedTiming.Enabled; Timing.Enabled = !Timing.Enabled; }

                    if (_windowResized)
                    {
                        _windowResized = false;
                        GraphicsDevice.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);

                        _projectionMatrix = Matrix4x4.CreatePerspectiveFieldOfView(
                            0.90f,
                            (float)_window.Width / _window.Height,
                            0.4f,
                            512f);
                        if (GraphicsDevice.IsClipSpaceYInverted)
                        {
                            _projectionMatrix *= Matrix4x4.CreateScale(1, -1, 1);
                        }

                        imGuiRenderer.WindowResized(_window.Width, _window.Height);
                    }

                    var frameTime = frameWatch.Elapsed.TotalSeconds;
                    frameTime = Math.Min(frameTime, 0.033333);
                    frameWatch.Restart();

                    imGuiRenderer.Update((float)frameTime, InputTracker.LockMouse ? new EmptyInputSnapshot() : InputTracker.FrameSnapshot);

                    Scene.Update(frameTime);

                    Tick?.Invoke();

                    CommandList.Begin();
                    CommandList.SetFramebuffer(MainSceneFramebuffer);
                    CommandList.ClearColorTarget(0, RgbaFloat.CornflowerBlue);
                    CommandList.ClearDepthStencil(1f);

                    var context = new RenderingContext()
                    {
                        GraphicsDevice = GraphicsDevice,
                        CommandList = CommandList,
                        CameraTransform = CameraTransform,
                        ProjectionMatrix = _projectionMatrix
                    };
                    Scene.Render(context);

                    var displaySize = ImGui.GetIO().DisplaySize;
                    ImGui.GetBackgroundDrawList().AddCircleFilled(displaySize / 2, 2, ImGui.GetColorU32(new Vector4(1, 1, 1, 1)));

                    imGuiRenderer.Render(GraphicsDevice, CommandList);

                    if (_mainSceneColourTexture != null && _mainSceneColourTexture.SampleCount != TextureSampleCount.Count1)
                    {
                        CommandList.ResolveTexture(_mainSceneColourTexture, GraphicsDevice.MainSwapchain.Framebuffer.ColorTargets.First().Target);
                    }

                    CommandList.End();
                    GraphicsDevice.SubmitCommands(CommandList);
                    GraphicsDevice.SwapBuffers(GraphicsDevice.MainSwapchain);
                    GraphicsDevice.WaitForIdle();

                    Resources.Update();
                }
            }, TaskCreationOptions.LongRunning));
        }
Example #26
0
 public void WindowResized(int width, int height)
 {
     _imGuiRenderer?.WindowResized(width, height);
 }
Example #27
0
        static string?Launcher()
        {
            var createInfo = new WindowCreateInfo
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 400,
                WindowHeight       = 150,
                WindowInitialState = WindowState.Normal,
                WindowTitle        = "OpenSAGE Apt Editor"
            };

            VeldridStartup.CreateWindowAndGraphicsDevice(createInfo, out var window, out var outGraphicsDevice);
            using var graphicsDevice           = outGraphicsDevice;
            graphicsDevice.SyncToVerticalBlank = true;
            using var commandList   = graphicsDevice.ResourceFactory.CreateCommandList();
            using var imGuiRenderer = new ImGuiRenderer(graphicsDevice,
                                                        graphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
                                                        window.Width,
                                                        window.Height);
            using var gameTimer = new DeltaTimer();
            string?rootPath      = null;
            var    rootPathInput = new ImGuiTextBox(1024);

            void OnWindowResized()
            {
                graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);
                imGuiRenderer.WindowResized(window.Width, window.Height);
            }

            window.Resized += OnWindowResized;
            try
            {
                gameTimer.Start();
                while (rootPath == null)
                {
                    if (!window.Exists)
                    {
                        return(null);
                    }

                    gameTimer.Update();
                    var inputSnapshot = window.PumpEvents();
                    imGuiRenderer.Update((float)gameTimer.CurrentGameTime.DeltaTime.TotalSeconds, inputSnapshot);

                    commandList.Begin();
                    commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
                    commandList.ClearColorTarget(0, RgbaFloat.Clear);

                    ImGui.SetNextWindowPos(Vector2.Zero);
                    ImGui.SetNextWindowSize(new Vector2(window.Width, window.Height));
                    var open = true;
                    if (ImGui.Begin("Launcher", ref open, ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize))
                    {
                        ImGui.TextWrapped("Start OpenSage Apt Editor by providing a root path.");
                        ImGui.TextWrapped("It's recommended that you set it to " +
                                          "the RA3SDK_UI_ScreensPack folder so you could load apt files more easily.");
                        rootPathInput.InputText("##rootPath", out var inputRootPath);
                        if (ImGui.Button("Load"))
                        {
                            rootPath = inputRootPath;
                            window.Close();
                        }
                    }
                    ImGui.End();

                    imGuiRenderer.Render(graphicsDevice, commandList);
                    commandList.End();
                    graphicsDevice.SubmitCommands(commandList);
                    graphicsDevice.SwapBuffers();
                }
                return(rootPath);
            }
            finally
            {
                window.Resized -= OnWindowResized;
            }
        }
Example #28
0
        static void GameWindowAdapter(string rootPath)
        {
            var installation = new GameInstallation(new AptEditorDefinition(), rootPath);

            using var game = new Game(installation, null, new Configuration { LoadShellMap = false });
            // should be the ImGui context created by DeveloperModeView
            var initialContext = ImGui.GetCurrentContext();
            var device         = game.GraphicsDevice;
            var window         = game.Window;

            using var imGuiRenderer = new ImGuiRenderer(device,
                                                        game.Panel.OutputDescription,
                                                        window.ClientBounds.Width,
                                                        window.ClientBounds.Height);
            var font = imGuiRenderer.LoadSystemFont("consola.ttf");

            using var commandList = device.ResourceFactory.CreateCommandList();
            var ourContext = ImGui.GetCurrentContext();

            // reset ImGui Context to initial one
            ImGui.SetCurrentContext(initialContext);

            var mainForm = new MainForm(game);

            void OnClientSizeChanged(object?sender, EventArgs args)
            {
                imGuiRenderer.WindowResized(window.ClientBounds.Width, window.ClientBounds.Height);
            }

            void OnRendering2D(object?sender, EventArgs e)
            {
                var previousContext = ImGui.GetCurrentContext();

                ImGui.SetCurrentContext(ourContext);
                try
                {
                    commandList.Begin();
                    commandList.SetFramebuffer(game.Panel.Framebuffer);
                    imGuiRenderer.Update((float)game.RenderTime.DeltaTime.TotalSeconds, window.CurrentInputSnapshot);
                    using (var fontSetter = new ImGuiFontSetter(font))
                    {
                        mainForm.Draw();
                    }
                    imGuiRenderer.Render(game.GraphicsDevice, commandList);
                    commandList.End();
                    device.SubmitCommands(commandList);
                }
                finally
                {
                    ImGui.SetCurrentContext(previousContext);
                }
            }

            window.ClientSizeChanged += OnClientSizeChanged;
            game.RenderCompleted     += OnRendering2D;
            try
            {
                game.ShowMainMenu();
                game.Run();
            }
            finally
            {
                game.RenderCompleted     -= OnRendering2D;
                window.ClientSizeChanged -= OnClientSizeChanged;
            }
        }
Example #29
0
        public static void Main(string[] args)
        {
            GraphicsBackend?preferredBackend = null;

            ArgumentSyntax.Parse(args, syntax =>
            {
                string preferredBackendString = null;
                syntax.DefineOption("renderer", ref preferredBackendString, false, $"Choose which renderer backend should be used. Valid options: {string.Join(",", Enum.GetNames(typeof(GraphicsBackend)))}");
                if (preferredBackendString != null)
                {
                    if (Enum.TryParse <GraphicsBackend>(preferredBackendString, out var preferredBackendTemp))
                    {
                        preferredBackend = preferredBackendTemp;
                    }
                    else
                    {
                        syntax.ReportError($"Unknown renderer backend: {preferredBackendString}");
                    }
                }
            });

            Platform.Start();

            const int initialWidth  = 1024;
            const int initialHeight = 768;

            using (var window = new GameWindow("OpenSAGE Viewer", 100, 100, initialWidth, initialHeight, preferredBackend))
                using (var commandList = window.GraphicsDevice.ResourceFactory.CreateCommandList())
                    using (var imGuiRenderer = new ImGuiRenderer(window.GraphicsDevice, window.GraphicsDevice.MainSwapchain.Framebuffer.OutputDescription, initialWidth, initialHeight))
                        using (var gameTimer = new GameTimer())
                        {
                            window.ClientSizeChanged += (sender, e) =>
                            {
                                imGuiRenderer.WindowResized(window.ClientBounds.Width, window.ClientBounds.Height);
                            };

                            gameTimer.Start();

                            using (var mainForm = new MainForm(window, imGuiRenderer))
                            {
                                var emptyInputSnapshot = new EmptyInputSnapshot();
                                var isGameViewFocused  = false;

                                while (true)
                                {
                                    commandList.Begin();

                                    gameTimer.Update();

                                    if (!window.PumpEvents())
                                    {
                                        break;
                                    }

                                    commandList.SetFramebuffer(window.GraphicsDevice.MainSwapchain.Framebuffer);

                                    commandList.ClearColorTarget(0, RgbaFloat.Clear);

                                    if (isGameViewFocused)
                                    {
                                        if (window.CurrentInputSnapshot.KeyEvents.Any(x => x.Down && x.Key == Key.Escape))
                                        {
                                            isGameViewFocused = false;
                                        }
                                    }

                                    var inputSnapshot = isGameViewFocused
                            ? emptyInputSnapshot
                            : window.CurrentInputSnapshot;

                                    imGuiRenderer.Update(
                                        (float)gameTimer.CurrentGameTime.ElapsedGameTime.TotalSeconds,
                                        inputSnapshot);

                                    mainForm.Draw(ref isGameViewFocused);

                                    imGuiRenderer.Render(window.GraphicsDevice, commandList);

                                    commandList.End();

                                    window.GraphicsDevice.SubmitCommands(commandList);

                                    window.GraphicsDevice.SwapBuffers();
                                }
                            }
                        }

            Platform.Stop();
        }