|
| 1 | +using Veldrid; |
| 2 | +using Veldrid.Sdl2; |
| 3 | +using Veldrid.StartupUtilities; |
| 4 | + |
| 5 | +namespace XIVLauncher.Core.DesktopEnvironment; |
| 6 | + |
| 7 | +// Patched piece of VeldridStartup to pass SDL_WindowFlags.AllowHighDpi to SDL_CreateWindow |
| 8 | +public static class XLVeldridStartup |
| 9 | +{ |
| 10 | + public static void CreateWindowAndGraphicsDevice( |
| 11 | + WindowCreateInfo windowCI, |
| 12 | + out Sdl2Window window, |
| 13 | + out GraphicsDevice gd) |
| 14 | + => CreateWindowAndGraphicsDevice( |
| 15 | + windowCI, |
| 16 | + new GraphicsDeviceOptions(), |
| 17 | + VeldridStartup.GetPlatformDefaultBackend(), |
| 18 | + out window, |
| 19 | + out gd); |
| 20 | + |
| 21 | + public static void CreateWindowAndGraphicsDevice( |
| 22 | + WindowCreateInfo windowCI, |
| 23 | + GraphicsDeviceOptions deviceOptions, |
| 24 | + out Sdl2Window window, |
| 25 | + out GraphicsDevice gd) |
| 26 | + => CreateWindowAndGraphicsDevice(windowCI, deviceOptions, VeldridStartup.GetPlatformDefaultBackend(), out window, out gd); |
| 27 | + |
| 28 | + public static void CreateWindowAndGraphicsDevice( |
| 29 | + WindowCreateInfo windowCI, |
| 30 | + GraphicsDeviceOptions deviceOptions, |
| 31 | + GraphicsBackend preferredBackend, |
| 32 | + out Sdl2Window window, |
| 33 | + out GraphicsDevice gd) |
| 34 | + { |
| 35 | + Sdl2Native.SDL_Init(SDLInitFlags.Video); |
| 36 | + if (preferredBackend == GraphicsBackend.OpenGL || preferredBackend == GraphicsBackend.OpenGLES) |
| 37 | + { |
| 38 | + VeldridStartup.SetSDLGLContextAttributes(deviceOptions, preferredBackend); |
| 39 | + } |
| 40 | + |
| 41 | + window = CreateWindow(ref windowCI); |
| 42 | + gd = VeldridStartup.CreateGraphicsDevice(window, deviceOptions, preferredBackend); |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + public static Sdl2Window CreateWindow(WindowCreateInfo windowCI) => CreateWindow(ref windowCI); |
| 47 | + |
| 48 | + public static Sdl2Window CreateWindow(ref WindowCreateInfo windowCI) |
| 49 | + { |
| 50 | + SDL_WindowFlags flags = SDL_WindowFlags.OpenGL | SDL_WindowFlags.Resizable | SDL_WindowFlags.AllowHighDpi |
| 51 | + | GetWindowFlags(windowCI.WindowInitialState); |
| 52 | + if (windowCI.WindowInitialState != WindowState.Hidden) |
| 53 | + { |
| 54 | + flags |= SDL_WindowFlags.Shown; |
| 55 | + } |
| 56 | + Sdl2Window window = new Sdl2Window( |
| 57 | + windowCI.WindowTitle, |
| 58 | + windowCI.X, |
| 59 | + windowCI.Y, |
| 60 | + windowCI.WindowWidth, |
| 61 | + windowCI.WindowHeight, |
| 62 | + flags, |
| 63 | + false); |
| 64 | + |
| 65 | + return window; |
| 66 | + } |
| 67 | + |
| 68 | + private static SDL_WindowFlags GetWindowFlags(WindowState state) |
| 69 | + { |
| 70 | + switch (state) |
| 71 | + { |
| 72 | + case WindowState.Normal: |
| 73 | + return 0; |
| 74 | + case WindowState.FullScreen: |
| 75 | + return SDL_WindowFlags.Fullscreen; |
| 76 | + case WindowState.Maximized: |
| 77 | + return SDL_WindowFlags.Maximized; |
| 78 | + case WindowState.Minimized: |
| 79 | + return SDL_WindowFlags.Minimized; |
| 80 | + case WindowState.BorderlessFullScreen: |
| 81 | + return SDL_WindowFlags.FullScreenDesktop; |
| 82 | + case WindowState.Hidden: |
| 83 | + return SDL_WindowFlags.Hidden; |
| 84 | + default: |
| 85 | + throw new VeldridException("Invalid WindowState: " + state); |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments