From 6b9d35df8c5a2035b65fbcb88ea87807a256b56e Mon Sep 17 00:00:00 2001 From: myT Date: Sun, 11 Dec 2022 19:09:34 +0100 Subject: [PATCH] fixed /imageinfo and /shadermixeduse --- code/renderer/tr_image.cpp | 35 +++++++++++++++++++++++++++++------ code/renderer/tr_init.cpp | 2 +- code/renderer/tr_local.h | 14 ++++++++------ code/renderer/tr_shader.cpp | 29 +++++++++++------------------ 4 files changed, 49 insertions(+), 31 deletions(-) diff --git a/code/renderer/tr_image.cpp b/code/renderer/tr_image.cpp index 3746938..29e90d9 100644 --- a/code/renderer/tr_image.cpp +++ b/code/renderer/tr_image.cpp @@ -143,21 +143,34 @@ void R_ImageInfo_f() const char* const name = Cmd_Argv(1); const image_t* image = NULL; + int imageIndex = -1; for ( int i = 0; i < tr.numImages; i++ ) { if ( !Q_stricmp( tr.images[i]->name, name ) ) { image = tr.images[i]; + imageIndex = i; break; } } + if ( imageIndex < 0 ) { + ri.Printf( PRINT_ALL, "image not found\n" ); + return; + } + char pakName[256]; if ( FS_GetPakPath( pakName, sizeof( pakName ), image->pakChecksum ) ) { ri.Printf( PRINT_ALL, "%s/%s\n", pakName, image->name ); } ri.Printf( PRINT_ALL, "Used in these shaders:\n" ); - for ( int s = 0; s < image->numShaders; ++s ) { - const shader_t* const shader = tr.imageShaders[image->firstShaderIndex + s]; + for ( int is = 0; is < ARRAY_LEN( tr.imageShaders ); ++is ) { + 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 npmS = shader->imgflags & IMG_NOPICMIP; 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->wrapClampMode = glWrapClampMode; + image->index = tr.numImages; + image->numShaders = 0; + image->flags0 = 0; + image->flags1 = 0; + tr.numImages++; 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 )) 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 if (tr.numImageShaders == 0) tr.numImageShaders++; - tr.imageShaders[tr.numImageShaders] = shader; - if (image->firstShaderIndex == 0) - image->firstShaderIndex = tr.numImageShaders; + tr.imageShaders[tr.numImageShaders++] = imageShader; image->numShaders++; - tr.numImageShaders++; + image->flags0 |= shader->imgflags ^ -1; + image->flags1 |= shader->imgflags; } diff --git a/code/renderer/tr_init.cpp b/code/renderer/tr_init.cpp index 742baa3..82cbbfe 100644 --- a/code/renderer/tr_init.cpp +++ b/code/renderer/tr_init.cpp @@ -343,7 +343,7 @@ static const cmdTableItem_t r_cmds[] = { "imageinfo", R_ImageInfo_f, NULL, "prints info for a specific image" }, { "shaderlist", R_ShaderList_f, NULL, "prints loaded shaders" }, { "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" }, { "modellist", R_Modellist_f, NULL, "prints loaded models" }, { "screenshot", R_ScreenShotTGA_f, NULL, "takes a TARGA (.tga) screenshot" }, diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index da1059c..177c91a 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -101,11 +101,11 @@ struct image_t { char name[MAX_QPATH]; // game path, including extension - // used to index into tr.imageShaders - int firstShaderIndex; - int numShaders; - 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; 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; // 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_ShaderList_f( void ); void R_ShaderInfo_f(); -void R_MixedUse_f(); +void R_ShaderMixedUse_f(); void R_CompleteShaderName_f( int startArg, int compArg ); const char* R_GetShaderPath( const shader_t* shader ); diff --git a/code/renderer/tr_shader.cpp b/code/renderer/tr_shader.cpp index 888cb7b..cfe950d 100644 --- a/code/renderer/tr_shader.cpp +++ b/code/renderer/tr_shader.cpp @@ -2912,7 +2912,7 @@ void R_ShaderInfo_f() } -void R_MixedUse_f() +void R_ShaderMixedUse_f() { for ( int i = 0; i < tr.numImages; ++i ) { image_t* const image = tr.images[i]; @@ -2920,27 +2920,20 @@ void R_MixedUse_f() continue; } - const qbool nmm0 = tr.imageShaders[image->firstShaderIndex]->imgflags & IMG_NOMIPMAP; - const qbool npm0 = tr.imageShaders[image->firstShaderIndex]->imgflags & IMG_NOPICMIP; - - 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 ) { + const int mixedFlags = image->flags0 & image->flags1; + if ( ( mixedFlags & ( IMG_NOMIPMAP | IMG_NOPICMIP ) ) == 0 ) { continue; } ri.Printf( PRINT_ALL, "^5%s:\n", image->name ); - for ( int s = 0; s < image->numShaders; ++s ) { - const shader_t* const shader = tr.imageShaders[image->firstShaderIndex + s]; + for ( int is = 0; is < ARRAY_LEN( tr.imageShaders ); ++is ) { + 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 npmS = shader->imgflags & IMG_NOPICMIP; ri.Printf( PRINT_ALL, "%s %s %s\n",