static void Main(string[] args) { Veldrid.StartupUtilities.VeldridStartup.CreateWindowAndGraphicsDevice( new Veldrid.StartupUtilities.WindowCreateInfo( 48, 48, 512, 384, Veldrid.WindowState.Normal, "Example" ), new Veldrid.GraphicsDeviceOptions(true, null, true), out window, out gd ); window.Resized += () => { gd.MainSwapchain.Resize((uint)window.Width, (uint)window.Height); controller.WindowResized(window.Width, window.Height); }; cl = gd.ResourceFactory.CreateCommandList(); controller = new Veldrid.ImGuiRenderer(gd, gd.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height); // main while (window.Exists) { Veldrid.InputSnapshot snapshot = window.PumpEvents(); if (!window.Exists) { break; } controller.Update(1f / 60f, snapshot); // UI { ImGuiNET.ImGui.Text("Hello World!"); ImGuiNET.ImGui.SameLine(); ImGuiNET.ImGui.Checkbox("show another window?", ref showAWindow); } if (showAWindow) { ImGuiNET.ImGui.SetNextWindowSize( new System.Numerics.Vector2(128, 128)); ImGuiNET.ImGui.Begin("Another window", ref showAWindow); ImGuiNET.ImGui.Text("Lorem ipsum"); if (ImGuiNET.ImGui.Button("I got it")) { showAWindow = false; } ImGuiNET.ImGui.End(); } cl.Begin(); cl.SetFramebuffer(gd.MainSwapchain.Framebuffer); cl.ClearColorTarget(0, new Veldrid.RgbaFloat(160f / 255, 160f / 255, 192f / 255, 255f)); controller.Render(gd, cl); cl.End(); gd.SubmitCommands(cl); gd.SwapBuffers(gd.MainSwapchain); } gd.WaitForIdle(); controller.Dispose(); cl.Dispose(); gd.Dispose(); }
protected override void Draw(Veldrid.CommandList cl) { // FIXME: Handle elapsed time and not constant float elapsedTime = 1f / 60; // FIXME: Can I get the "last" state from Veldrid? this.deviceSet.UpdateSnapshot(this.LastInputSnapshot); this.deviceSet.Update(elapsedTime); this.InputSystem.Update(elapsedTime); this.ComboTracker.Update(elapsedTime); this.DeviceSetControl.DrawWindow(); this.InputSystemControl.DrawWindow(); this.ComboTrackerControl.DrawWindow(); }
public void ThreadProc() { System.Diagnostics.Stopwatch st = new(); PlottedGraph?activeGraph; int exceptionCount = 0; Veldrid.CommandList cl = _clientState !._GraphicsDevice !.ResourceFactory.CreateCommandList(); while (!rgatState.rgatIsExiting) { activeGraph = rgatState.GetActiveGraph(); while (activeGraph == null) { Thread.Sleep(50); if (rgatState.rgatIsExiting) { Finished(); return; } activeGraph = rgatState.GetActiveGraph(); continue; } st.Restart(); try { update_rendering(activeGraph); } catch (Exception e) { Logging.RecordException($"update_rendering error: {e.Message}", e); if (exceptionCount++ > 5) { Logging.RecordError("Maingraph renderer terminating due to excess exceptions"); break; } } st.Stop(); //if (st.ElapsedMilliseconds > 0) System.Console.WriteLine($"u_R took {st.ElapsedMilliseconds} ms"); //st.Restart(); try { _graphWidget.GenerateMainGraph(cl); } catch (Exception e) { Logging.RecordException($"update_rendering error: {e.Message}", e); if (exceptionCount++ > 5) { Logging.RecordError("Maingraph renderer terminating due to excess exceptions"); break; } } //clear staging buffers //https://github.com/mellinoe/veldrid/issues/411 cl.Dispose(); cl = _clientState !._GraphicsDevice !.ResourceFactory.CreateCommandList(); st.Stop(); //if (st.ElapsedMilliseconds > 0) System.Console.WriteLine($"gmg took {st.ElapsedMilliseconds} ms"); Thread.Sleep(GlobalConfig.MainGraphRenderDelay); } Finished(); }