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. 91
      engine/client/cl_game.c
  2. 23
      engine/client/cl_gameui.c
  3. 3
      engine/client/client.h

91
engine/client/cl_game.c

@ -345,53 +345,43 @@ SPR_AdjustSize
draw hudsprite routine 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; float xscale, yscale;
// scale for screen sizes if( refState.width == clgame.scrInfo.iWidth && refState.height == clgame.scrInfo.iHeight )
xscale = refState.width / (float)clgame.scrInfo.iWidth; return;
yscale = refState.height / (float)clgame.scrInfo.iHeight;
if( x ) *x *= xscale;
if( y ) *y *= yscale;
if( w ) *w *= xscale;
if( h ) *h *= yscale;
}
/*
====================
SPR_AdjustSize
draw hudsprite routine
====================
*/
static void SPR_AdjustSizei( int *x, int *y, int *w, int *h )
{
float xscale, yscale;
// scale for screen sizes // scale for screen sizes
xscale = refState.width / (float)clgame.scrInfo.iWidth; xscale = refState.width / (float)clgame.scrInfo.iWidth;
yscale = refState.height / (float)clgame.scrInfo.iHeight; yscale = refState.height / (float)clgame.scrInfo.iHeight;
if( x ) *x *= xscale; *x *= xscale;
if( y ) *y *= yscale; *y *= yscale;
if( w ) *w *= xscale; *w *= xscale;
if( h ) *h *= yscale; *h *= yscale;
} }
/* void SPR_AdjustTexCoords( float width, float height, float *s1, float *t1, float *s2, float *t2 )
====================
PictAdjustSize
draw hudsprite routine
====================
*/
void PicAdjustSize( float *x, float *y, float *w, float *h )
{ {
if( !clgame.ds.adjust_size ) return; if( refState.width != clgame.scrInfo.iWidth )
{
// align to texel if scaling
*s1 += 0.5f;
*s2 -= 0.5f;
}
SPR_AdjustSize( x, y, w, h ); if( refState.height != clgame.scrInfo.iHeight )
{
// align to texel if scaling
*t1 += 0.5f;
*t2 -= 0.5f;
}
*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 ) 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
if( prc ) if( prc )
{ {
wrect_t rc; wrect_t rc = *prc;
rc = *prc;
// Sigh! some stupid modmakers set wrong rectangles in hud.txt // Sigh! some stupid modmakers set wrong rectangles in hud.txt
if( rc.left <= 0 || rc.left >= width ) rc.left = 0; 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
if( rc.right <= 0 || rc.right > width ) rc.right = width; if( rc.right <= 0 || rc.right > width ) rc.right = width;
if( rc.bottom <= 0 || rc.bottom > height ) rc.bottom = height; 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 // calc user-defined rectangle
s1 = (float)rc.left / width; SPR_AdjustTexCoords( width, height, &s1, &t1, &s2, &t2 );
t1 = (float)rc.top / height;
s2 = (float)rc.right / width;
t2 = (float)rc.bottom / height;
width = rc.right - rc.left; width = rc.right - rc.left;
height = rc.bottom - rc.top; height = rc.bottom - rc.top;
} }
@ -950,13 +940,16 @@ draw loading progress bar
*/ */
static void CL_DrawLoadingOrPaused( qboolean paused, float percent ) 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 ); R_GetTextureParms( &iWidth, &iHeight, paused ? cls.pauseIcon : cls.loadingBar );
x = ( clgame.scrInfo.iWidth - width ) >> 1; x = ( clgame.scrInfo.iWidth - width ) / 2.0f;;
y = ( clgame.scrInfo.iHeight - height) >> 1; 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 ) if( !paused )
{ {
@ -1170,10 +1163,6 @@ static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite,
if( type == SPR_CLIENT || type == SPR_HUDSPRITE ) if( type == SPR_CLIENT || type == SPR_HUDSPRITE )
SetBits( m_pSprite->flags, MODEL_CLIENT ); 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 m_pSprite->numtexinfo = texFlags; // store texFlags into numtexinfo
if( !FS_FileExists( szSpriteName, false ) ) 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
if( prc ) if( prc )
{ {
// calc user-defined rectangle // calc user-defined rectangle
s1 = (float)prc->left / (float)w; s1 = prc->left;
t1 = (float)prc->top / (float)h; t1 = prc->top;
s2 = (float)prc->right / (float)w; s2 = prc->right;
t2 = (float)prc->bottom / (float)h; 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 ) if( width == -1 && height == -1 )
{ {
@ -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 )) if( gameui.ds.scissor_test && !PIC_Scissor( &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
return; 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.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, gameui.ds.gl_texturenum );
ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); ref.dllFuncs.Color4ub( 255, 255, 255, 255 );
} }

3
engine/client/client.h

@ -824,7 +824,8 @@ model_t *CL_LoadClientSprite( const char *filename );
model_t *CL_LoadModel( const char *modelname, int *index ); model_t *CL_LoadModel( const char *modelname, int *index );
HSPRITE EXPORT pfnSPR_Load( const char *szPicName ); HSPRITE EXPORT pfnSPR_Load( const char *szPicName );
HSPRITE pfnSPR_LoadExt( const char *szPicName, uint texFlags ); 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 ); 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_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 ); void CL_PlayerTrace( float *start, float *end, int traceFlags, int ignore_pe, pmtrace_t *tr );

Loading…
Cancel
Save