@@ -27,6 +27,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2727#include < iomanip>
2828#include " Material.h"
2929
30+ static Cvar::Cvar<bool > r_allowImageParamMismatch (
31+ " r_allowImageParamMismatch" , " reuse images when requested with different parameters" ,
32+ Cvar::NONE, false );
33+
3034int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
3135int gl_filter_max = GL_LINEAR;
3236
@@ -1813,26 +1817,32 @@ image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams )
18131817 {
18141818 if ( !Q_strnicmp ( imageName, image->name , sizeof ( image->name ) ) )
18151819 {
1816- // The white image can be used with any set of parms, but other mismatches are errors.
1817- if ( Q_stricmp ( imageName, " _white" ) )
1820+ if ( imageParams == image->initialParams || r_allowImageParamMismatch.Get () )
18181821 {
1819- unsigned int diff = imageParams.bits ^ image->bits ;
1820-
1821- if ( diff & IF_NOPICMIP )
1822- {
1823- Log::Warn (" reused image '%s' with mixed allowPicmip parm for shader" , imageName );
1824- }
1822+ return image;
1823+ }
18251824
1826- if ( image->wrapType != imageParams.wrapType )
1827- {
1828- Log::Warn (" reused image '%s' with mixed glWrapType parm for shader" , imageName);
1829- }
1825+ // Built-in images can't be reloaded with different parameters, so return them as-is.
1826+ // For most of the usable ones e.g. _white, parameters wouldn't make a difference anyway.
1827+ // HACK: detect built-in images by naming convention, though nothing stops users from using such names
1828+ if ( image->name [ 0 ] == ' _' && !strchr ( image->name , ' /' ) )
1829+ {
1830+ return image;
18301831 }
18311832
1832- return image;
1833+ Log::Verbose ( " image params mismatch for %s: 0x%X %d %d/%d %d %d vs. 0x%X %d %d/%d %d %d" ,
1834+ imageName,
1835+ image->initialParams .bits , Util::ordinal ( image->initialParams .filterType ),
1836+ Util::ordinal ( image->initialParams .wrapType .s ), Util::ordinal ( image->initialParams .wrapType .t ),
1837+ image->initialParams .minDimension , image->initialParams .maxDimension ,
1838+ imageParams.bits , Util::ordinal ( imageParams.filterType ),
1839+ Util::ordinal ( imageParams.wrapType .s ), Util::ordinal ( imageParams.wrapType .t ),
1840+ imageParams.minDimension , imageParams.maxDimension );
18331841 }
18341842 }
18351843
1844+ const imageParams_t initialParams = imageParams;
1845+
18361846 // Load and create the image.
18371847 int width = 0 , height = 0 , numLayers = 0 , numMips = 0 ;
18381848 byte *pic[ MAX_TEXTURE_MIPS * MAX_TEXTURE_LAYERS ];
@@ -1859,6 +1869,7 @@ image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams )
18591869 }
18601870
18611871 image_t *image = R_CreateImage ( imageName, (const byte **)pic, width, height, numMips, imageParams );
1872+ image->initialParams = initialParams;
18621873
18631874 Z_Free ( *pic );
18641875
0 commit comments