예제 #1
0
        internal IntPtr CreateGlfwWindow(string title, int width, int height, WindowFlags flags)
        {
            GLFW.WindowHint(GLFW_Enum.VISIBLE, false);
            GLFW.WindowHint(GLFW_Enum.FOCUS_ON_SHOW, true);
            GLFW.WindowHint(GLFW_Enum.FOCUSED, true);
            GLFW.WindowHint(GLFW_Enum.TRANSPARENT_FRAMEBUFFER, flags.HasFlag(WindowFlags.Transparent));
            GLFW.WindowHint(GLFW_Enum.SCALE_TO_MONITOR, flags.HasFlag(WindowFlags.ScaleToMonitor));
            GLFW.WindowHint(GLFW_Enum.SAMPLES, flags.HasFlag(WindowFlags.MultiSampling) ? 4 : 0);
            GLFW.WindowHint(GLFW_Enum.MAXIMIZED, flags.HasFlag(WindowFlags.Maximized));

            IntPtr shared = IntPtr.Zero;

            if (App.Graphics is IGraphicsOpenGL && windowPointers.Count > 0)
            {
                shared = windowPointers[0];
            }

            var monitor = IntPtr.Zero;

            if (flags.HasFlag(WindowFlags.Fullscreen))
            {
                monitor = GLFW.GetPrimaryMonitor();
            }

            // create the GLFW Window and return thr pointer
            var ptr = GLFW.CreateWindow(width, height, title, monitor, shared);

            if (ptr == IntPtr.Zero)
            {
                GLFW.GetError(out string error);
                throw new Exception($"Unable to create a new Window: {error}");
            }
            windowPointers.Add(ptr);

            // create the Vulkan surface
            if (App.Graphics is IGraphicsVulkan vkGraphics)
            {
                var vkInstance = vkGraphics.GetVulkanInstancePointer();
                var result     = GLFW.CreateWindowSurface(vkInstance, ptr, IntPtr.Zero, out var surface);

                if (result != GLFW_VkResult.Success)
                {
                    throw new Exception($"Unable to create a Vulkan Surface, {result}");
                }

                vkSurfaces.Add(ptr, surface);
            }

            // show window
            if (!flags.HasFlag(WindowFlags.Hidden))
            {
                GLFW.ShowWindow(ptr);
            }

            return(ptr);
        }