diff --git a/src/refresh/gl/gl.h b/src/refresh/gl/gl.h index 358d2d294..09d2c7078 100644 --- a/src/refresh/gl/gl.h +++ b/src/refresh/gl/gl.h @@ -108,6 +108,9 @@ typedef struct { int stencilbits; } glConfig_t; +#define AT_LEAST_OPENGL(major, minor) \ + (gl_config.version_major > major || (gl_config.version_major == major && gl_config.version_minor >= minor)) + extern glStatic_t gl_static; extern glConfig_t gl_config; extern glRefdef_t glr; diff --git a/src/refresh/gl/images.c b/src/refresh/gl/images.c index 551ad92ec..dd8bebda0 100644 --- a/src/refresh/gl/images.c +++ b/src/refresh/gl/images.c @@ -618,7 +618,19 @@ static void GL_Upscale8(byte *data, int width, int height, imagetype_t type, ima FS_FreeTempMem(buffer); GL_Upload8(data, width, height, maxlevel, type, flags); - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxlevel); + + if (AT_LEAST_OPENGL(1, 2)) + qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxlevel); + + // adjust LOD for non power-of-two textures + if ((width & (width - 1)) || (height & (height - 1))) { + float du = npot32(width) / (float)width; + float dv = npot32(height) / (float)height; + float bias = -log2(max(du, dv)); + + if (AT_LEAST_OPENGL(1, 4)) + qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, bias); + } } static void GL_SetFilterAndRepeat(imagetype_t type, imageflags_t flags) @@ -642,7 +654,7 @@ static void GL_SetFilterAndRepeat(imagetype_t type, imageflags_t flags) nearest = qfalse; } - if (flags & IF_UPSCALED) { + if ((flags & IF_UPSCALED) && AT_LEAST_OPENGL(1, 2)) { if (nearest) { qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -671,9 +683,12 @@ static void GL_SetFilterAndRepeat(imagetype_t type, imageflags_t flags) if (type == IT_WALL || type == IT_SKIN || (flags & IF_REPEAT)) { qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - } else { + } else if (AT_LEAST_OPENGL(1, 2)) { qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } else { + qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); } } diff --git a/src/refresh/gl/main.c b/src/refresh/gl/main.c index 2fe3032ed..adcbb4e2b 100644 --- a/src/refresh/gl/main.c +++ b/src/refresh/gl/main.c @@ -820,9 +820,8 @@ static qboolean GL_SetupConfig(void) } // OpenGL 1.0 doesn't have vertex arrays - // OpenGL 1.1 doesn't have GL_CLAMP_TO_EDGE, GL_TEXTURE_MAX_LEVEL - if (gl_config.version_major == 1 && gl_config.version_minor < 2) { - Com_EPrintf("OpenGL version 1.2 or higher required\n"); + if (!AT_LEAST_OPENGL(1, 1)) { + Com_EPrintf("OpenGL version 1.1 or higher required\n"); return qfalse; }