Browse Source

engine: client: fix filtering errors by adjusting texcoords by half of a pixel

Remove useless wrapper functions and conversions
Don't scale texcoords and position if hud_scale is not active
pull/2/head
Alibek Omarov 2 years ago
parent
commit
84c14b32ec
  1. 87
      engine/client/cl_game.c
  2. 23
      engine/client/cl_gameui.c
  3. 3
      engine/client/client.h

87
engine/client/cl_game.c

@ -345,53 +345,43 @@ SPR_AdjustSize @@ -345,53 +345,43 @@ SPR_AdjustSize
draw hudsprite routine
====================
*/
static void SPR_AdjustSize( float *x, float *y, float *w, float *h )
void SPR_AdjustSize( float *x, float *y, float *w, float *h )
{
float xscale, yscale;
if( refState.width == clgame.scrInfo.iWidth && refState.height == clgame.scrInfo.iHeight )
return;
// scale for screen sizes
xscale = refState.width / (float)clgame.scrInfo.iWidth;
yscale = refState.height / (float)clgame.scrInfo.iHeight;
if( x ) *x *= xscale;
if( y ) *y *= yscale;
if( w ) *w *= xscale;
if( h ) *h *= yscale;
*x *= xscale;
*y *= yscale;
*w *= xscale;
*h *= yscale;
}
/*
====================
SPR_AdjustSize
draw hudsprite routine
====================
*/
static void SPR_AdjustSizei( int *x, int *y, int *w, int *h )
void SPR_AdjustTexCoords( float width, float height, float *s1, float *t1, float *s2, float *t2 )
{
float xscale, yscale;
// scale for screen sizes
xscale = refState.width / (float)clgame.scrInfo.iWidth;
yscale = refState.height / (float)clgame.scrInfo.iHeight;
if( x ) *x *= xscale;
if( y ) *y *= yscale;
if( w ) *w *= xscale;
if( h ) *h *= yscale;
if( refState.width != clgame.scrInfo.iWidth )
{
// align to texel if scaling
*s1 += 0.5f;
*s2 -= 0.5f;
}
/*
====================
PictAdjustSize
draw hudsprite routine
====================
*/
void PicAdjustSize( float *x, float *y, float *w, float *h )
if( refState.height != clgame.scrInfo.iHeight )
{
if( !clgame.ds.adjust_size ) return;
// align to texel if scaling
*t1 += 0.5f;
*t2 -= 0.5f;
}
SPR_AdjustSize( x, y, w, h );
*s1 /= width;
*t1 /= height;
*s2 /= width;
*t2 /= height;
}
static qboolean SPR_Scissor( float *x, float *y, float *width, float *height, float *u0, float *v0, float *u1, float *v1 )
@ -468,9 +458,7 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei @@ -468,9 +458,7 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei
if( prc )
{
wrect_t rc;
rc = *prc;
wrect_t rc = *prc;
// Sigh! some stupid modmakers set wrong rectangles in hud.txt
if( rc.left <= 0 || rc.left >= width ) rc.left = 0;
@ -478,11 +466,13 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei @@ -478,11 +466,13 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei
if( rc.right <= 0 || rc.right > width ) rc.right = width;
if( rc.bottom <= 0 || rc.bottom > height ) rc.bottom = height;
s1 = rc.left;
t1 = rc.top;
s2 = rc.right;
t2 = rc.bottom;
// calc user-defined rectangle
s1 = (float)rc.left / width;
t1 = (float)rc.top / height;
s2 = (float)rc.right / width;
t2 = (float)rc.bottom / height;
SPR_AdjustTexCoords( width, height, &s1, &t1, &s2, &t2 );
width = rc.right - rc.left;
height = rc.bottom - rc.top;
}
@ -950,13 +940,16 @@ draw loading progress bar @@ -950,13 +940,16 @@ draw loading progress bar
*/
static void CL_DrawLoadingOrPaused( qboolean paused, float percent )
{
int x, y, width, height, right;
float x, y, width, height;
int iWidth, iHeight;
R_GetTextureParms( &width, &height, paused ? cls.pauseIcon : cls.loadingBar );
x = ( clgame.scrInfo.iWidth - width ) >> 1;
y = ( clgame.scrInfo.iHeight - height) >> 1;
R_GetTextureParms( &iWidth, &iHeight, paused ? cls.pauseIcon : cls.loadingBar );
x = ( clgame.scrInfo.iWidth - width ) / 2.0f;;
y = ( clgame.scrInfo.iHeight - height ) / 2.0f;
width = iWidth;
height = iHeight;
SPR_AdjustSizei( &x, &y, &width, &height );
SPR_AdjustSize( &x, &y, &width, &height );
if( !paused )
{
@ -1170,10 +1163,6 @@ static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite, @@ -1170,10 +1163,6 @@ static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite,
if( type == SPR_CLIENT || type == SPR_HUDSPRITE )
SetBits( m_pSprite->flags, MODEL_CLIENT );
// force nearest filter for hud sprites to have less artifacts with hud_scale
if( type == SPR_HUDSPRITE )
SetBits( texFlags, TF_NEAREST );
m_pSprite->numtexinfo = texFlags; // store texFlags into numtexinfo
if( !FS_FileExists( szSpriteName, false ) )

23
engine/client/cl_gameui.c

@ -487,10 +487,22 @@ static void PIC_DrawGeneric( float x, float y, float width, float height, const @@ -487,10 +487,22 @@ static void PIC_DrawGeneric( float x, float y, float width, float height, const
if( prc )
{
// calc user-defined rectangle
s1 = (float)prc->left / (float)w;
t1 = (float)prc->top / (float)h;
s2 = (float)prc->right / (float)w;
t2 = (float)prc->bottom / (float)h;
s1 = prc->left;
t1 = prc->top;
s2 = prc->right;
t2 = prc->bottom;
if( clgame.ds.adjust_size )
{
SPR_AdjustTexCoords( w, h, &s1, &t1, &s2, &t2 );
}
else
{
s1 /= (float)w;
t1 /= (float)h;
s2 /= (float)w;
t2 /= (float)h;
}
if( width == -1 && height == -1 )
{
@ -514,7 +526,8 @@ static void PIC_DrawGeneric( float x, float y, float width, float height, const @@ -514,7 +526,8 @@ static void PIC_DrawGeneric( float x, float y, float width, float height, const
if( gameui.ds.scissor_test && !PIC_Scissor( &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
return;
PicAdjustSize( &x, &y, &width, &height );
if( clgame.ds.adjust_size )
SPR_AdjustSize( &x, &y, &width, &height );
ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, gameui.ds.gl_texturenum );
ref.dllFuncs.Color4ub( 255, 255, 255, 255 );
}

3
engine/client/client.h

@ -824,7 +824,8 @@ model_t *CL_LoadClientSprite( const char *filename ); @@ -824,7 +824,8 @@ model_t *CL_LoadClientSprite( const char *filename );
model_t *CL_LoadModel( const char *modelname, int *index );
HSPRITE EXPORT pfnSPR_Load( const char *szPicName );
HSPRITE pfnSPR_LoadExt( const char *szPicName, uint texFlags );
void PicAdjustSize( float *x, float *y, float *w, float *h );
void SPR_AdjustSize( float *x, float *y, float *w, float *h );
void SPR_AdjustTexCoords( float width, float height, float *s1, float *t1, float *s2, float *t2 );
int CL_GetScreenInfo( SCREENINFO *pscrinfo );
void CL_FillRGBA( int x, int y, int width, int height, int r, int g, int b, int a );
void CL_PlayerTrace( float *start, float *end, int traceFlags, int ignore_pe, pmtrace_t *tr );

Loading…
Cancel
Save