Skip to content

Commit

Permalink
Adjust LOD for upscaled, non power-of-two textures.
Browse files Browse the repository at this point in the history
Also put back checks for OpenGL version and restore OpenGL 1.1
requirement.
  • Loading branch information
skullernet committed Apr 1, 2013
1 parent 4874d4e commit 50fcb41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/refresh/gl/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 18 additions & 3 deletions src/refresh/gl/images.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/refresh/gl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 50fcb41

Please sign in to comment.