Switch from SDL_WINDOW_FULLSCREEN to SDL_WINDOW_FULLSCREEN_DESKTOP.

SDL_WINDOW_FULLSCREEN changes the display resolution if the requested
resolution is different to the actual resultion. SDL_WINDOW_FULLSCREEN_
DESKTOP doesn't do that, it places a smaller or bigger render area
somewhere inside the fullscreen area. This is somewhat nicer with modern
high resolution flatscreens.

This commit changes vid_fullscreen 1 from SDL_WINDOW_FULLSCREEN to
SDL_WINDOW_FULLSCREEN_DESKTOP. Additional vid_fullscreen 2 is
implemented, it uses SDL_WINDOW_FULLSCREEN to create the fullscreen
area.

TL;DR: Use vid_fullscreen 1 to keep the current resolution or use
vid_fullscreen 2 to switch the resolution.

Implementation details: The whole fullscreen stuff is a horrible mess.
Like generations of hackers before me I'm not desperated enough to clean
it up. GLimp_InitGraphics() is modified to take the fullscreen mode as
an integer and not as a boolean. That's a change to the renderer API.
In GLimp_InitGraphics() the needed SDL fullscreen mode flag is
determined once at the top and just used further down below. That saves
dome SDL1 <-> SDL2 compatibility cruft. IsFullscreen() was modified to
return the actual fullscreen mode and not just if fullscreen is enabled.
This commit is contained in:
Yamagi Burmeister 2017-08-01 10:08:24 +02:00
parent 60bef10748
commit 908fd30148
5 changed files with 36 additions and 18 deletions

View file

@ -315,7 +315,7 @@ qboolean ref_active = false; /* Is the refresher being used? */
void Key_MarkAllUp(void);
extern int GLimp_Init(void);
extern qboolean GLimp_InitGraphics(qboolean fullscreen, int *pwidth, int *pheight);
extern qboolean GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight);
extern void VID_ShutdownWindow(void);
qboolean

View file

@ -55,7 +55,6 @@ static SDL_Surface* window = NULL;
#if SDL_VERSION_ATLEAST(2, 0, 0)
// some compatibility defines
#define SDL_SRCCOLORKEY SDL_TRUE
#define SDL_FULLSCREEN SDL_WINDOW_FULLSCREEN
#define SDL_OPENGL SDL_WINDOW_OPENGL
#endif
@ -175,10 +174,16 @@ SetSDLIcon()
}
#endif /* SDL 1.2 */
static qboolean IsFullscreen()
static int IsFullscreen()
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
return !!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN);
if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) {
return 1;
} else if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
return 2;
} else {
return 0;
}
#else
return !!(window->flags & SDL_FULLSCREEN);
#endif
@ -226,12 +231,25 @@ static qboolean GetWindowSize(int* w, int* h)
* Initializes the OpenGL window
*/
qboolean
GLimp_InitGraphics(qboolean fullscreen, int *pwidth, int *pheight)
GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
{
int flags;
int curWidth, curHeight;
int width = *pwidth;
int height = *pheight;
unsigned int fs_flag;
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (fullscreen == 1) {
fs_flag = SDL_WINDOW_FULLSCREEN_DESKTOP;
} else if (fullscreen == 2) {
fs_flag = SDL_WINDOW_FULLSCREEN;
} else {
fs_flag = 0;
}
#else
fs_flag = SDL_FULLSCREEN;
#endif
if (GetWindowSize(&curWidth, &curHeight) && (curWidth == width) && (curHeight == height))
{
@ -239,7 +257,7 @@ GLimp_InitGraphics(qboolean fullscreen, int *pwidth, int *pheight)
if (fullscreen != IsFullscreen())
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetWindowFullscreen(window, fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
SDL_SetWindowFullscreen(window, fs_flag);
#else
SDL_WM_ToggleFullScreen(window);
#endif
@ -279,9 +297,9 @@ GLimp_InitGraphics(qboolean fullscreen, int *pwidth, int *pheight)
return false;
}
if (fullscreen)
if (fs_flag)
{
flags |= SDL_FULLSCREEN;
flags |= fs_flag;
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
@ -301,7 +319,7 @@ GLimp_InitGraphics(qboolean fullscreen, int *pwidth, int *pheight)
{
Com_Printf("SDL SetVideoMode failed: %s\n", SDL_GetError());
Com_Printf("Reverting to %s gl_mode %i (%ix%i) without MSAA.\n",
(flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed",
(flags & fs_flag) ? "fullscreen" : "windowed",
(int) Cvar_VariableValue("gl_mode"), width, height);
/* Try to recover */
@ -310,7 +328,7 @@ GLimp_InitGraphics(qboolean fullscreen, int *pwidth, int *pheight)
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
}
}
else if (width != 640 || height != 480 || (flags & SDL_FULLSCREEN))
else if (width != 640 || height != 480 || (flags & fs_flag))
{
Com_Printf("SDL SetVideoMode failed: %s\n", SDL_GetError());
Com_Printf("Reverting to windowed gl_mode 4 (640x480).\n");
@ -321,7 +339,7 @@ GLimp_InitGraphics(qboolean fullscreen, int *pwidth, int *pheight)
VID_NewWindow(width, height);
*pwidth = width = 640;
*pheight = height = 480;
flags &= ~SDL_FULLSCREEN;
flags &= ~fs_flag;
}
else
{

View file

@ -234,7 +234,7 @@ typedef struct
void (IMPORT *Vid_ShutdownWindow)(void);
int (IMPORT *GLimp_Init)(void);
qboolean (IMPORT *GLimp_InitGraphics)(qboolean fullscreen, int *pwidth, int *pheight);
qboolean (IMPORT *GLimp_InitGraphics)(int fullscreen, int *pwidth, int *pheight);
} refimport_t;
// this is the only function actually exported at the linker level

View file

@ -1278,7 +1278,7 @@ R_Register(void)
* Changes the video mode
*/
static int
SetMode_impl(int *pwidth, int *pheight, int mode, qboolean fullscreen)
SetMode_impl(int *pwidth, int *pheight, int mode, int fullscreen)
{
R_Printf(PRINT_ALL, "setting mode %d:", mode);
@ -1304,9 +1304,9 @@ qboolean
R_SetMode(void)
{
rserr_t err;
qboolean fullscreen;
int fullscreen;
fullscreen = vid_fullscreen->value;
fullscreen = (int)vid_fullscreen->value;
vid_fullscreen->modified = false;
gl_mode->modified = false;

View file

@ -339,7 +339,7 @@ enum
};
static int
SetMode_impl(int *pwidth, int *pheight, int mode, qboolean fullscreen)
SetMode_impl(int *pwidth, int *pheight, int mode, int fullscreen)
{
R_Printf(PRINT_ALL, "setting mode %d:", mode);
@ -365,9 +365,9 @@ static qboolean
GL3_SetMode(void)
{
int err;
qboolean fullscreen;
int fullscreen;
fullscreen = vid_fullscreen->value;
fullscreen = (int)vid_fullscreen->value;
vid_fullscreen->modified = false;
gl_mode->modified = false;