fixed /imageinfo and /shadermixeduse

This commit is contained in:
myT 2022-12-11 19:09:34 +01:00
parent 952da7c009
commit 6b9d35df8c
4 changed files with 49 additions and 31 deletions

View file

@ -143,21 +143,34 @@ void R_ImageInfo_f()
const char* const name = Cmd_Argv(1); const char* const name = Cmd_Argv(1);
const image_t* image = NULL; const image_t* image = NULL;
int imageIndex = -1;
for ( int i = 0; i < tr.numImages; i++ ) { for ( int i = 0; i < tr.numImages; i++ ) {
if ( !Q_stricmp( tr.images[i]->name, name ) ) { if ( !Q_stricmp( tr.images[i]->name, name ) ) {
image = tr.images[i]; image = tr.images[i];
imageIndex = i;
break; break;
} }
} }
if ( imageIndex < 0 ) {
ri.Printf( PRINT_ALL, "image not found\n" );
return;
}
char pakName[256]; char pakName[256];
if ( FS_GetPakPath( pakName, sizeof( pakName ), image->pakChecksum ) ) { if ( FS_GetPakPath( pakName, sizeof( pakName ), image->pakChecksum ) ) {
ri.Printf( PRINT_ALL, "%s/%s\n", pakName, image->name ); ri.Printf( PRINT_ALL, "%s/%s\n", pakName, image->name );
} }
ri.Printf( PRINT_ALL, "Used in these shaders:\n" ); ri.Printf( PRINT_ALL, "Used in these shaders:\n" );
for ( int s = 0; s < image->numShaders; ++s ) { for ( int is = 0; is < ARRAY_LEN( tr.imageShaders ); ++is ) {
const shader_t* const shader = tr.imageShaders[image->firstShaderIndex + s]; const int i = tr.imageShaders[is] & 0xFFFF;
if ( i != imageIndex ) {
continue;
}
const int s = (tr.imageShaders[is] >> 16) & 0xFFFF;
const shader_t* const shader = tr.shaders[s];
const qbool nmmS = shader->imgflags & IMG_NOMIPMAP; const qbool nmmS = shader->imgflags & IMG_NOMIPMAP;
const qbool npmS = shader->imgflags & IMG_NOPICMIP; const qbool npmS = shader->imgflags & IMG_NOPICMIP;
ri.Printf( PRINT_ALL, "%s %s %s\n", ri.Printf( PRINT_ALL, "%s %s %s\n",
@ -391,6 +404,11 @@ image_t* R_CreateImage( const char* name, byte* pic, int width, int height, text
image->height = height; image->height = height;
image->wrapClampMode = glWrapClampMode; image->wrapClampMode = glWrapClampMode;
image->index = tr.numImages;
image->numShaders = 0;
image->flags0 = 0;
image->flags1 = 0;
tr.numImages++; tr.numImages++;
Upload32( image, (unsigned int*)pic ); Upload32( image, (unsigned int*)pic );
@ -1182,13 +1200,18 @@ void R_AddImageShader( image_t* image, shader_t* shader )
if (tr.numImageShaders >= ARRAY_LEN( tr.imageShaders )) if (tr.numImageShaders >= ARRAY_LEN( tr.imageShaders ))
return; return;
const int imageShader = (shader->index << 16) | image->index;
for (int is = 0; is < tr.numImageShaders; ++is) {
if (tr.imageShaders[is] == imageShader)
return;
}
// we consider index 0 to be invalid // we consider index 0 to be invalid
if (tr.numImageShaders == 0) if (tr.numImageShaders == 0)
tr.numImageShaders++; tr.numImageShaders++;
tr.imageShaders[tr.numImageShaders] = shader; tr.imageShaders[tr.numImageShaders++] = imageShader;
if (image->firstShaderIndex == 0)
image->firstShaderIndex = tr.numImageShaders;
image->numShaders++; image->numShaders++;
tr.numImageShaders++; image->flags0 |= shader->imgflags ^ -1;
image->flags1 |= shader->imgflags;
} }

View file

@ -343,7 +343,7 @@ static const cmdTableItem_t r_cmds[] =
{ "imageinfo", R_ImageInfo_f, NULL, "prints info for a specific image" }, { "imageinfo", R_ImageInfo_f, NULL, "prints info for a specific image" },
{ "shaderlist", R_ShaderList_f, NULL, "prints loaded shaders" }, { "shaderlist", R_ShaderList_f, NULL, "prints loaded shaders" },
{ "shaderinfo", R_ShaderInfo_f, R_CompleteShaderName_f, "prints info for a specific shader" }, { "shaderinfo", R_ShaderInfo_f, R_CompleteShaderName_f, "prints info for a specific shader" },
{ "shadermixeduse", R_MixedUse_f, NULL, "prints all mixed use issues" }, { "shadermixeduse", R_ShaderMixedUse_f, NULL, "prints all mixed use issues" },
{ "skinlist", R_SkinList_f, NULL, "prints loaded skins" }, { "skinlist", R_SkinList_f, NULL, "prints loaded skins" },
{ "modellist", R_Modellist_f, NULL, "prints loaded models" }, { "modellist", R_Modellist_f, NULL, "prints loaded models" },
{ "screenshot", R_ScreenShotTGA_f, NULL, "takes a TARGA (.tga) screenshot" }, { "screenshot", R_ScreenShotTGA_f, NULL, "takes a TARGA (.tga) screenshot" },

View file

@ -101,11 +101,11 @@ struct image_t {
char name[MAX_QPATH]; // game path, including extension char name[MAX_QPATH]; // game path, including extension
// used to index into tr.imageShaders
int firstShaderIndex;
int numShaders;
int pakChecksum; int pakChecksum;
int index; // indexes tr.images
int numShaders; // number of shaders referencing this image
int flags0; // flags requested to be 0 by at least 1 shader
int flags1; // flags requested to be 1 by at least 1 shader
}; };
@ -916,7 +916,9 @@ typedef struct {
int numImages; int numImages;
image_t* images[MAX_DRAWIMAGES]; image_t* images[MAX_DRAWIMAGES];
shader_t* imageShaders[2048]; // associative array of image_t and shader_t indices where each entry is unique
// the indices index into tr.images and tr.shaders
int imageShaders[2048]; // shader index in high 16 bits, image index in low 16 bits
int numImageShaders; int numImageShaders;
// shader indexes from other modules will be looked up in tr.shaders[] // shader indexes from other modules will be looked up in tr.shaders[]
@ -1209,7 +1211,7 @@ const shader_t* R_GetShaderByHandle( qhandle_t hShader );
void R_InitShaders(); void R_InitShaders();
void R_ShaderList_f( void ); void R_ShaderList_f( void );
void R_ShaderInfo_f(); void R_ShaderInfo_f();
void R_MixedUse_f(); void R_ShaderMixedUse_f();
void R_CompleteShaderName_f( int startArg, int compArg ); void R_CompleteShaderName_f( int startArg, int compArg );
const char* R_GetShaderPath( const shader_t* shader ); const char* R_GetShaderPath( const shader_t* shader );

View file

@ -2912,7 +2912,7 @@ void R_ShaderInfo_f()
} }
void R_MixedUse_f() void R_ShaderMixedUse_f()
{ {
for ( int i = 0; i < tr.numImages; ++i ) { for ( int i = 0; i < tr.numImages; ++i ) {
image_t* const image = tr.images[i]; image_t* const image = tr.images[i];
@ -2920,27 +2920,20 @@ void R_MixedUse_f()
continue; continue;
} }
const qbool nmm0 = tr.imageShaders[image->firstShaderIndex]->imgflags & IMG_NOMIPMAP; const int mixedFlags = image->flags0 & image->flags1;
const qbool npm0 = tr.imageShaders[image->firstShaderIndex]->imgflags & IMG_NOPICMIP; if ( ( mixedFlags & ( IMG_NOMIPMAP | IMG_NOPICMIP ) ) == 0 ) {
qbool mixed = qfalse;
for ( int s = 1; s < image->numShaders; ++s ) {
const shader_t* const shader = tr.imageShaders[image->firstShaderIndex + s];
const qbool nmmS = shader->imgflags & IMG_NOMIPMAP;
const qbool npmS = shader->imgflags & IMG_NOPICMIP;
if ( nmmS != nmm0 || npmS != npm0 ) {
mixed = qtrue;
break;
}
}
if ( !mixed ) {
continue; continue;
} }
ri.Printf( PRINT_ALL, "^5%s:\n", image->name ); ri.Printf( PRINT_ALL, "^5%s:\n", image->name );
for ( int s = 0; s < image->numShaders; ++s ) { for ( int is = 0; is < ARRAY_LEN( tr.imageShaders ); ++is ) {
const shader_t* const shader = tr.imageShaders[image->firstShaderIndex + s]; const int imageIndex = tr.imageShaders[is] & 0xFFFF;
if ( imageIndex != i ) {
continue;
}
const int s = (tr.imageShaders[is] >> 16) & 0xFFFF;
const shader_t* const shader = tr.shaders[s];
const qbool nmmS = shader->imgflags & IMG_NOMIPMAP; const qbool nmmS = shader->imgflags & IMG_NOMIPMAP;
const qbool npmS = shader->imgflags & IMG_NOPICMIP; const qbool npmS = shader->imgflags & IMG_NOPICMIP;
ri.Printf( PRINT_ALL, "%s %s %s\n", ri.Printf( PRINT_ALL, "%s %s %s\n",