unsafe public void RecordFramebuffer(Framebuffer fbuf) { //exit if no video capture or screenshot pending VideoEncoder recorder = rgatState.VideoRecorder; if ((recorder == null || !recorder.Recording) && _rgatUI !.PendingScreenshot == VideoEncoder.CaptureContent.Invalid) { return; } if (rgatState.VideoRecorder.Recording && !rgatState.VideoRecorder.CapturePaused) { _rgatUI !.GetFrameDimensions(rgatState.VideoRecorder.GetCapturedContent(), out int startX, out int startY, out int width, out int height); System.Drawing.Bitmap videoBmp = MediaDrawing.CreateRecordingFrame(fbuf, startX, startY, width, height); rgatState.VideoRecorder.QueueFrame(videoBmp, rgatState.ActiveGraph); } if (_rgatUI !.PendingScreenshot != VideoEncoder.CaptureContent.Invalid) { string?savePath = null; try { _rgatUI.GetFrameDimensions(_rgatUI.PendingScreenshot, out int startX, out int startY, out int width, out int height); System.Drawing.Bitmap screenBmp = MediaDrawing.CreateRecordingFrame(fbuf, startX, startY, width, height); savePath = rgatState.VideoRecorder.SaveImage(rgatState.ActiveGraph, screenBmp); } catch (Exception e) { Logging.RecordException($"Unhandled exception while taking screenshot {_rgatUI.PendingScreenshot}: {e.Message}", e); } if (savePath is not null) { _rgatUI.NotifyScreenshotComplete(savePath); } } }
private bool Setup() { System.Threading.Thread.CurrentThread.Name = "rgatUIMain"; GraphicsDeviceOptions options = new GraphicsDeviceOptions( debug: true, swapchainDepthFormat: PixelFormat.R8_UNorm, syncToVerticalBlank: true, resourceBindingModel: ResourceBindingModel.Improved, preferDepthRangeZeroToOne: true, preferStandardClipSpaceYDirection: false); bool loadSuccess = false; try { string windowTitle = $"rgat {CONSTANTS.PROGRAMVERSION.RGAT_VERSION_LONG}"; Veldrid.StartupUtilities.VeldridStartup.CreateWindowAndGraphicsDevice( new Veldrid.StartupUtilities.WindowCreateInfo(50, 50, 1800, 900, WindowState.Normal, windowTitle), //new GraphicsDeviceOptions(true, null, true, ResourceBindingModel.Improved, true, true), options, preferredBackend: GraphicsBackend.Vulkan, out _window, out _gd); loadSuccess = true; } catch (System.TypeInitializationException e) { if (e.InnerException != null) { if (e.InnerException.GetType() == typeof(System.InvalidOperationException)) { Logging.RecordError($"Error: Unable to initialise the Vulkan graphics driver: {e.InnerException.Message}"); } else { Logging.RecordError($"Window Creation Exception: {e.InnerException.Message}"); } } else { Logging.RecordError($"Error: Unable to initialise the Vulkan graphics driver. {e.Message}"); } } catch (Exception e) { Logging.RecordException($"Error 2: unable to initialise Vulkan driver. {e.Message}", e); } if (!loadSuccess || _gd is null || _window is null) { return(false); } _cl = _gd.ResourceFactory.CreateCommandList(); _rgatState.InitVeldrid(_gd); _controller = new ImGuiController(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height); MediaDrawing.SetController(_controller); _rgatUI = new rgatUI(_rgatState, _controller); //load in a thread to keep things interactive Task loader = Task.Run(() => LoadingThread()); ImGui.GetIO().ConfigWindowsMoveFromTitleBarOnly = true; return(true); }