From 350b8f9c7c88c002dccea4f0350f1919b86d3b4e Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Tue, 28 May 2019 22:44:57 -0500 Subject: [PATCH] Restore OpenGL 1.1 support (GL_CLAMP) GL_CLAMP (clamp to border) was changed to GL_CLAMP_TO_EDGE in 2008 (f2baf359). In 2018 (ce1d5406) I made OpenGL 1.2 be required since GL_CLAMP_TO_EDGE is used. Restore support for GL_CLAMP in order to support OpenGL 1.1 like vanilla Quake 3 does. This should allow using the default Microsoft Windows GDI Generic OpenGL 1.1 driver (untested but it won't fail the version check at least). From gpuinfo.org, it looks like drivers stopped advertising support for GL_SGIS_texture_edge_clamp so use a version check in addition to the extension check. r_allowExtensions 0 disables using GL_CLAMP_TO_EDGE in the opengl1 renderer. GL_CLAMP support wasn't added to the opengl2 renderer. --- code/renderercommon/tr_common.h | 1 + code/renderergl1/tr_backend.c | 4 ++-- code/renderergl1/tr_image.c | 2 +- code/renderergl1/tr_init.c | 2 ++ code/renderergl2/tr_init.c | 2 ++ code/sdl/sdl_glimp.c | 15 +++++++++++++-- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/code/renderercommon/tr_common.h b/code/renderercommon/tr_common.h index 9c7e176b..c183ca8b 100644 --- a/code/renderercommon/tr_common.h +++ b/code/renderercommon/tr_common.h @@ -80,6 +80,7 @@ extern glconfig_t glConfig; // outside of TR since it shouldn't be cleared duri extern qboolean textureFilterAnisotropic; extern int maxAnisotropy; extern float displayAspect; +extern qboolean haveClampToEdge; // // cvars diff --git a/code/renderergl1/tr_backend.c b/code/renderergl1/tr_backend.c index abf15f2e..56cf37d1 100644 --- a/code/renderergl1/tr_backend.c +++ b/code/renderergl1/tr_backend.c @@ -794,8 +794,8 @@ void RE_UploadCinematic (int w, int h, int cols, int rows, const byte *data, int qglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, cols, rows, 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, haveClampToEdge ? GL_CLAMP_TO_EDGE : GL_CLAMP ); + qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, haveClampToEdge ? GL_CLAMP_TO_EDGE : GL_CLAMP ); } else { if (dirty) { // otherwise, just subimage upload it so that drivers can tell we are going to be changing diff --git a/code/renderergl1/tr_image.c b/code/renderergl1/tr_image.c index 9603ff71..a63de580 100644 --- a/code/renderergl1/tr_image.c +++ b/code/renderergl1/tr_image.c @@ -866,7 +866,7 @@ image_t *R_CreateImage( const char *name, byte *pic, int width, int height, image->width = width; image->height = height; if (flags & IMGFLAG_CLAMPTOEDGE) - glWrapClampMode = GL_CLAMP_TO_EDGE; + glWrapClampMode = haveClampToEdge ? GL_CLAMP_TO_EDGE : GL_CLAMP; else glWrapClampMode = GL_REPEAT; diff --git a/code/renderergl1/tr_init.c b/code/renderergl1/tr_init.c index 2c7d91de..2539ffa7 100644 --- a/code/renderergl1/tr_init.c +++ b/code/renderergl1/tr_init.c @@ -27,6 +27,7 @@ glconfig_t glConfig; qboolean textureFilterAnisotropic = qfalse; int maxAnisotropy = 0; float displayAspect = 0.0f; +qboolean haveClampToEdge = qfalse; glstate_t glState; @@ -1294,6 +1295,7 @@ void RE_Shutdown( qboolean destroyWindow ) { textureFilterAnisotropic = qfalse; maxAnisotropy = 0; displayAspect = 0.0f; + haveClampToEdge = qfalse; Com_Memset( &glState, 0, sizeof( glState ) ); } diff --git a/code/renderergl2/tr_init.c b/code/renderergl2/tr_init.c index bd34cc61..275d621e 100644 --- a/code/renderergl2/tr_init.c +++ b/code/renderergl2/tr_init.c @@ -30,6 +30,7 @@ glRefConfig_t glRefConfig; qboolean textureFilterAnisotropic = qfalse; int maxAnisotropy = 0; float displayAspect = 0.0f; +qboolean haveClampToEdge = qfalse; glstate_t glState; @@ -1552,6 +1553,7 @@ void RE_Shutdown( qboolean destroyWindow ) { textureFilterAnisotropic = qfalse; maxAnisotropy = 0; displayAspect = 0.0f; + haveClampToEdge = qfalse; Com_Memset( &glState, 0, sizeof( glState ) ); } diff --git a/code/sdl/sdl_glimp.c b/code/sdl/sdl_glimp.c index 28524ce4..4b284fdb 100644 --- a/code/sdl/sdl_glimp.c +++ b/code/sdl/sdl_glimp.c @@ -277,7 +277,7 @@ static qboolean GLimp_GetProcAddresses( qboolean fixedFunction ) { } if ( fixedFunction ) { - if ( QGL_VERSION_ATLEAST( 1, 2 ) ) { + if ( QGL_VERSION_ATLEAST( 1, 1 ) ) { QGL_1_1_PROCS; QGL_1_1_FIXED_FUNCTION_PROCS; QGL_DESKTOP_1_1_PROCS; @@ -291,7 +291,7 @@ static qboolean GLimp_GetProcAddresses( qboolean fixedFunction ) { // error so this doesn't segfault due to NULL desktop GL functions being used Com_Error( ERR_FATAL, "Unsupported OpenGL Version: %s", version ); } else { - Com_Error( ERR_FATAL, "Unsupported OpenGL Version (%s), OpenGL 1.2 is required", version ); + Com_Error( ERR_FATAL, "Unsupported OpenGL Version (%s), OpenGL 1.1 is required", version ); } } else { if ( QGL_VERSION_ATLEAST( 2, 0 ) ) { @@ -965,6 +965,17 @@ static void GLimp_InitExtensions( qboolean fixedFunction ) { ri.Printf( PRINT_ALL, "...GL_EXT_texture_filter_anisotropic not found\n" ); } + + haveClampToEdge = qfalse; + if ( QGL_VERSION_ATLEAST( 1, 2 ) || QGLES_VERSION_ATLEAST( 1, 0 ) || SDL_GL_ExtensionSupported( "GL_SGIS_texture_edge_clamp" ) ) + { + ri.Printf( PRINT_ALL, "...using GL_SGIS_texture_edge_clamp\n" ); + haveClampToEdge = qtrue; + } + else + { + ri.Printf( PRINT_ALL, "...GL_SGIS_texture_edge_clamp not found\n" ); + } } #define R_MODE_FALLBACK 3 // 640 * 480