From e274c62cfc4739f77ad46f6ad876ed0ea0b37385 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 29 Jan 2024 05:44:14 +0300 Subject: [PATCH] ref: gl: use TextureFilteringEnabled to decide whether texture will have nearest filtering or linear --- ref/gl/gl_context.c | 24 ++++-------------------- ref/gl/gl_image.c | 28 +++++++++++++++++++++++++--- ref/gl/gl_local.h | 1 + 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/ref/gl/gl_context.c b/ref/gl/gl_context.c index a5d9aa08..7d0d5682 100644 --- a/ref/gl/gl_context.c +++ b/ref/gl/gl_context.c @@ -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 ); } diff --git a/ref/gl/gl_image.c b/ref/gl/gl_image.c index 196b7ad8..5cdae89b 100644 --- a/ref/gl/gl_image.c +++ b/ref/gl/gl_image.c @@ -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 ); diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index 11cccb2b..be29b8db 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -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 );