Browse Source

engine: client: consolidate client and menu scissor functions

pull/2/head
Alibek Omarov 2 years ago
parent
commit
c0fa91bec9
  1. 149
      engine/client/cl_game.c
  2. 64
      engine/client/cl_gameui.c
  3. 32
      engine/client/client.h

149
engine/client/cl_game.c

@ -371,55 +371,6 @@ void SPR_AdjustTexCoords( float width, float height, float *s1, float *t1, float @@ -371,55 +371,6 @@ void SPR_AdjustTexCoords( float width, float height, float *s1, float *t1, float
*t2 /= height;
}
static qboolean SPR_Scissor( float *x, float *y, float *width, float *height, float *u0, float *v0, float *u1, float *v1 )
{
float dudx, dvdy;
// clip sub rect to sprite
if(( width == 0 ) || ( height == 0 ))
return false;
if( *x + *width <= clgame.ds.scissor_x )
return false;
if( *x >= clgame.ds.scissor_x + clgame.ds.scissor_width )
return false;
if( *y + *height <= clgame.ds.scissor_y )
return false;
if( *y >= clgame.ds.scissor_y + clgame.ds.scissor_height )
return false;
dudx = (*u1 - *u0) / *width;
dvdy = (*v1 - *v0) / *height;
if( *x < clgame.ds.scissor_x )
{
*u0 += (clgame.ds.scissor_x - *x) * dudx;
*width -= clgame.ds.scissor_x - *x;
*x = clgame.ds.scissor_x;
}
if( *x + *width > clgame.ds.scissor_x + clgame.ds.scissor_width )
{
*u1 -= (*x + *width - (clgame.ds.scissor_x + clgame.ds.scissor_width)) * dudx;
*width = clgame.ds.scissor_x + clgame.ds.scissor_width - *x;
}
if( *y < clgame.ds.scissor_y )
{
*v0 += (clgame.ds.scissor_y - *y) * dvdy;
*height -= clgame.ds.scissor_y - *y;
*y = clgame.ds.scissor_y;
}
if( *y + *height > clgame.ds.scissor_y + clgame.ds.scissor_height )
{
*v1 -= (*y + *height - (clgame.ds.scissor_y + clgame.ds.scissor_height)) * dvdy;
*height = clgame.ds.scissor_y + clgame.ds.scissor_height - *y;
}
return true;
}
/*
====================
SPR_DrawGeneric
@ -470,7 +421,7 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei @@ -470,7 +421,7 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei
}
// pass scissor test if supposed
if( clgame.ds.scissor_test && !SPR_Scissor( &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
if( !CL_Scissor( &clgame.ds.scissor, &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
return;
// scale for screen sizes
@ -825,6 +776,92 @@ const char *CL_SoundFromIndex( int index ) @@ -825,6 +776,92 @@ const char *CL_SoundFromIndex( int index )
return sfx->name;
}
/*
================
CL_EnableScissor
enable scissor test
================
*/
void CL_EnableScissor( scissor_state_t *scissor, int x, int y, int width, int height )
{
scissor->x = x;
scissor->y = y;
scissor->width = width;
scissor->height = height;
scissor->test = true;
}
/*
================
CL_DisableScissor
disable scissor test
================
*/
void CL_DisableScissor( scissor_state_t *scissor )
{
scissor->test = false;
}
/*
================
CL_Scissor
perform common scissor test
================
*/
qboolean CL_Scissor( const scissor_state_t *scissor, float *x, float *y, float *width, float *height, float *u0, float *v0, float *u1, float *v1 )
{
float dudx, dvdy;
if( !scissor->test )
return true;
// clip sub rect to sprite
if( *width == 0 || *height == 0 )
return false;
if( *x + *width <= scissor->x )
return false;
if( *x >= scissor->x + scissor->width )
return false;
if( *y + *height <= scissor->y )
return false;
if( *y >= scissor->y + scissor->height )
return false;
dudx = (*u1 - *u0) / *width;
dvdy = (*v1 - *v0) / *height;
if( *x < scissor->x )
{
*u0 += (scissor->x - *x) * dudx;
*width -= scissor->x - *x;
*x = scissor->x;
}
if( *x + *width > scissor->x + scissor->width )
{
*u1 -= (*x + *width - (scissor->x + scissor->width)) * dudx;
*width = scissor->x + scissor->width - *x;
}
if( *y < scissor->y )
{
*v0 += (scissor->y - *y) * dvdy;
*height -= scissor->y - *y;
*y = scissor->y;
}
if( *y + *height > scissor->y + scissor->height )
{
*v1 -= (*y + *height - (scissor->y + scissor->height)) * dvdy;
*height = scissor->y + scissor->height - *y;
}
return true;
}
/*
=========
SPR_EnableScissor
@ -839,11 +876,7 @@ static void GAME_EXPORT SPR_EnableScissor( int x, int y, int width, int height ) @@ -839,11 +876,7 @@ static void GAME_EXPORT SPR_EnableScissor( int x, int y, int width, int height )
width = bound( 0, width, clgame.scrInfo.iWidth - x );
height = bound( 0, height, clgame.scrInfo.iHeight - y );
clgame.ds.scissor_x = x;
clgame.ds.scissor_width = width;
clgame.ds.scissor_y = y;
clgame.ds.scissor_height = height;
clgame.ds.scissor_test = true;
CL_EnableScissor( &clgame.ds.scissor, x, y, width, height );
}
/*
@ -854,11 +887,7 @@ SPR_DisableScissor @@ -854,11 +887,7 @@ SPR_DisableScissor
*/
static void GAME_EXPORT SPR_DisableScissor( void )
{
clgame.ds.scissor_x = 0;
clgame.ds.scissor_width = 0;
clgame.ds.scissor_y = 0;
clgame.ds.scissor_height = 0;
clgame.ds.scissor_test = false;
CL_DisableScissor( &clgame.ds.scissor );
}
/*

64
engine/client/cl_gameui.c

@ -421,54 +421,6 @@ static void UI_ConvertGameInfo( GAMEINFO *out, gameinfo_t *in ) @@ -421,54 +421,6 @@ static void UI_ConvertGameInfo( GAMEINFO *out, gameinfo_t *in )
out->flags |= GFL_RENDER_PICBUTTON_TEXT;
}
static qboolean PIC_Scissor( float *x, float *y, float *width, float *height, float *u0, float *v0, float *u1, float *v1 )
{
float dudx, dvdy;
// clip sub rect to sprite
if(( width == 0 ) || ( height == 0 ))
return false;
if( *x + *width <= gameui.ds.scissor_x )
return false;
if( *x >= gameui.ds.scissor_x + gameui.ds.scissor_width )
return false;
if( *y + *height <= gameui.ds.scissor_y )
return false;
if( *y >= gameui.ds.scissor_y + gameui.ds.scissor_height )
return false;
dudx = (*u1 - *u0) / *width;
dvdy = (*v1 - *v0) / *height;
if( *x < gameui.ds.scissor_x )
{
*u0 += (gameui.ds.scissor_x - *x) * dudx;
*width -= gameui.ds.scissor_x - *x;
*x = gameui.ds.scissor_x;
}
if( *x + *width > gameui.ds.scissor_x + gameui.ds.scissor_width )
{
*u1 -= (*x + *width - (gameui.ds.scissor_x + gameui.ds.scissor_width)) * dudx;
*width = gameui.ds.scissor_x + gameui.ds.scissor_width - *x;
}
if( *y < gameui.ds.scissor_y )
{
*v0 += (gameui.ds.scissor_y - *y) * dvdy;
*height -= gameui.ds.scissor_y - *y;
*y = gameui.ds.scissor_y;
}
if( *y + *height > gameui.ds.scissor_y + gameui.ds.scissor_height )
{
*v1 -= (*y + *height - (gameui.ds.scissor_y + gameui.ds.scissor_height)) * dvdy;
*height = gameui.ds.scissor_y + gameui.ds.scissor_height - *y;
}
return true;
}
/*
====================
PIC_DrawGeneric
@ -511,7 +463,7 @@ static void PIC_DrawGeneric( float x, float y, float width, float height, const @@ -511,7 +463,7 @@ static void PIC_DrawGeneric( float x, float y, float width, float height, const
}
// pass scissor test if supposed
if( gameui.ds.scissor_test && !PIC_Scissor( &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
if( !CL_Scissor( &gameui.ds.scissor, &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
return;
ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, gameui.ds.gl_texturenum );
@ -658,11 +610,7 @@ static void GAME_EXPORT pfnPIC_EnableScissor( int x, int y, int width, int heigh @@ -658,11 +610,7 @@ static void GAME_EXPORT pfnPIC_EnableScissor( int x, int y, int width, int heigh
width = bound( 0, width, gameui.globals->scrWidth - x );
height = bound( 0, height, gameui.globals->scrHeight - y );
gameui.ds.scissor_x = x;
gameui.ds.scissor_width = width;
gameui.ds.scissor_y = y;
gameui.ds.scissor_height = height;
gameui.ds.scissor_test = true;
CL_EnableScissor( &gameui.ds.scissor, x, y, width, height );
}
/*
@ -673,11 +621,7 @@ pfnPIC_DisableScissor @@ -673,11 +621,7 @@ pfnPIC_DisableScissor
*/
static void GAME_EXPORT pfnPIC_DisableScissor( void )
{
gameui.ds.scissor_x = 0;
gameui.ds.scissor_width = 0;
gameui.ds.scissor_y = 0;
gameui.ds.scissor_height = 0;
gameui.ds.scissor_test = false;
CL_DisableScissor( &gameui.ds.scissor );
}
/*
@ -765,7 +709,7 @@ static void GAME_EXPORT pfnDrawCharacter( int ix, int iy, int iwidth, int iheigh @@ -765,7 +709,7 @@ static void GAME_EXPORT pfnDrawCharacter( int ix, int iy, int iwidth, int iheigh
t2 = t1 + size;
// pass scissor test if supposed
if( gameui.ds.scissor_test && !PIC_Scissor( &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
if( !CL_Scissor( &gameui.ds.scissor, &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
return;
ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture );

32
engine/client/client.h

@ -340,18 +340,23 @@ typedef struct @@ -340,18 +340,23 @@ typedef struct
qboolean valid; // all rectangles are valid
} cl_font_t;
typedef struct scissor_state_s
{
int x;
int y;
int width;
int height;
qboolean test;
} scissor_state_t;
typedef struct
{
// scissor test
scissor_state_t scissor;
// temp handle
const model_t *pSprite; // pointer to current SpriteTexture
// scissor test
int scissor_x;
int scissor_y;
int scissor_width;
int scissor_height;
qboolean scissor_test;
int renderMode; // override kRenderMode from TriAPI
TRICULLSTYLE cullMode; // override CULL FACE from TriAPI
@ -378,14 +383,10 @@ typedef struct cl_predicted_player_s @@ -378,14 +383,10 @@ typedef struct cl_predicted_player_s
typedef struct
{
int gl_texturenum; // this is a real texnum
// scissor test
int scissor_x;
int scissor_y;
int scissor_width;
int scissor_height;
qboolean scissor_test;
scissor_state_t scissor;
int gl_texturenum; // this is a real texnum
// holds text color
rgba_t textColor;
@ -862,6 +863,9 @@ void pfnGetScreenFade( struct screenfade_s *fade ); @@ -862,6 +863,9 @@ void pfnGetScreenFade( struct screenfade_s *fade );
physent_t *pfnGetPhysent( int idx );
struct msurface_s *pfnTraceSurface( int ground, float *vstart, float *vend );
movevars_t *pfnGetMoveVars( void );
void CL_EnableScissor( scissor_state_t *scissor, int x, int y, int width, int height );
void CL_DisableScissor( scissor_state_t *scissor );
qboolean CL_Scissor( const scissor_state_t *scissor, float *x, float *y, float *width, float *height, float *u0, float *v0, float *u1, float *v1 );
_inline cl_entity_t *CL_EDICT_NUM( int n )
{

Loading…
Cancel
Save