From 9725a9d9a595cb490f7528a37cffd3e26c03d186 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 19 Jan 2024 19:23:49 +0100 Subject: [PATCH] Fix blackscreen on start + some other changes move a few things around in HWR_Startup so they only get called on startup --- src/d_main.c | 2 - src/hardware/hw_main.c | 77 +++++++++++++++----------------- src/hardware/r_opengl/r_opengl.c | 2 - src/screen.h | 7 +++ src/sdl/i_video.c | 16 ++++--- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 3850243b8..a56c69436 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1521,9 +1521,7 @@ void D_SRB2Main(void) // Has to be done before the configuration file loads, // but after the OpenGL library loads. HWR_AddCommands(); -#endif -#ifdef HWRENDER if (rendermode == render_opengl) { for (i = 0; i < numwadfiles; i++) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index cfb8c7aa4..4cf8b04a3 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -163,31 +163,31 @@ consvar_t cv_grslopecontrast = {"gr_slopecontrast", "Off", CV_SAVE, CV_OnOff, NU consvar_t cv_grhorizonlines = {"gr_horizonlines", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +#define ONLY_IF_GL_LOADED if (vid.glstate != VID_GL_LIBRARY_LOADED) return; static void CV_filtermode_ONChange(void) { - if (rendermode == render_opengl) - HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_grfiltermode.value); + ONLY_IF_GL_LOADED + HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_grfiltermode.value); } static void CV_anisotropic_ONChange(void) { - if (rendermode == render_opengl) - HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_granisotropicmode.value); + ONLY_IF_GL_LOADED + HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_granisotropicmode.value); } static void CV_screentextures_ONChange(void) { - if (rendermode == render_opengl) - HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); + ONLY_IF_GL_LOADED + HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); } static void CV_grshaders_OnChange(void) { - if (rendermode == render_opengl) - HWR_SetShaderState(); - - if ((rendermode == render_opengl) && (cv_grpaletterendering.value)) + ONLY_IF_GL_LOADED + HWR_SetShaderState(); + if ((cv_grpaletterendering.value)) { // can't do palette rendering without shaders, so update the state if needed HWR_TogglePaletteRendering(); @@ -196,22 +196,22 @@ static void CV_grshaders_OnChange(void) static void CV_useCustomShaders_ONChange(void) // should we do a call to HWR_TogglePaletteRendering here aswell in pal rendering mode? { - if (rendermode == render_opengl) - { - if (HWR_UseShader()) - HWD.pfnInitCustomShaders(); - } + ONLY_IF_GL_LOADED + if (HWR_UseShader()) + HWD.pfnInitCustomShaders(); } static void CV_grpaletterendering_OnChange(void) { - if ((rendermode == render_opengl) && (gr_shadersavailable)) + ONLY_IF_GL_LOADED + if (gr_shadersavailable) HWR_TogglePaletteRendering(); } static void CV_grpalettedepth_OnChange(void) { - if ((rendermode == render_opengl) && (HWR_ShouldUsePaletteRendering())) + ONLY_IF_GL_LOADED + if (HWR_ShouldUsePaletteRendering()) HWR_SetPalette(pLocalPalette); } @@ -220,10 +220,7 @@ static void CV_grpalettedepth_OnChange(void) // void HWR_SetShaderState(void) { - INT32 state = cv_grshaders.value; - - HWD.pfnSetSpecialState(HWD_SET_SHADERS, (INT32)state); - HWD.pfnSetShader(0); + HWD.pfnSetSpecialState(HWD_SET_SHADERS, HWR_UseShader()); } // ========================================================================== @@ -6273,8 +6270,8 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) HWR_ClearClipper(); // Reset the shader state. - HWD.pfnSetSpecialState(HWD_SET_SHADERS, cv_grshaders.value); - HWD.pfnSetShader(0); + //HWD.pfnSetSpecialState(HWD_SET_SHADERS, cv_grshaders.value); + //HWD.pfnSetShader(0); validcount++; @@ -6447,26 +6444,24 @@ void HWR_Startup(void) HWR_InitMD2(); HWD.pfnSetupGLInfo(); - } + + // jimita + HWD.pfnKillShaders(); + if (!HWD.pfnLoadShaders()) + gr_shadersavailable = false; + HWR_SetShaderState(); + HWR_TogglePaletteRendering(); + + if (msaa) + { + if (a2c) + HWD.pfnSetSpecialState(HWD_SET_MSAA, 2); + else + HWD.pfnSetSpecialState(HWD_SET_MSAA, 1); + } + } startupdone = true; - - // jimita - HWD.pfnKillShaders(); - if (!HWD.pfnLoadShaders()) - gr_shadersavailable = false; - - HWR_SetShaderState(); - - HWR_TogglePaletteRendering(); - - if (msaa) - { - if (a2c) - HWD.pfnSetSpecialState(HWD_SET_MSAA, 2); - else - HWD.pfnSetSpecialState(HWD_SET_MSAA, 1); - } } // -------------------------------------------------------------------------- diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index bb5f3396a..26073bbeb 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3411,8 +3411,6 @@ EXPORT void HWRAPI(DrawScreenTexture)(int tex, FSurfaceInfo *surf, FBITFIELD pol if (!surf) pglColor4ubv(white); - pglColor4ubv(white); - pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); diff --git a/src/screen.h b/src/screen.h index 64c04dc15..478890c49 100644 --- a/src/screen.h +++ b/src/screen.h @@ -72,11 +72,18 @@ typedef struct viddef_s #ifdef HWRENDER INT32/*fixed_t*/ fsmalldupx, fsmalldupy; INT32/*fixed_t*/ fmeddupx, fmeddupy; + INT32 glstate; #endif } viddef_t; #define VIDWIDTH vid.width #define VIDHEIGHT vid.height +enum +{ + VID_GL_LIBRARY_LOADED = 1, + VID_GL_LIBRARY_ERROR = -1, +}; + // internal additional info for vesa modes only typedef struct { diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c070b3826..8ce2b4710 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1787,10 +1787,8 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) flags |= SDL_WINDOW_BORDERLESS; #ifdef HWRENDER - if (rendermode == render_opengl) - { + if (vid.glstate == VID_GL_LIBRARY_LOADED) flags |= SDL_WINDOW_OPENGL; - } if (msaa) { @@ -1802,12 +1800,12 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) // Some GPU drivers may give us a 16-bit depth buffer since the // default value for SDL_GL_DEPTH_SIZE is 16. SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); -#endif - + // request stencil buffer. If there are problems on weaker hw the bit count could be reduced // If only something like 1-bit or 2-bit stencil is available on some gpus then should implement limit for maxportals based on that. // 4 bits would be enough for current limit in maxportals (12) SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 4); +#endif // Create a window window = SDL_CreateWindow("SRB2Kart "VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, @@ -1821,7 +1819,8 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) // Renderer-specific stuff #ifdef HWRENDER - if (rendermode == render_opengl) + if ((rendermode == render_opengl) + && (vid.glstate != VID_GL_LIBRARY_ERROR)) { sdlglcontext = SDL_GL_CreateContext(window); if (sdlglcontext == NULL) @@ -2151,8 +2150,11 @@ void I_StartupGraphics(void) HWD.pfnClearLightTables = hwSym("ClearLightTables",NULL); HWD.pfnSetScreenPalette = hwSym("SetScreenPalette",NULL); - if (!HWD.pfnInit()) // load the OpenGL library + vid.glstate = HWD.pfnInit() ? VID_GL_LIBRARY_LOADED : VID_GL_LIBRARY_ERROR; // let load the OpenGL library + if (vid.glstate == VID_GL_LIBRARY_ERROR) + { rendermode = render_soft; + } } #endif