Exemple #1
0
        private void Poll()
        {
            GLFW.PollEvents();

            // check for closing windows
            for (int i = windowPointers.Count - 1; i >= 0; i--)
            {
                if (GLFW.WindowShouldClose(windowPointers[i]))
                {
                    // see if we have a GLFW_Window associated
                    if (glfwWindows.TryGetValue(windowPointers[i], out var window))
                    {
                        input.StopListening(window.pointer);
                        glfwWindows.Remove(window.pointer);
                        window.InvokeCloseWindowCallback();
                    }

                    // remove OpenGL context
                    if (App.Graphics is IGraphicsOpenGL)
                    {
                        glContexts.Remove(windowPointers[i]);
                    }
                    // remove Vulkan Surface
                    else if (App.Graphics is IGraphicsVulkan vkGraphics)
                    {
                        var vkInstance = vkGraphics.GetVulkanInstancePointer();

                        if (vkDestroySurfaceKHR == null)
                        {
                            var ptr = GetVKProcAddress(vkInstance, "vkDestroySurfaceKHR");
                            if (ptr != null)
                            {
                                vkDestroySurfaceKHR = (VkDestroySurfaceKHR)Marshal.GetDelegateForFunctionPointer(ptr, typeof(VkDestroySurfaceKHR));
                            }
                        }

                        vkDestroySurfaceKHR?.Invoke(vkInstance, vkSurfaces[windowPointers[i]], IntPtr.Zero);
                        vkSurfaces.Remove(windowPointers[i]);
                    }

                    GLFW.DestroyWindow(windowPointers[i]);
                    windowPointers.RemoveAt(i);
                }
            }
        }