Ejemplo n.º 1
0
        private void ResizeSwapchain()
        {
            var dpiScale = GetDpiScale();
            var width    = (uint)(ActualWidth < 0 ? 0 : Math.Ceiling(ActualWidth * dpiScale));
            var height   = (uint)(ActualHeight < 0 ? 0 : Math.Ceiling(ActualHeight * dpiScale));

            _sc.Resize(width, height);
        }
        public VeldridImGuiWindow(GraphicsDevice gd, ImGuiViewportPtr vp)
        {
            _gcHandle = GCHandle.Alloc(this);
            _gd       = gd;
            _vp       = vp;

            SDL_WindowFlags flags = SDL_WindowFlags.Hidden;

            if ((vp.Flags & ImGuiViewportFlags.NoTaskBarIcon) != 0)
            {
                flags |= SDL_WindowFlags.SkipTaskbar;
            }
            if ((vp.Flags & ImGuiViewportFlags.NoDecoration) != 0)
            {
                flags |= SDL_WindowFlags.Borderless;
            }
            else
            {
                flags |= SDL_WindowFlags.Resizable;
            }

            if ((vp.Flags & ImGuiViewportFlags.TopMost) != 0)
            {
                flags |= SDL_WindowFlags.AlwaysOnTop;
            }

            _window = new Sdl2Window(
                "No Title Yet",
                (int)vp.Pos.X, (int)vp.Pos.Y,
                (int)vp.Size.X, (int)vp.Size.Y,
                flags,
                false);
            _window.Resized += () => _vp.PlatformRequestResize = true;
            _window.Moved   += p => _vp.PlatformRequestMove = true;
            _window.Closed  += () => _vp.PlatformRequestClose = true;

            SwapchainSource      scSource = VeldridStartup.GetSwapchainSource(_window);
            SwapchainDescription scDesc   = new SwapchainDescription(scSource, (uint)_window.Width, (uint)_window.Height, null, true, false);

            _sc              = _gd.ResourceFactory.CreateSwapchain(scDesc);
            _window.Resized += () => _sc.Resize((uint)_window.Width, (uint)_window.Height);

            unsafe
            {
                ViewportDataPtr data = new ViewportDataPtr(Marshal.AllocHGlobal(Unsafe.SizeOf <ViewportDataPtr>()));
                vp.PlatformUserData = new HandleRef(data, (IntPtr)data.NativePtr).Handle;
            }
            vp.PlatformUserData = (IntPtr)_gcHandle;
        }
Ejemplo n.º 3
0
 public void Resize(uint width, uint height)
 {
     if (Swapchain is object &&
         Camera is object &&
         rendering.WaitOne())
     {
         try
         {
             Swapchain.Resize(width, height);
             Camera.AspectRatio = AspectRatio;
         }
         finally
         {
             _ = rendering.Release();
         }
     }
 }
Ejemplo n.º 4
0
 // Called whenever view changes orientation or layout is changed
 public override void ViewDidLayoutSubviews()
 {
     base.ViewDidLayoutSubviews();
     _sc.Resize((uint)View.Frame.Width, (uint)View.Frame.Height);
     Resized?.Invoke();
 }