Add r_2D_unfiltered CVar, improve r_nolerp_list handling

Setting r_2D_unfiltered to 1 (0 is default), 2D elements (GUI, menu,
console) are rendered without texture filtering in GL1 and GL3, while
everything else is still rendered with whatever is set in gl_texturemode

This setting (and now also gl_nolerp_list) is applied immediately,
so no vid_restart is needed.

refs #752
This commit is contained in:
Daniel Gibson 2021-10-30 20:42:43 +02:00
parent 568602ab49
commit 3873c76e12
6 changed files with 62 additions and 18 deletions

View File

@ -214,13 +214,16 @@ R_TextureMode(char *string)
} }
const char* nolerplist = gl_nolerp_list->string; const char* nolerplist = gl_nolerp_list->string;
qboolean unfiltered2D = r_2D_unfiltered->value != 0;
/* change all the existing mipmap texture objects */ /* change all the existing mipmap texture objects */
for (i = 0, glt = gltextures; i < numgltextures; i++, glt++) for (i = 0, glt = gltextures; i < numgltextures; i++, glt++)
{ {
if (nolerplist != NULL && strstr(nolerplist, glt->name) != NULL) qboolean nolerp = false;
/* r_2D_unfiltered and r_nolerp_list allow rendering stuff unfiltered even if gl_filter_* is filtered */
if ( (unfiltered2D && glt->type == it_pic) || (nolerplist != NULL && strstr(nolerplist, glt->name) != NULL) )
{ {
continue; /* those (by default: font and crosshairs) always only use GL_NEAREST */ nolerp = true;
} }
R_Bind(glt->texnum); R_Bind(glt->texnum);
@ -238,10 +241,19 @@ R_TextureMode(char *string)
} }
else /* texture has no mipmaps */ else /* texture has no mipmaps */
{ {
// we can't use gl_filter_min which might be GL_*_MIPMAP_* if (nolerp)
// also, there's no anisotropic filtering for textures w/o mipmaps {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max); // this texture shouldn't be filtered at all (no gl_nolerp_list or r_2D_unfiltered case)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
else
{
// we can't use gl_filter_min which might be GL_*_MIPMAP_*
// also, there's no anisotropic filtering for textures w/o mipmaps
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
}
} }
} }
} }
@ -849,8 +861,11 @@ R_LoadPic(char *name, byte *pic, int width, int realwidth,
int i; int i;
qboolean nolerp = false; qboolean nolerp = false;
if (r_2D_unfiltered->value && type == it_pic)
if(gl_nolerp_list != NULL && gl_nolerp_list->string != NULL) {
nolerp = true;
}
else if(gl_nolerp_list != NULL && gl_nolerp_list->string != NULL)
{ {
nolerp = strstr(gl_nolerp_list->string, name) != NULL; nolerp = strstr(gl_nolerp_list->string, name) != NULL;
} }

View File

@ -104,6 +104,7 @@ cvar_t *r_retexturing;
cvar_t *r_scale8bittextures; cvar_t *r_scale8bittextures;
cvar_t *gl_nolerp_list; cvar_t *gl_nolerp_list;
cvar_t *r_2D_unfiltered;
cvar_t *gl1_dynamic; cvar_t *gl1_dynamic;
cvar_t *r_modulate; cvar_t *r_modulate;
@ -1266,6 +1267,8 @@ R_Register(void)
/* don't bilerp characters and crosshairs */ /* don't bilerp characters and crosshairs */
gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", 0); gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", 0);
/* don't bilerp any 2D elements */
r_2D_unfiltered = ri.Cvar_Get("r_2D_unfiltered", "0", CVAR_ARCHIVE);
gl1_stereo = ri.Cvar_Get( "gl1_stereo", "0", CVAR_ARCHIVE ); gl1_stereo = ri.Cvar_Get( "gl1_stereo", "0", CVAR_ARCHIVE );
gl1_stereo_separation = ri.Cvar_Get( "gl1_stereo_separation", "-0.4", CVAR_ARCHIVE ); gl1_stereo_separation = ri.Cvar_Get( "gl1_stereo_separation", "-0.4", CVAR_ARCHIVE );
@ -1689,11 +1692,14 @@ RI_BeginFrame(float camera_separation)
} }
/* texturemode stuff */ /* texturemode stuff */
if (gl_texturemode->modified || (gl_config.anisotropic && gl_anisotropic->modified)) if (gl_texturemode->modified || (gl_config.anisotropic && gl_anisotropic->modified)
|| gl_nolerp_list->modified || r_2D_unfiltered->modified)
{ {
R_TextureMode(gl_texturemode->string); R_TextureMode(gl_texturemode->string);
gl_texturemode->modified = false; gl_texturemode->modified = false;
gl_anisotropic->modified = false; gl_anisotropic->modified = false;
gl_nolerp_list->modified = false;
r_2D_unfiltered->modified = false;
} }
if (gl1_texturealphamode->modified) if (gl1_texturealphamode->modified)

View File

@ -195,6 +195,7 @@ extern cvar_t *r_retexturing;
extern cvar_t *r_scale8bittextures; extern cvar_t *r_scale8bittextures;
extern cvar_t *gl_nolerp_list; extern cvar_t *gl_nolerp_list;
extern cvar_t *r_2D_unfiltered;
extern cvar_t *gl_lightmap; extern cvar_t *gl_lightmap;
extern cvar_t *gl_shadows; extern cvar_t *gl_shadows;

