mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-10 22:35:38 +00:00
Implemented resolution change workaround on SDL2
SDL2 does not support changing display resolutions independently of an SDL window. As a workaround, if the user uses ChangeResolution and then makes a GameWindow fullscreen, we use old-style SDL fullscreen which changes the resolution. If the user makes a GameWindow fullscreen without calling ChangeResolution first, we use the new fullscreen-desktop mode to match the other OpenTK backends.
This commit is contained in:
parent
19d9beb6a4
commit
694869dc05
|
@ -94,24 +94,14 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
|
||||
{
|
||||
// Todo: we need a temporary window to change resolutions, most probably
|
||||
Trace.WriteLine("SDL2 driver does not implement TryChangeResolution");
|
||||
Sdl2Factory.UseFullscreenDesktop = false;
|
||||
return true;
|
||||
|
||||
//SDL2.SDL_DisplayMode desired, closest;
|
||||
//desired.w = resolution.Width;
|
||||
//desired.h = resolution.Height;
|
||||
//desired.format = SDL.SDL_PIXELFORMAT_BGRA8888;
|
||||
|
||||
//SDL2.SDL_GetClosestDisplayMode((int)device.Id, ref desired, out closest);
|
||||
//SDL2.SDL_SetWindowDisplayMode(IntPtr.Zero, ref closest);
|
||||
}
|
||||
|
||||
public override bool TryRestoreResolution(DisplayDevice device)
|
||||
{
|
||||
Trace.WriteLine("SDL2 driver does not support TryRestoreResolution");
|
||||
Sdl2Factory.UseFullscreenDesktop = true;
|
||||
return true;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -37,8 +37,21 @@ namespace OpenTK.Platform.SDL2
|
|||
readonly IInputDriver2 InputDriver = new Sdl2InputDriver();
|
||||
bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to use SDL2 fullscreen-desktop mode
|
||||
/// for fullscreen windows. When true, then GameWindow instances will not change
|
||||
/// DisplayDevice resolutions when going fullscreen. When false, fullscreen GameWindows
|
||||
/// will change the device resolution to match their size.
|
||||
/// </summary>
|
||||
/// <remarks>>
|
||||
/// This is a workaround for the lack of ChangeResolution support in SDL2.
|
||||
/// When and if this changes upstream, we should remove this code.
|
||||
/// </remarks>
|
||||
public static bool UseFullscreenDesktop { get; set; }
|
||||
|
||||
public Sdl2Factory()
|
||||
{
|
||||
UseFullscreenDesktop = true;
|
||||
}
|
||||
|
||||
#region IPlatformFactory implementation
|
||||
|
|
|
@ -112,8 +112,11 @@ namespace OpenTK.Platform.SDL2
|
|||
switch (flags)
|
||||
{
|
||||
case GameWindowFlags.Fullscreen:
|
||||
return WindowFlags.FULLSCREEN_DESKTOP;
|
||||
|
||||
if (Sdl2Factory.UseFullscreenDesktop)
|
||||
return WindowFlags.FULLSCREEN_DESKTOP;
|
||||
else
|
||||
return WindowFlags.FULLSCREEN;
|
||||
|
||||
default:
|
||||
return WindowFlags.Default;
|
||||
}
|
||||
|
@ -626,13 +629,15 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
case WindowState.Fullscreen:
|
||||
RestoreWindow();
|
||||
if (SDL.SetWindowFullscreen(window.Handle, (uint)WindowFlags.FULLSCREEN_DESKTOP) < 0)
|
||||
bool success = Sdl2Factory.UseFullscreenDesktop ?
|
||||
SDL.SetWindowFullscreen(window.Handle, (uint)WindowFlags.FULLSCREEN_DESKTOP) < 0 :
|
||||
SDL.SetWindowFullscreen(window.Handle, (uint)WindowFlags.FULLSCREEN) < 0;
|
||||
|
||||
if (!success)
|
||||
{
|
||||
if (SDL.SetWindowFullscreen(window.Handle, (uint)WindowFlags.FULLSCREEN) < 0)
|
||||
{
|
||||
Debug.Print("SDL2 failed to enter fullscreen mode: {0}", SDL.GetError());
|
||||
}
|
||||
}
|
||||
|
||||
SDL.RaiseWindow(window.Handle);
|
||||
// There is no "fullscreen" message in the event loop
|
||||
// so we have to mark that ourselves
|
||||
|
|
Loading…
Reference in a new issue