From 0babeb62c184d659b9957cdaafcded9876c4c5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Fri, 15 Nov 2024 23:19:08 +0100 Subject: [PATCH 1/9] cmake: optionally disable the building of rendering libraries default options are kept as before, i.e., all but GLES1 are enabled by default --- CMakeLists.txt | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8df4dc97f..64a5d61c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,11 @@ option(CURL_SUPPORT "cURL support" ON) option(OPENAL_SUPPORT "OpenAL support" ON) option(SYSTEMWIDE_SUPPORT "Enable systemwide installation of game assets" OFF) option(SDL3_SUPPORT "Build against SDL 3 instead of SDL2" OFF) +option(GL1_RENDERER "Build the GL3 renderer" ON) +option(GL3_RENDERER "Build the GL3 renderer" ON) +option(GLES1_RENDERER "Build the GLES1 renderer" OFF) +option(GLES3_RENDERER "Build the GLES3 renderer" ON) +option(SOFT_RENDERER "Build the software renderer" ON) set(SYSTEMDIR "" CACHE STRING "Override the system default directory") @@ -189,11 +194,13 @@ else() list(APPEND yquake2SDLLinkerFlags ${SDL2_LIBRARY}) endif() -# We need an OpenGL implementation. -set(OpenGL_GL_PREFERENCE GLVND) -find_package(OpenGL REQUIRED) -list(APPEND yquake2IncludeDirectories ${OPENGL_INCLUDE_DIR}) -list(APPEND yquake2OpenGLLinkerFlags ${OPENGL_LIBRARIES}) +if(GL1_RENDERER OR GL3_RENDERER OR GLES1_RENDERER OR GLES2_RENDERER) + # We need an OpenGL implementation. + set(OpenGL_GL_PREFERENCE GLVND) + find_package(OpenGL REQUIRED) + list(APPEND yquake2IncludeDirectories ${OPENGL_INCLUDE_DIR}) + list(APPEND yquake2OpenGLLinkerFlags ${OPENGL_LIBRARIES}) +endif() # backtrace lookup # Some systems like Linux has it within the libc some like the BSD, Haiku ... @@ -781,6 +788,8 @@ else() # single-config, like normal Makefiles endif() target_link_libraries(game ${yquake2LinkerFlags}) +if(${GL1_RENDERER}) + # Build the GL1 dynamic library add_library(ref_gl1 MODULE ${GL1-Source} ${GL1-Header} ${REF-Platform-Specific-Source}) set_target_properties(ref_gl1 PROPERTIES @@ -795,6 +804,10 @@ if(SDL3_SUPPORT) target_link_libraries(ref_gl1 SDL3::SDL3) endif() +endif() + +if(${GL3_RENDERER}) + # Build the GL3 dynamic library add_library(ref_gl3 MODULE ${GL3-Source} ${Glad-GL3-Source} ${GL3-Header} ${Glad-GL3-Header} ${REF-Platform-Specific-Source}) set_target_properties(ref_gl3 PROPERTIES @@ -809,6 +822,10 @@ if(SDL3_SUPPORT) target_link_libraries(ref_gl3 SDL3::SDL3) endif() +endif() + +if(${GLES3_RENDERER}) + # Build the GLES3 dynamic library add_library(ref_gles3 MODULE ${GL3-Source} ${Glad-GLES3-Source} ${GL3-Header} ${Glad-GLES3-Header} ${REF-Platform-Specific-Source}) set_target_properties(ref_gles3 PROPERTIES @@ -825,6 +842,10 @@ if(SDL3_SUPPORT) target_link_libraries(ref_gles3 SDL3::SDL3) endif() +endif() + +if(${SOFT_RENDERER}) + # Build the soft renderer dynamic library add_library(ref_soft MODULE ${SOFT-Source} ${SOFT-Header} ${REF-Platform-Specific-Source}) set_target_properties(ref_soft PROPERTIES @@ -838,7 +859,9 @@ if(SDL3_SUPPORT) target_link_libraries(ref_soft SDL3::SDL3) endif() -if(FALSE) +endif() + +if(${GLES1_RENDERER}) # Build the GLES1 dynamic library add_library(ref_gles1 MODULE ${GL1-Source} ${Glad-GLES1-Source} ${GL1-Header} ${Glad-GLES1-Header} ${REF-Platform-Specific-Source}) From ccc9027b1addcae6fe2f7483a166473c8820e4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Fri, 15 Nov 2024 23:34:44 +0100 Subject: [PATCH 2/9] ref_soft: if SDL renderer does not support SDL_RENDERER_ACCELERATED, fallback to SDL_RENDERER_SOFTWARE --- src/client/refresh/soft/sw_main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index a45f5ebd0..ec61a763b 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -1914,6 +1914,10 @@ RE_InitContext(void *win) SDL_SetRenderVSync(renderer, 1); #else renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if(!renderer) + { + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC); + } #endif } else @@ -1922,6 +1926,10 @@ RE_InitContext(void *win) renderer = SDL_CreateRenderer(window, NULL); #else renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if(!renderer) + { + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE); + } #endif } From 0ea0dbf4ac4e93479c6667b31f48ce398a7b9f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sat, 16 Nov 2024 15:30:18 +0100 Subject: [PATCH 3/9] ref_soft: check if renderer and texture are created correctly during context initialization --- src/client/refresh/soft/sw_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index ec61a763b..c9d51b75e 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -1932,6 +1932,10 @@ RE_InitContext(void *win) } #endif } + if(!renderer) { + Com_Printf("Can't create renderer: %s\n", SDL_GetError()); + return false; + } /* Select the color for drawing. It is set to black here. */ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); @@ -1974,7 +1978,10 @@ RE_InitContext(void *win) #endif SDL_TEXTUREACCESS_STREAMING, vid_buffer_width, vid_buffer_height); - + if(!texture) { + Com_Printf("Can't create texture: %s\n", SDL_GetError()); + return false; + } R_InitGraphics(vid_buffer_width, vid_buffer_height); SWimp_CreateRender(vid_buffer_width, vid_buffer_height); From c0eda78e436634a079582536737634315ededd02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sat, 16 Nov 2024 15:37:43 +0100 Subject: [PATCH 4/9] sdl2: avoid spamming warnings when setting relative mouse mode fails --- src/client/vid/glimp_sdl2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/vid/glimp_sdl2.c b/src/client/vid/glimp_sdl2.c index d2a725915..6a1333929 100644 --- a/src/client/vid/glimp_sdl2.c +++ b/src/client/vid/glimp_sdl2.c @@ -720,13 +720,15 @@ GLimp_ShutdownGraphics(void) void GLimp_GrabInput(qboolean grab) { + static qboolean seen_error = false; if(window != NULL) { SDL_SetWindowGrab(window, grab ? SDL_TRUE : SDL_FALSE); } - if(SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE) < 0) + if(SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE) < 0 && !seen_error) { + seen_error = true; 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"); } From 38843f0f3303ab71ce5c819d8f5f06fd228e2baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sat, 16 Nov 2024 15:42:54 +0100 Subject: [PATCH 5/9] backends: when failing to determine executable path, print full path to cwd instead of just ./ --- src/backends/generic/misc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backends/generic/misc.c b/src/backends/generic/misc.c index f0f47213d..7a8460e85 100644 --- a/src/backends/generic/misc.c +++ b/src/backends/generic/misc.c @@ -156,8 +156,9 @@ const char *Sys_GetBinaryDir(void) SetExecutablePath(exeDir); if (exeDir[0] == '\0') { - Com_Printf("Couldn't determine executable path. Using ./ instead.\n"); - Q_strlcpy(exeDir, "./", sizeof(exeDir)); + getcwd(exeDir, sizeof(exeDir)); + strcat(exeDir, "/"); + Com_Printf("Couldn't determine executable path. Using %s instead.\n", exeDir); } else { // cut off executable name char *lastSlash = strrchr(exeDir, '/'); From 9700eb6baf84d688ad919d45e41812164834e564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sun, 17 Nov 2024 01:34:07 +0100 Subject: [PATCH 6/9] cmake: only gl1 renderer needs to be specifically linked --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64a5d61c3..1892d1f66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,7 +194,7 @@ else() list(APPEND yquake2SDLLinkerFlags ${SDL2_LIBRARY}) endif() -if(GL1_RENDERER OR GL3_RENDERER OR GLES1_RENDERER OR GLES2_RENDERER) +if(GL1_RENDERER) # We need an OpenGL implementation. set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) From e87bcfb906e8c17af58bd3235a59a369d08e2edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sat, 23 Nov 2024 13:11:19 +0100 Subject: [PATCH 7/9] backends: ensure unistd.h is included when compiling for apple OSes --- src/backends/generic/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/generic/misc.c b/src/backends/generic/misc.c index 7a8460e85..f65d912ec 100644 --- a/src/backends/generic/misc.c +++ b/src/backends/generic/misc.c @@ -29,7 +29,7 @@ #include "../../common/header/shared.h" -#if defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) +#if defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(__APPLE__) #include // readlink(), amongst others #endif From 24888cc3c11e2230e10c1cc42c0af0e8876ae952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sat, 23 Nov 2024 13:12:36 +0100 Subject: [PATCH 8/9] backends: add portable variant of getcwd --- src/backends/generic/misc.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/backends/generic/misc.c b/src/backends/generic/misc.c index f65d912ec..00607a0f5 100644 --- a/src/backends/generic/misc.c +++ b/src/backends/generic/misc.c @@ -145,6 +145,31 @@ static void SetExecutablePath(char* exePath) #endif } +qboolean Sys_GetCwd(char *buf, size_t size) +{ +#ifdef _WIN32 + WCHAR wpath[PATH_MAX]; + DWORD len; + + if (_wgetcwd(wpath, PATH_MAX) == NULL) + { + return false; + } + len = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, buf, size, NULL, NULL); + if (len <= 0 || len == size) + { + return false; + } +#else + if (getcwd(buf, size) == NULL) + { + return false; + } +#endif + return Q_strlcat(buf, "/", size) == 1; +} + + const char *Sys_GetBinaryDir(void) { static char exeDir[PATH_MAX] = {0}; @@ -156,8 +181,10 @@ const char *Sys_GetBinaryDir(void) SetExecutablePath(exeDir); if (exeDir[0] == '\0') { - getcwd(exeDir, sizeof(exeDir)); - strcat(exeDir, "/"); + if (Sys_GetCwd(exeDir, sizeof(exeDir)) == false) + { + Q_strlcpy(exeDir, "./", sizeof(exeDir)); + } Com_Printf("Couldn't determine executable path. Using %s instead.\n", exeDir); } else { // cut off executable name From e21e057b0481974bd1c2196446dc4af46b02e417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sat, 23 Nov 2024 13:36:13 +0100 Subject: [PATCH 9/9] backends: ensure _wgetcwd() is declared when compiling for windows --- src/backends/generic/misc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backends/generic/misc.c b/src/backends/generic/misc.c index 00607a0f5..68683b34b 100644 --- a/src/backends/generic/misc.c +++ b/src/backends/generic/misc.c @@ -39,6 +39,7 @@ #ifdef _WIN32 #include // GetModuleFileNameA() +#include // _wgetcwd() #endif #ifdef __APPLE__