View File

@ -88,13 +88,16 @@ GL3_TextureMode(char *string)
gl3image_t *glt; gl3image_t *glt;
const char* nolerplist = gl_nolerp_list->string; const char* nolerplist = gl_nolerp_list->string;
qboolean unfiltered2D = r_2D_unfiltered->value != 0;
/* change all the existing texture objects */ /* change all the existing texture objects */
for (i = 0, glt = gl3textures; i < numgl3textures; i++, glt++) for (i = 0, glt = gl3textures; i < numgl3textures; i++, glt++)
{ {
if (nolerplist != NULL && strstr(nolerplist, glt->name) != NULL) qboolean nolerp = false;
/* r_2D_unfiltered and gl_nolerp_list allow rendering stuff unfiltered even if gl_filter_* is filtered */
if ( (unfiltered2D && glt->type == it_pic) || (nolerplist != NULL && strstr(nolerplist, glt->name) != NULL) )
{ {
continue; /* those (by default: font and crosshairs) always only use GL_NEAREST */ nolerp = true;
} }
GL3_SelectTMU(GL_TEXTURE0); GL3_SelectTMU(GL_TEXTURE0);
@ -112,10 +115,19 @@ GL3_TextureMode(char *string)
} }
else /* texture has no mipmaps */ else /* texture has no mipmaps */
{ {
// we can't use gl_filter_min which might be GL_*_MIPMAP_* if (nolerp)
// also, there's no anisotropic filtering for textures w/o mipmaps {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max); // this texture shouldn't be filtered at all (no gl_nolerp_list or r_2D_unfiltered case)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
else
{
// we can't use gl_filter_min which might be GL_*_MIPMAP_*
// also, there's no anisotropic filtering for textures w/o mipmaps
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
}
} }
} }
} }
@ -375,8 +387,11 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
int i; int i;
qboolean nolerp = false; qboolean nolerp = false;
if (r_2D_unfiltered->value && type == it_pic)
if (gl_nolerp_list != NULL && gl_nolerp_list->string != NULL) {
nolerp = true;
}
else if (gl_nolerp_list != NULL && gl_nolerp_list->string != NULL)
{ {
nolerp = strstr(gl_nolerp_list->string, name) != NULL; nolerp = strstr(gl_nolerp_list->string, name) != NULL;
} }

View File

@ -107,6 +107,7 @@ cvar_t *r_norefresh;
cvar_t *r_drawentities; cvar_t *r_drawentities;
cvar_t *r_drawworld; cvar_t *r_drawworld;
cvar_t *gl_nolerp_list; cvar_t *gl_nolerp_list;
cvar_t *r_2D_unfiltered;
cvar_t *gl_nobind; cvar_t *gl_nobind;
cvar_t *r_lockpvs; cvar_t *r_lockpvs;
cvar_t *r_novis; cvar_t *r_novis;
@ -221,6 +222,8 @@ GL3_Register(void)
/* don't bilerp characters and crosshairs */ /* don't bilerp characters and crosshairs */
gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", 0); gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", 0);
/* don't bilerp any 2D elements */
r_2D_unfiltered = ri.Cvar_Get("r_2D_unfiltered", "0", CVAR_ARCHIVE);
gl_nobind = ri.Cvar_Get("gl_nobind", "0", 0); gl_nobind = ri.Cvar_Get("gl_nobind", "0", 0);
gl_texturemode = ri.Cvar_Get("gl_texturemode", "GL_LINEAR_MIPMAP_NEAREST", CVAR_ARCHIVE); gl_texturemode = ri.Cvar_Get("gl_texturemode", "GL_LINEAR_MIPMAP_NEAREST", CVAR_ARCHIVE);
@ -1766,11 +1769,14 @@ GL3_BeginFrame(float camera_separation)
} }
/* texturemode stuff */ /* texturemode stuff */
if (gl_texturemode->modified || (gl3config.anisotropic && gl_anisotropic->modified)) if (gl_texturemode->modified || (gl3config.anisotropic && gl_anisotropic->modified)
|| gl_nolerp_list->modified || r_2D_unfiltered->modified)
{ {
GL3_TextureMode(gl_texturemode->string); GL3_TextureMode(gl_texturemode->string);
gl_texturemode->modified = false; gl_texturemode->modified = false;
gl_anisotropic->modified = false; gl_anisotropic->modified = false;
gl_nolerp_list->modified = false;
r_2D_unfiltered->modified = false;
} }
if (r_vsync->modified) if (r_vsync->modified)

View File

@ -487,6 +487,7 @@ extern cvar_t *r_mode;
extern cvar_t *r_customwidth; extern cvar_t *r_customwidth;
extern cvar_t *r_customheight; extern cvar_t *r_customheight;
extern cvar_t *r_2D_unfiltered;
extern cvar_t *gl_nolerp_list; extern cvar_t *gl_nolerp_list;
extern cvar_t *gl_nobind; extern cvar_t *gl_nobind;
extern cvar_t *r_lockpvs; extern cvar_t *r_lockpvs;