ref: gl: use TextureFilteringEnabled to decide whether texture will have nearest filtering or linear

This commit is contained in:
Alibek Omarov 2024-01-29 05:44:14 +03:00
parent a28d45fdb2
commit e274c62cfc
3 changed files with 30 additions and 23 deletions

View File

@ -167,25 +167,6 @@ static qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte
return loaded;
}
static qboolean R_TextureFilteringEnabled( int arg )
{
gl_texture_t *glt;
if( arg < 0 )
return gl_texture_nearest.value == 0.0f;
glt = R_GetTexture( arg );
if( FBitSet( glt->flags, TF_NEAREST ))
return false;
// lightmaps have special cvar
if( FBitSet( glt->flags, TF_ATLAS_PAGE ))
return gl_lightmap_nearest.value == 0.0f;
return gl_texture_nearest.value == 0.0f;
}
static int GL_RefGetParm( int parm, int arg )
{
gl_texture_t *glt;
@ -257,7 +238,10 @@ static int GL_RefGetParm( int parm, int arg )
case PARM_SKY_SPHERE:
return FBitSet( tr.world->flags, FWORLD_SKYSPHERE ) && !FBitSet( tr.world->flags, FWORLD_CUSTOM_SKYBOX );
case PARM_TEX_FILTERING:
return R_TextureFilteringEnabled( arg );
if( arg < 0 )
return gl_texture_nearest.value == 0.0f;
return GL_TextureFilteringEnabled( R_GetTexture( arg ));
default:
return ENGINE_GET_PARM_( parm, arg );
}

View File

@ -118,6 +118,28 @@ void GL_Bind( GLint tmu, GLenum texnum )
glState.currentTexturesIndex[tmu] = texnum;
}
qboolean GL_TextureFilteringEnabled( const gl_texture_t *tex )
{
if( FBitSet( tex->flags, TF_NEAREST ))
return false;
if( FBitSet( tex->flags, TF_DEPTHMAP ))
return true;
if( FBitSet( tex->flags, TF_NOMIPMAP ) || tex->numMips <= 1 )
{
if( FBitSet( tex->flags, TF_ATLAS_PAGE ))
return gl_lightmap_nearest.value == 0.0f;
if( FBitSet( tex->flags, TF_SKYSIDE ))
return gl_texture_nearest.value == 0.0f;
return true;
}
return gl_texture_nearest.value == 0.0f;
}
/*
=================
GL_ApplyTextureParams
@ -149,7 +171,7 @@ void GL_ApplyTextureParams( gl_texture_t *tex )
pglTexParameteri( tex->target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE );
else pglTexParameteri( tex->target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY );
if( FBitSet( tex->flags, TF_NEAREST ))
if( !GL_TextureFilteringEnabled( tex ))
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
@ -166,7 +188,7 @@ void GL_ApplyTextureParams( gl_texture_t *tex )
}
else if( FBitSet( tex->flags, TF_NOMIPMAP ) || tex->numMips <= 1 )
{
if( FBitSet( tex->flags, TF_NEAREST ) || ( IsLightMap( tex ) && gl_lightmap_nearest.value ) || ( tex->flags == TF_SKYSIDE && gl_texture_nearest.value ))
if( !GL_TextureFilteringEnabled( tex ))
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
@ -179,7 +201,7 @@ void GL_ApplyTextureParams( gl_texture_t *tex )
}
else
{
if( FBitSet( tex->flags, TF_NEAREST ) || gl_texture_nearest.value )
if( !GL_TextureFilteringEnabled( tex ))
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );

View File

@ -364,6 +364,7 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe
int GL_CreateTextureArray( const char *name, int width, int height, int depth, const void *buffer, texFlags_t flags );
void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor );
void GL_UpdateTexSize( int texnum, int width, int height, int depth );
qboolean GL_TextureFilteringEnabled( const gl_texture_t *tex );
void GL_ApplyTextureParams( gl_texture_t *tex );
int GL_FindTexture( const char *name );
void GL_FreeTexture( GLenum texnum );