summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2013-04-01 19:40:23 +0400
committerAndrey Nazarov <skuller@skuller.net>2013-04-01 19:40:23 +0400
commit50fcb41bebc280bd2ea01652129a109b19a01aff (patch)
treeaafa46ef5e8064aa2f8175871a748898634acfa7
parent4874d4ee9325360590575dab1ba2b64f2fc1f464 (diff)
Adjust LOD for upscaled, non power-of-two textures.
Also put back checks for OpenGL version and restore OpenGL 1.1 requirement.
-rw-r--r--src/refresh/gl/gl.h3
-rw-r--r--src/refresh/gl/images.c21
-rw-r--r--src/refresh/gl/main.c5
3 files changed, 23 insertions, 6 deletions
diff --git a/src/refresh/gl/gl.h b/src/refresh/gl/gl.h
index 358d2d2..09d2c70 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 551ad92..dd8bebd 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 2fe3032..adcbb4e 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;
}