@@ -27,6 +27,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
27
#include < iomanip>
28
28
#include " Material.h"
29
29
30
+ static Cvar::Cvar<bool > r_allowImageParamMismatch (
31
+ " r_allowImageParamMismatch" , " reuse images when requested with different parameters" ,
32
+ Cvar::NONE, false );
33
+
30
34
int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
31
35
int gl_filter_max = GL_LINEAR;
32
36
@@ -1813,26 +1817,32 @@ image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams )
1813
1817
{
1814
1818
if ( !Q_strnicmp ( imageName, image->name , sizeof ( image->name ) ) )
1815
1819
{
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 () )
1818
1821
{
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
+ }
1825
1824
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;
1830
1831
}
1831
1832
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 );
1833
1841
}
1834
1842
}
1835
1843
1844
+ const imageParams_t initialParams = imageParams;
1845
+
1836
1846
// Load and create the image.
1837
1847
int width = 0 , height = 0 , numLayers = 0 , numMips = 0 ;
1838
1848
byte *pic[ MAX_TEXTURE_MIPS * MAX_TEXTURE_LAYERS ];
@@ -1859,6 +1869,7 @@ image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams )
1859
1869
}
1860
1870
1861
1871
image_t *image = R_CreateImage ( imageName, (const byte **)pic, width, height, numMips, imageParams );
1872
+ image->initialParams = initialParams;
1862
1873
1863
1874
Z_Free ( *pic );
1864
1875
0 commit comments