From 277dbf89f1ab43bca98f5fd1dbe1689f0550de89 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Thu, 24 Jun 2021 18:37:14 +0200 Subject: [PATCH] Make sure shaders are only loaded once at startup, fix #386 this *shouldn't* matter, but due to some Mesa bug is does: If the shaders have been loaded already (with R_LoadARBProgram()), then loading them again (like from the `reloadARBprograms` console cmd or as it happens if the `r_gammaInShader` has been modified) will cause glitches with the open source radeonsi driver (maybe also with others? at least the open source intel driver seems unaffected). As r_gammaInShader was marked as modified at startup (before the shaders were even loaded) they were loaded twice: First as expected when OpenGL is initialized, then again in R_CheckCvars() which is executed each frame. Marking as at not modified in R_InitOpenGL() prevents this and thus works around the bug. However this means that changing r_gammaInShader at runtime will still trigger this bug (while with non-broken drivers it switches seamlessly between gamma in shader and gamma in hardware without a vid_restart). --- neo/renderer/RenderSystem_init.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index b070d3f7..55fa1c4f 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -734,7 +734,13 @@ void R_InitOpenGL( void ) { R_InitFrameData(); // Reset our gamma - R_SetColorMappings(); + r_gammaInShader.ClearModified(); + if ( r_gammaInShader.GetBool() ) { + common->Printf( "Will apply r_gamma and r_brightness in shaders (r_gammaInShader 1)\n" ); + } else { + common->Printf( "Will apply r_gamma and r_brightness in hardware (possibly on all screens; r_gammaInShader 0)\n" ); + R_SetColorMappings(); + } #ifdef _WIN32 static bool glCheck = false;