Esempio n. 1
0
        public static Vector2 SDL_GL_GetDrawableSize(SDL_Window window)
        {
            int w, h;

            sdl_gl_get_drawable_size(window, &w, &h);
            return(new Vector2(w, h));
        }
Esempio n. 2
0
        public static SDL_DisplayMode SDL_GetWindowDisplayMode(SDL_Window window)
        {
            SDL_DisplayMode mode;

            sdl_get_window_display_mode(window.NativePointer, &mode);
            return(mode);
        }
Esempio n. 3
0
        public unsafe NativeWindow(
            GraphicsService graphicsService,
            string title,
            int x, int y,
            int width, int height,
            SDL_WindowFlags flags
            )
        {
            _width           = width;
            _height          = height;
            _graphicsService = graphicsService;
            _handle          = SDL2Native.SDL_CreateWindow(
                title,
                x, y,
                width, height,
                flags
                );

            //get sdl version
            var sysWindowInfo = new SDL_SysWMinfo();

            SDL2Native.SDL_GetVersion(&sysWindowInfo.version);
            _version = sysWindowInfo.version;
            if (SDL2Native.SDL_GetWMWindowInfo(
                    _handle,
                    &sysWindowInfo
                    ) == 0)
            {
                throw new Exception("couldn't retrive sdl window information");
            }

            VkResult     error;
            VkSurfaceKHR surface;

            if (sysWindowInfo.subsystem == SysWMType.Windows)
            {
                var processHandle = (
                    Process
                    .GetCurrentProcess()
                    .SafeHandle
                    .DangerousGetHandle()
                    );
                var win32Info   = Unsafe.Read <Win32WindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkWin32SurfaceCreateInfoKHR
                {
                    sType     = VkStructureType.Win32SurfaceCreateInfoKHR,
                    hinstance = processHandle,
                    hwnd      = win32Info.window
                };
                error = VulkanNative.vkCreateWin32SurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.X11)
            {
                var x11Info     = Unsafe.Read <X11WindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkXlibSurfaceCreateInfoKHR
                {
                    sType  = VkStructureType.XlibSurfaceCreateInfoKHR,
                    dpy    = (Vulkan.Xlib.Display *)x11Info.display,
                    window = new Vulkan.Xlib.Window
                    {
                        Value = x11Info.window
                    }
                };
                error = VulkanNative.vkCreateXlibSurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.Wayland)
            {
                var waylandINfo = Unsafe.Read <WaylandWindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkWaylandSurfaceCreateInfoKHR
                {
                    sType   = VkStructureType.WaylandSurfaceCreateInfoKHR,
                    display = (Vulkan.Wayland.wl_display *)waylandINfo.display,
                    surface = (Vulkan.Wayland.wl_surface *)waylandINfo.surface
                };
                error = VulkanNative.vkCreateWaylandSurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.Android)
            {
                var androidInfo = Unsafe.Read <AndroidWindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkAndroidSurfaceCreateInfoKHR
                {
                    sType  = VkStructureType.AndroidSurfaceCreateInfoKHR,
                    window = (Vulkan.Android.ANativeWindow *)androidInfo.window
                };
                error = VulkanNative.vkCreateAndroidSurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.Mir)
            {
                var mirInfo     = Unsafe.Read <MirWindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkMirSurfaceCreateInfoKHR
                {
                    sType      = VkStructureType.MirSurfaceCreateInfoKHR,
                    connection = (Vulkan.Mir.MirConnection *)mirInfo.connection,
                    mirSurface = (Vulkan.Mir.MirSurface *)mirInfo.mirSurface
                };
                error = VulkanNative.vkCreateMirSurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.Cocoa)
            {
                var cocaInfo = Unsafe.Read <CocoaWindowInfo>(&sysWindowInfo.info);

                var nsWindow    = new NSWindow(cocaInfo.Window);
                var contentView = nsWindow.contentView;
                contentView.wantsLayer = true;
                contentView.layer      = CAMetalLayer.New().NativePtr;

                var surfaceInfo = new VkMacOSSurfaceCreateInfoMVK
                {
                    sType = VkStructureType.MacosSurfaceCreateInfoMvk,
                    pView = nsWindow.contentView.NativePtr.ToPointer()
                };
                error = VulkanNative.vkCreateMacOSSurfaceMVK(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else
            {
                throw new PlatformNotSupportedException("this platform is currently not supported");
            }

            if (error != VkResult.Success)
            {
                throw new Exception("failed to create window surface");
            }

            _surface = surface;
        }
Esempio n. 4
0
 public static int SDL_GetWindowDisplayIndex(SDL_Window Sdl2Window) => GetWindowDisplayIndexImpl(Sdl2Window);
Esempio n. 5
0
 public static SDL_Renderer SDL_CreateRenderer(SDL_Window window, int index, uint flags)
 => s_sdl_createRenderer(window, index, flags);
Esempio n. 6
0
 public static int SDL_GetWindowDisplayIndex(SDL_Window window) => sdl_get_window_display_index(window);
Esempio n. 7
0
 public static int SDL_SetWindowDisplayMode(SDL_Window window, SDL_DisplayMode mode) => sdl_set_window_display_mode(window.NativePointer, &mode);