static void render(SwapChainPanel swapChainPanel)
        {
            ICommandListFactory commandListFactory = GetCommandListFactory(swapChainPanel);

            if (commandListFactory == null)
            {
                return;
            }

            RenderData _renderData = RenderData.Find(swapChainPanel, false);

            if (_renderData == null)
            {
                return;
            }

            Debug.WriteLine($"{nameof(SwapChainPanelPainter)}.{nameof(render)} _renderData={_renderData}");

            GraphicsDevice _graphicsDevice = _renderData.graphicsDevice;

            if (_graphicsDevice == null)
            {
                return;
            }

            Veldrid.Swapchain _swapchain = _renderData.swapchain;
            if (_swapchain == null)
            {
                return;
            }

            Framebuffer _framebuffer = _renderData.framebuffer;

            if (_framebuffer == null)
            {
                return;
            }

            {
                Veldrid.CommandList _commandList = null;
                try
                {
                    _commandList = commandListFactory.BuildCommandList(_graphicsDevice, _framebuffer);
                    if (_commandList == null)
                    {
                        return;
                    }

                    _graphicsDevice.SubmitCommands(_commandList);
                    _graphicsDevice.SwapBuffers(_swapchain);
                }
                catch (Exception E)
                {
                }
                finally
                {
                    _commandList?.Dispose();
                }
            }
        }
Esempio n. 2
0
        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;
        }