From 9b26f1fdcbe4dc38d8b26d0b982398f0e854cbc6 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 25 Sep 2025 16:04:17 +0200 Subject: [PATCH] make the game fail loud if some critical gl function cant be loaded also add safety to the portal stencil stuff, if that fails. everything gl2.0 and newer is not critical and will just prevent some effects from working so that does not need to error loudly TODO: perhaps actually port renderer switching so this instead will fallback to software if smth fails this late during gl initalization --- src/hardware/hw_main.cpp | 2 +- src/hardware/r_opengl/r_opengl.c | 104 +++++++++++++++++-------------- src/hardware/r_opengl/r_opengl.h | 2 + src/sdl/ogl_sdl.c | 7 +-- 4 files changed, 63 insertions(+), 52 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 8dec512dc..d634ed5d9 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -2203,7 +2203,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom static inline boolean HWR_UsePortals(void) { - return cv_glportals.value && gl_maphasportals; + return supportstencil && cv_glportals.value && gl_maphasportals; } // From PrBoom: diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 811f61c40..5bd9268ad 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -35,13 +35,10 @@ #include "r_opengl.h" #include "r_vbo.h" -#include "../hw_batching.h" #include "../hw_clip.h" #include "../hw_main.h" #include "../hw_shaders.h" -#include "../../f_finale.h" -#include "../../r_local.h" // For rendertimefrac, used for the leveltime shader uniform #include "../../i_video.h" #ifdef GLDEBUGMESSAGE @@ -167,6 +164,9 @@ GL_DEPTH_STENCIL_ATTACHMENT GL_DEPTH_ATTACHMENT_EXT static void GL_Framebuffer_DeleteAttachments(void); #endif +// needed for glportals +boolean supportstencil = false; + // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels // These need to start at 0 and be set to their number, and be reset to 0 when deleted so that Intel GPUs @@ -244,7 +244,6 @@ FUNCPRINTF void GL_DBG_Printf(const char *format, ...) // Returns : // -----------------+ - static void GL_MSG_Warning(const char *format, ...) { char str[4096] = ""; @@ -600,6 +599,7 @@ boolean SetupGLfunc(void) if (!p##func) \ { \ GL_MSG_Warning("failed to get OpenGL function: %s", #func); \ + return false; \ } \ GetGLfunc(glClearColor) @@ -730,8 +730,6 @@ static INT32 gl_enable_screen_textures = 2; static GLint gl_portal_stencil_level = 0; -static INT32 gl_portal_mode = HWD_PORTAL_NORMAL; - // 13062019 typedef enum { @@ -827,13 +825,17 @@ static int GLFramebuffer_CheckExt(void) } #endif + void SetupGLFunc4(void) { +// critical functions for operation #define GetGLfunc(func) \ p##func = GetGLFunc(#func); \ if (!p##func) \ { \ - GL_MSG_Warning("failed to get OpenGL function: %s", #func); \ + I_Error("Failed to get critical OpenGL function: %s. Possible reasons include:\n" \ + "- GPU vendor has dropped OpenGL support on your GPU and OS. (Old GPU?)\n" \ + "- GPU drivers are missing or broken. You may need to update your drivers.", #func); \ } \ /* 1.2 funcs */ @@ -851,6 +853,15 @@ void SetupGLFunc4(void) GetGLfunc(glBufferData); GetGLfunc(glDeleteBuffers); GetGLfunc(glColorPointer); +#undef GetGLfunc + +// noncritical functions for operation +#define GetGLfunc(func) \ + p##func = GetGLFunc(#func); \ + if (!p##func) \ + { \ + GL_MSG_Warning("failed to get OpenGL function: %s", #func); \ + } \ /* 2.0 funcs */ GetGLfunc(glBlendEquation); @@ -885,7 +896,23 @@ void SetupGLFunc4(void) GetGLfunc(glDebugMessageCallback); #endif + if (pglStencilFuncSeparate && pglStencilOpSeparate) + { + supportstencil = true; + } +#undef GetGLfunc + #ifdef USE_FBO_OGL +#define GetGLfunc(func) \ + p##func = GetGLFunc(#func); \ + if (!p##func) \ + { \ + GL_MSG_Warning("failed to get OpenGL FBO function: %s\n", #func); \ + GL_DBG_Printf("\nFBO: No framebuffer object support\n"); \ + supportFBO = false; \ + return; \ + } \ + const int fbocheck = GLFramebuffer_CheckExt(); if (fbocheck != FBO_NONE) @@ -903,17 +930,7 @@ void SetupGLFunc4(void) GetGLfunc(glRenderbufferStorage); GetGLfunc(glFramebufferRenderbuffer); - // check if ALL functions are availible - // what a mouthful - if (pglGenFramebuffers && pglBindFramebuffer && - pglDeleteFramebuffers && pglFramebufferTexture2D && - pglCheckFramebufferStatus && pglGenRenderbuffers && - pglBindRenderbuffer && pglDeleteRenderbuffers && - pglRenderbufferStorage && pglFramebufferRenderbuffer) - { - supportFBO = fbocheck; - GL_DBG_Printf("\nFBO: ARB extensions found\n"); - } + GL_DBG_Printf("\nFBO: ARB extensions found\n"); } else if (fbocheck == FBO_EXT || fbocheck == FBO_EXT_STENCIL) // uh oh only support for EXT prefix fbos... { @@ -928,40 +945,31 @@ void SetupGLFunc4(void) GetGLfunc(glRenderbufferStorageEXT); GetGLfunc(glFramebufferRenderbufferEXT); - // check if ALL functions are availible - // what a mouthful - if (pglGenFramebuffersEXT && pglBindFramebufferEXT && - pglDeleteFramebuffersEXT && pglFramebufferTexture2DEXT && - pglCheckFramebufferStatusEXT && pglGenRenderbuffersEXT && - pglBindRenderbufferEXT && pglDeleteRenderbuffersEXT && - pglRenderbufferStorageEXT && pglFramebufferRenderbufferEXT) - { - // remapping galore huehue - // do this so we dont have to dupe half our code - pglGenFramebuffers = pglGenFramebuffersEXT; - pglBindFramebuffer = pglBindFramebufferEXT; - pglDeleteFramebuffers = pglDeleteFramebuffersEXT; - pglFramebufferTexture2D = pglFramebufferTexture2DEXT; - pglCheckFramebufferStatus = pglCheckFramebufferStatusEXT; - pglGenRenderbuffers = pglGenRenderbuffersEXT; - pglBindRenderbuffer = pglBindRenderbufferEXT; - pglDeleteRenderbuffers = pglDeleteRenderbuffersEXT; - pglRenderbufferStorage = pglRenderbufferStorageEXT; - pglFramebufferRenderbuffer = pglFramebufferRenderbufferEXT; + // remapping galore huehue + // do this so we dont have to dupe half our code + pglGenFramebuffers = pglGenFramebuffersEXT; + pglBindFramebuffer = pglBindFramebufferEXT; + pglDeleteFramebuffers = pglDeleteFramebuffersEXT; + pglFramebufferTexture2D = pglFramebufferTexture2DEXT; + pglCheckFramebufferStatus = pglCheckFramebufferStatusEXT; + pglGenRenderbuffers = pglGenRenderbuffersEXT; + pglBindRenderbuffer = pglBindRenderbufferEXT; + pglDeleteRenderbuffers = pglDeleteRenderbuffersEXT; + pglRenderbufferStorage = pglRenderbufferStorageEXT; + pglFramebufferRenderbuffer = pglFramebufferRenderbufferEXT; - supportFBO = fbocheck; - - if (fbocheck == FBO_EXT) - GL_DBG_Printf("\nFBO: EXT extensions found, no stencil\n"); - else if (fbocheck == FBO_EXT_STENCIL) - GL_DBG_Printf("\nFBO: EXT extensions with packed depth-stencil\n"); - } + if (fbocheck == FBO_EXT) + GL_DBG_Printf("\nFBO: EXT extensions found, no stencil\n"); + else if (fbocheck == FBO_EXT_STENCIL) + GL_DBG_Printf("\nFBO: EXT extensions with packed depth-stencil\n"); } + + supportFBO = fbocheck; } else GL_DBG_Printf("\nFBO: No framebuffer object support\n"); -#endif #undef GetGLfunc +#endif } boolean GL_InitShaders(void) @@ -2633,7 +2641,9 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) break; case HWD_SET_PORTAL_MODE: - gl_portal_mode = Value; + if (!supportstencil) + break; + switch (Value) { case HWD_PORTAL_NORMAL: diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 397e8702b..4cf2b2e46 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -64,6 +64,8 @@ extern FILE *gllogstream; FUNCPRINTF void GL_DBG_Printf(const char *format, ...); +extern boolean supportstencil; + void *GetGLFunc(const char *proc); boolean SetupGLfunc(void); void SetupGLFunc4(void); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 0ee886d1e..4465c6094 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -98,11 +98,10 @@ boolean VID_LoadOGLAPI(void) if (SDL_GL_LoadLibrary(OGLLibname) != 0) { - CONS_Alert(CONS_ERROR, "Could not load OpenGL Library: %s\n" - "Falling back to Software mode.\n", SDL_GetError()); + CONS_Alert(CONS_ERROR, "Could not load OpenGL Library: %s\n" "Falling back to Software mode.\n", SDL_GetError()); if (!M_CheckParm("-OGLlib")) CONS_Printf("If you know what is the OpenGL library's name, use -OGLlib\n"); - return 0; + return false; } #endif return true; @@ -206,7 +205,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) char videodriver[4] = {'S','D','L',0}; if (supportFBO && strstr((const char*)gl_renderer, "NVIDIA") && (*strncpy(videodriver, SDL_GetCurrentVideoDriver(), sizeof(videodriver)-1) != '\0') - && (strncasecmp("x11",videodriver,4) == 0)) + && (strncasecmp("x11", videodriver, 4) == 0)) xwaylandcrap = true; #endif #endif