ref: gl: add r_showtextures implementation by ncuxonaT

Main changes made by me besides engine differences:
* Text color changed to pure white for better readability
* An attempt to draw texture name in full size
This commit is contained in:
Alibek Omarov 2024-10-08 12:56:05 +03:00
parent 482dc3a5a5
commit f5ae806b31
3 changed files with 77 additions and 53 deletions

View file

@ -620,14 +620,16 @@ was there. This is used to test for texture thrashing.
*/ */
void R_ShowTextures( void ) void R_ShowTextures( void )
{ {
gl_texture_t *image; float w, h;
float x, y, w, h; int start;
int total, start, end; int i, k, base_w, base_h;
int i, j, k, base_w, base_h; rgba_t color = { 255, 255, 255, 255 };
rgba_t color = { 192, 192, 192, 255 }; int charHeight;
int charHeight, numTries = 0;
static qboolean showHelp = true; static qboolean showHelp = true;
string shortname; float time; //nc add
float time_cubemap; //nc add
float cbm_cos, cbm_sin; //nc add
int per_page; //nc add
if( !r_showtextures->value ) if( !r_showtextures->value )
return; return;
@ -638,85 +640,108 @@ void R_ShowTextures( void )
showHelp = false; showHelp = false;
} }
GL_SetRenderMode( kRenderNormal );
pglClear( GL_COLOR_BUFFER_BIT ); pglClear( GL_COLOR_BUFFER_BIT );
pglFinish();
base_w = 8; // textures view by horizontal w = 200;
base_h = 6; // textures view by vertical h = 200;
rebuild_page: time = gp_cl->time * 0.5f;
total = base_w * base_h; time -= floor( time );
start = total * (r_showtextures->value - 1); time_cubemap = gp_cl->time * 0.25f;
end = total * r_showtextures->value; time_cubemap -= floor( time_cubemap );
if( end > MAX_TEXTURES ) end = MAX_TEXTURES; time_cubemap *= 6.2831853f;
SinCos( time_cubemap, &cbm_sin, &cbm_cos );
w = gpGlobals->width / base_w;
h = gpGlobals->height / base_h;
gEngfuncs.Con_DrawStringLen( NULL, NULL, &charHeight ); gEngfuncs.Con_DrawStringLen( NULL, NULL, &charHeight );
for( i = j = 0; i < MAX_TEXTURES; i++ ) base_w = gpGlobals->width / w;
{ base_h = gpGlobals->height / ( h + charHeight * 2 );
image = R_GetTexture( i ); per_page = base_w * base_h;
if( j == start ) break; // found start start = per_page * ( r_showtextures->value - 1 );
if( pglIsTexture( image->texnum )) j++;
}
if( i == MAX_TEXTURES && r_showtextures->value != 1 ) GL_SetRenderMode( kRenderTransTexture ); //nc changed from normal to trans, Con_DrawString does this anyway
{
// bad case, rewind to one and try again
gEngfuncs.Cvar_SetValue( "r_showtextures", Q_max( 1, r_showtextures->value - 1 ));
if( ++numTries < 2 ) goto rebuild_page; // to prevent infinite loop
}
for( k = 0; i < MAX_TEXTURES; i++ ) for( k = 0; k < per_page; k++ )
{ {
if( j == end ) break; // page is full const gl_texture_t *image;
int textlen;
char text[MAX_VA_STRING];
string shortname;
float x, y;
i = k + start;
if ( i >= MAX_TEXTURES )
break;
image = R_GetTexture( i ); image = R_GetTexture( i );
if( !pglIsTexture( image->texnum )) if( !pglIsTexture( image->texnum ))
continue; continue;
x = k % base_w * w; x = k % base_w * gpGlobals->width / base_w;
y = k / base_w * h; y = k / base_w * gpGlobals->height / base_h;
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
GL_Bind( XASH_TEXTURE0, i ); // NOTE: don't use image->texnum here, because skybox has a 'wrong' indexes GL_Bind( XASH_TEXTURE0, image->texnum );
if( FBitSet( image->flags, TF_DEPTHMAP ) && !FBitSet( image->flags, TF_NOCOMPARE )) if( FBitSet( image->flags, TF_DEPTHMAP ) && !FBitSet( image->flags, TF_NOCOMPARE ))
pglTexParameteri( image->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE ); pglTexParameteri( image->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE );
pglBegin( GL_QUADS ); pglBegin( GL_QUADS );
pglTexCoord2f( 0, 0 ); if( image->target == GL_TEXTURE_CUBE_MAP_ARB )
pglVertex2f( x, y ); {
if( image->target == GL_TEXTURE_RECTANGLE_EXT ) pglTexCoord3f( 0.75 * cbm_cos - cbm_sin, 0.75 * cbm_sin + cbm_cos, 1.0 );
pglVertex2f( x, y );
pglTexCoord3f( 0.75 * cbm_cos + cbm_sin, 0.75 * cbm_sin - cbm_cos, 1.0 );
pglVertex2f( x + w, y );
pglTexCoord3f( 0.75 * cbm_cos + cbm_sin, 0.75 * cbm_sin - cbm_cos, -1.0 );
pglVertex2f( x + w, y + h );
pglTexCoord3f( 0.75 * cbm_cos - cbm_sin, 0.75 * cbm_sin + cbm_cos, -1.0 );
pglVertex2f( x, y + h );
}
else if( image->target == GL_TEXTURE_RECTANGLE_EXT )
{
pglTexCoord2f( 0, 0 );
pglVertex2f( x, y );
pglTexCoord2f( image->width, 0 ); pglTexCoord2f( image->width, 0 );
else pglTexCoord2f( 1, 0 ); pglVertex2f( x + w, y );
pglVertex2f( x + w, y );
if( image->target == GL_TEXTURE_RECTANGLE_EXT )
pglTexCoord2f( image->width, image->height ); pglTexCoord2f( image->width, image->height );
else pglTexCoord2f( 1, 1 ); pglVertex2f( x + w, y + h );
pglVertex2f( x + w, y + h );
if( image->target == GL_TEXTURE_RECTANGLE_EXT )
pglTexCoord2f( 0, image->height ); pglTexCoord2f( 0, image->height );
else pglTexCoord2f( 0, 1 ); pglVertex2f( x, y + h );
pglVertex2f( x, y + h ); }
else
{
pglTexCoord3f( 0, 0, time );
pglVertex2f( x, y );
pglTexCoord3f( 1, 0, time );
pglVertex2f( x + w, y );
pglTexCoord3f( 1, 1, time );
pglVertex2f( x + w, y + h );
pglTexCoord3f( 0, 1, time);
pglVertex2f( x, y + h );
}
pglEnd(); pglEnd();
if( FBitSet( image->flags, TF_DEPTHMAP ) && !FBitSet( image->flags, TF_NOCOMPARE )) if( FBitSet( image->flags, TF_DEPTHMAP ) && !FBitSet( image->flags, TF_NOCOMPARE ))
pglTexParameteri( image->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB ); pglTexParameteri( image->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
COM_FileBase( image->name, shortname, sizeof( shortname )); COM_FileBase( image->name, shortname, sizeof( shortname ));
if( Q_strlen( shortname ) > 18 ) gEngfuncs.Con_DrawStringLen( shortname, &textlen, NULL );
if( textlen > w )
{ {
// cutoff too long names, it looks ugly // cutoff too long names, it looks ugly
shortname[16] = '.'; shortname[16] = '.';
shortname[17] = '.'; shortname[17] = '.';
shortname[18] = '\0'; shortname[18] = '\0';
} }
gEngfuncs.Con_DrawString( x + 1, y + h - charHeight, shortname, color );
j++, k++; gEngfuncs.Con_DrawString( x + 1, y + h, shortname, color );
if( image->target == GL_TEXTURE_3D || image->target == GL_TEXTURE_2D_ARRAY_EXT )
Q_snprintf( text, sizeof( text ), "%ix%ix%i %s", image->width, image->height, image->depth, GL_TargetToString( image->target ));
else
Q_snprintf( text, sizeof( text ), "%ix%i %s", image->width, image->height, GL_TargetToString( image->target ));
gEngfuncs.Con_DrawString( x + 1, y + h + charHeight, text, color );
} }
gEngfuncs.CL_DrawCenterPrint (); gEngfuncs.CL_DrawCenterPrint ();

View file

@ -55,7 +55,7 @@ gl_texture_t *R_GetTexture( GLenum texnum )
GL_TargetToString GL_TargetToString
================= =================
*/ */
static const char *GL_TargetToString( GLenum target ) const char *GL_TargetToString( GLenum target )
{ {
switch( target ) switch( target )
{ {

View file

@ -354,6 +354,7 @@ void R_DrawModelHull( void );
// //
void R_SetTextureParameters( void ); void R_SetTextureParameters( void );
gl_texture_t *R_GetTexture( GLenum texnum ); gl_texture_t *R_GetTexture( GLenum texnum );
const char *GL_TargetToString( GLenum target );
#define GL_LoadTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, false ) #define GL_LoadTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, false )
#define GL_UpdateTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, true ) #define GL_UpdateTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, true )
int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags ); int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags );
@ -677,8 +678,6 @@ typedef struct
typedef struct typedef struct
{ {
int width, height;
int activeTMU; int activeTMU;
GLint currentTextures[MAX_TEXTURE_UNITS]; GLint currentTextures[MAX_TEXTURE_UNITS];
GLint currentTexturesIndex[MAX_TEXTURE_UNITS]; GLint currentTexturesIndex[MAX_TEXTURE_UNITS];