From 2099626b7b5d84fa7aab1dfc9f667ed59a013e61 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Wed, 18 Jul 2018 21:15:42 +0200 Subject: [PATCH] Remove SDL 1.2 support from the client side render backend. --- src/backends/sdl/refresh.c | 181 +++++++------------------------------ 1 file changed, 35 insertions(+), 146 deletions(-) diff --git a/src/backends/sdl/refresh.c b/src/backends/sdl/refresh.c index 278b8d22..21dda1fe 100644 --- a/src/backends/sdl/refresh.c +++ b/src/backends/sdl/refresh.c @@ -37,27 +37,10 @@ #include "../../common/header/common.h" /* CVar_*, qboolean (through shared.h) */ #include "../../client/header/ref.h" -#ifdef SDL2 #include #include -#else // SDL1.2 -#include -#endif //SDL2 - -#if SDL_VERSION_ATLEAST(2, 0, 0) static SDL_Window* window = NULL; -#else -static SDL_Surface* window = NULL; -#endif - - -#if SDL_VERSION_ATLEAST(2, 0, 0) -// some compatibility defines -#define SDL_SRCCOLORKEY SDL_TRUE -#define SDL_OPENGL SDL_WINDOW_OPENGL -#endif - cvar_t *vid_displayrefreshrate; /* @@ -74,21 +57,15 @@ GLimp_Init(void) if (SDL_Init(SDL_INIT_VIDEO) == -1) { Com_Printf("Couldn't init SDL video: %s.\n", SDL_GetError()); + return false; } SDL_version version; -#if SDL_VERSION_ATLEAST(2, 0, 0) SDL_GetVersion(&version); - const char* driverName = SDL_GetCurrentVideoDriver(); -#else - char driverName[64]; - SDL_VideoDriverName(driverName, sizeof(driverName)); - version = *SDL_Linked_Version(); -#endif Com_Printf("SDL version is: %i.%i.%i\n", (int)version.major, (int)version.minor, (int)version.patch); - Com_Printf("SDL video driver is \"%s\".\n", driverName); + Com_Printf("SDL video driver is \"%s\".\n", SDL_GetCurrentVideoDriver()); } return true; @@ -97,10 +74,7 @@ GLimp_Init(void) /* * Sets the window icon */ -#if SDL_VERSION_ATLEAST(2, 0, 0) - -/* The 64x64 32bit window icon */ -#include "icon/q2icon64.h" +#include "icon/q2icon64.h" // 64x64 32 Bit static void SetSDLIcon() @@ -108,6 +82,7 @@ SetSDLIcon() /* these masks are needed to tell SDL_CreateRGBSurface(From) to assume the data it gets is byte-wise RGB(A) data */ Uint32 rmask, gmask, bmask, amask; + #if SDL_BYTEORDER == SDL_BIG_ENDIAN int shift = (q2icon64.bytes_per_pixel == 3) ? 8 : 0; rmask = 0xff000000 >> shift; @@ -124,113 +99,53 @@ SetSDLIcon() SDL_Surface* icon = SDL_CreateRGBSurfaceFrom((void*)q2icon64.pixel_data, q2icon64.width, q2icon64.height, q2icon64.bytes_per_pixel*8, q2icon64.bytes_per_pixel*q2icon64.width, rmask, gmask, bmask, amask); - SDL_SetWindowIcon(window, icon); - SDL_FreeSurface(icon); } -#else /* SDL 1.2 */ - -/* The window icon */ -#include "icon/q2icon.xbm" - -static void -SetSDLIcon() -{ - SDL_Surface *icon; - SDL_Color transColor, solidColor; - Uint8 *ptr; - int i; - int mask; - - icon = SDL_CreateRGBSurface(SDL_SWSURFACE, - q2icon_width, q2icon_height, 8, - 0, 0, 0, 0); - - if (icon == NULL) - { - return; - } - - SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0); - - transColor.r = 255; - transColor.g = 255; - transColor.b = 255; - - solidColor.r = 0; - solidColor.g = 0; - solidColor.b = 0; - - SDL_SetColors(icon, &transColor, 0, 1); - SDL_SetColors(icon, &solidColor, 1, 1); - - ptr = (Uint8 *)icon->pixels; - - for (i = 0; i < sizeof(q2icon_bits); i++) - { - for (mask = 1; mask != 0x100; mask <<= 1) - { - *ptr = (q2icon_bits[i] & mask) ? 1 : 0; - ptr++; - } - } - - SDL_WM_SetIcon(icon, NULL); - - SDL_FreeSurface(icon); -} -#endif /* SDL 1.2 */ - static int IsFullscreen() { -#if SDL_VERSION_ATLEAST(2, 0, 0) - if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) { + if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) + { return 1; - } else if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) { + } + else if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) + { return 2; - } else { + } + else + { return 0; } -#else - return !!(window->flags & SDL_FULLSCREEN); -#endif } static qboolean CreateSDLWindow(int flags, int w, int h) { -#if SDL_VERSION_ATLEAST(2, 0, 0) int windowPos = SDL_WINDOWPOS_UNDEFINED; - // TODO: support fullscreen on different displays with SDL_WINDOWPOS_UNDEFINED_DISPLAY(displaynum) + window = SDL_CreateWindow("Yamagi Quake II", windowPos, windowPos, w, h, flags); return window != NULL; -#else - window = SDL_SetVideoMode(w, h, 0, flags); - SDL_EnableUNICODE(SDL_TRUE); - return window != NULL; -#endif } static qboolean GetWindowSize(int* w, int* h) { if(window == NULL || w == NULL || h == NULL) + { return false; + } -#if SDL_VERSION_ATLEAST(2, 0, 0) SDL_DisplayMode m; + if(SDL_GetWindowDisplayMode(window, &m) != 0) { Com_Printf("Can't get Displaymode: %s\n", SDL_GetError()); + return false; } + *w = m.w; *h = m.h; -#else - *w = window->w; - *h = window->h; -#endif return true; } @@ -249,17 +164,14 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) int height = *pheight; unsigned int fs_flag = 0; -#if SDL_VERSION_ATLEAST(2, 0, 0) - if (fullscreen == 1) { + if (fullscreen == 1) + { fs_flag = SDL_WINDOW_FULLSCREEN_DESKTOP; - } else if (fullscreen == 2) { + } + else if (fullscreen == 2) + { fs_flag = SDL_WINDOW_FULLSCREEN; } -#else - if (fullscreen) { - fs_flag = SDL_FULLSCREEN; - } -#endif // only do this if we already have a working window and fully initialized rendering backend // (GLimp_InitGraphics() is also called when recovering if creating GL context fails or the one we got is unusable) @@ -268,12 +180,7 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) /* If we want fullscreen, but aren't */ if (fullscreen != IsFullscreen()) { -#if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetWindowFullscreen(window, fs_flag); -#else - SDL_WM_ToggleFullScreen(window); -#endif - Cvar_SetValue("vid_fullscreen", fullscreen); } @@ -287,14 +194,9 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) /* Is the surface used? */ if (window) { -#if SDL_VERSION_ATLEAST(2, 0, 0) - re.ShutdownWindow(true); - SDL_DestroyWindow(window); -#else - SDL_FreeSurface(window); -#endif + window = NULL; } @@ -303,7 +205,8 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) // let renderer prepare things (set OpenGL attributes) flags = re.PrepareForWindow(); - if(flags == -1) + + if (flags == -1) { // hopefully PrepareForWindow() logged an error return false; @@ -314,10 +217,8 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) flags |= fs_flag; } -#if !SDL_VERSION_ATLEAST(2, 0, 0) /* Set window icon - For SDL1.2, this must be done before creating the window */ SetSDLIcon(); -#endif cvar_t *gl_msaa_samples = Cvar_Get("gl_msaa_samples", "0", CVAR_ARCHIVE); @@ -325,7 +226,7 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) { if (!CreateSDLWindow(flags, width, height)) { - if((flags & SDL_OPENGL) && gl_msaa_samples->value) + if((flags & SDL_WINDOW_OPENGL) && gl_msaa_samples->value) { Com_Printf("SDL SetVideoMode failed: %s\n", SDL_GetError()); Com_Printf("Reverting to %s r_mode %i (%ix%i) without MSAA.\n", @@ -334,6 +235,7 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) /* Try to recover */ Cvar_SetValue("gl_msaa_samples", 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); } @@ -345,7 +247,9 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) /* Try to recover */ Cvar_SetValue("r_mode", 4); Cvar_SetValue("vid_fullscreen", 0); + VID_NewWindow(width, height); + *pwidth = width = 640; *pheight = height = 480; flags &= ~fs_flag; @@ -368,11 +272,8 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) return false; } - /* Note: window title is now set in re.InitContext() to include renderer name */ -#if SDL_VERSION_ATLEAST(2, 0, 0) /* Set the window icon - For SDL2, this must be done after creating the window */ SetSDLIcon(); -#endif /* No cursor */ SDL_ShowCursor(0); @@ -387,19 +288,16 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) */ void GLimp_GrabInput(qboolean grab) { -#if SDL_VERSION_ATLEAST(2, 0, 0) if(window != NULL) { SDL_SetWindowGrab(window, grab ? SDL_TRUE : SDL_FALSE); } + if(SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE) < 0) { Com_Printf("WARNING: Setting Relative Mousemode failed, reason: %s\n", SDL_GetError()); Com_Printf(" You should probably update to SDL 2.0.3 or newer!\n"); } -#else - SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF); -#endif } int glimp_refreshRate = -1; @@ -414,15 +312,14 @@ int GLimp_GetRefreshRate(void) glimp_refreshRate = ceil(vid_displayrefreshrate->value); } -#if SDL_VERSION_ATLEAST(2, 0, 0) - // do this only once, assuming people don't change their display settings // or plug in new displays while the game is running if (glimp_refreshRate == -1) { SDL_DisplayMode mode; - // TODO: probably refreshRate should be reset to -1 if window is moved + int i = SDL_GetWindowDisplayIndex(window); + if(i >= 0 && SDL_GetCurrentDisplayMode(i, &mode) == 0) { glimp_refreshRate = mode.refresh_rate; @@ -442,10 +339,6 @@ int GLimp_GetRefreshRate(void) glimp_refreshRate++; return glimp_refreshRate; -#else - // Asume 60hz. - return 60; -#endif } /* @@ -458,15 +351,11 @@ VID_ShutdownWindow(void) { /* cleanly ungrab input (needs window) */ GLimp_GrabInput(false); - -#if SDL_VERSION_ATLEAST(2, 0, 0) SDL_DestroyWindow(window); -#else - SDL_FreeSurface(window); -#endif + + window = NULL; } - window = NULL; // make sure that after vid_restart the refreshrate will be queried from SDL2 again. glimp_refreshRate = -1;