private void InitializeSubWindow(GraphicsDevice gd, Sdl2Window sdlWindow) { GcHandle = GCHandle.Alloc(this); graphicsDevice = gd; VSync = gd.SyncToVerticalBlank; window = sdlWindow; SwapchainSource scSrc = WindowStartup.GetSwapchainSource(sdlWindow); SwapchainDescription scDesc = new SwapchainDescription(scSrc, (uint)sdlWindow.Width, (uint)sdlWindow.Height, gd.SwapchainFramebuffer.OutputDescription.DepthAttachment?.Format, VSync); swapchain = gd.ResourceFactory.CreateSwapchain(scDesc); window.Resized += () => swapchain.Resize((uint)window.Width, (uint)window.Height); }
private void Initialize(WindowProps props, GraphicsBackend backend) { InputManager.CreateInstance <WindowsInput>(); GcHandle = GCHandle.Alloc(this); GraphicsDeviceOptions options = new GraphicsDeviceOptions() { Debug = false, PreferDepthRangeZeroToOne = true, PreferStandardClipSpaceYDirection = false, ResourceBindingModel = ResourceBindingModel.Improved, SyncToVerticalBlank = props.VSync, HasMainSwapchain = true, SwapchainDepthFormat = PixelFormat.R16_UNorm, SwapchainSrgbFormat = false }; #if DEBUG options.Debug = true; #endif WindowStartup.CreateWindowAndGraphicsDevice(props, options, backend, out window, out graphicsDevice); VSync = props.VSync; swapchain = graphicsDevice.MainSwapchain; // Called twice possibly because of 2 events being fired: Resize and SizeChanged (and Maximized) // #TODO treat it here or hope for Veldrid to be updated with this (Maybe clone and alter source code myself) // currently deduplicated in the application window.Resized += () => { EventCallback(new WindowResizeEvent(window.Width, window.Height)); }; window.Closed += () => EventCallback(new WindowCloseEvent()); window.KeyUp += (keyEvent) => EventCallback(new KeyReleasedEvent((int)keyEvent.Key)); window.KeyDown += (keyEvent) => EventCallback(new KeyPressedEvent((int)keyEvent.Key, 1)); window.MouseDown += (mouseEvent) => EventCallback(new MouseButtonPressedEvent((int)mouseEvent.MouseButton)); window.MouseUp += (mouseEvent) => EventCallback(new MouseButtonReleasedEvent((int)mouseEvent.MouseButton)); window.MouseWheel += (mouseEvent) => EventCallback(new MouseScrolledEvent(mouseEvent.WheelDelta)); window.MouseMove += (mouseEvent) => EventCallback(new MouseMovedEvent(mouseEvent.MousePosition.X, mouseEvent.MousePosition.Y)); }