Skip to content

Commit a2383c6

Browse files
committed
Allow reusing image requested with lower min detail
When an image is requested to be loaded with different params (imageParams_t), but the only difference is that the first one had a larger minDimension, reuse the image. This happens with the models/buildables/arm/screen_s specular image, which is used with two diffuse maps that want different imageMinDimension.
1 parent 48f57a2 commit a2383c6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/engine/renderer/tr_image.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,14 +1826,33 @@ image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams )
18261826
return image;
18271827
}
18281828

1829-
Log::Verbose( "image params mismatch for %s: 0x%X %d %d/%d %d %d vs. 0x%X %d %d/%d %d %d",
1829+
bool compatible = false;
1830+
1831+
if ( image->initialParams.minDimension > imageParams.minDimension )
1832+
{
1833+
// Reuse the image if the only difference is that the minimum level of detail is lower.
1834+
// We could imagine a similar test for imageMaxDimension, but that keyword has never been
1835+
// used and the potential motivations are less than clear, so don't bother.
1836+
imageParams_t test = imageParams;
1837+
test.minDimension = image->initialParams.minDimension;
1838+
compatible = test == image->initialParams;
1839+
}
1840+
1841+
Log::Verbose( "image params mismatch for %s: 0x%X %d %d/%d %d %d vs. 0x%X %d %d/%d %d %d, %s",
18301842
imageName,
18311843
image->initialParams.bits, Util::ordinal( image->initialParams.filterType ),
18321844
Util::ordinal( image->initialParams.wrapType.s ), Util::ordinal( image->initialParams.wrapType.t ),
18331845
image->initialParams.minDimension, image->initialParams.maxDimension,
18341846
imageParams.bits, Util::ordinal( imageParams.filterType ),
18351847
Util::ordinal( imageParams.wrapType.s ), Util::ordinal( imageParams.wrapType.t ),
1836-
imageParams.minDimension, imageParams.maxDimension );
1848+
imageParams.minDimension, imageParams.maxDimension,
1849+
compatible ? "reusing previous image since compatible" : "loading new version of image" );
1850+
1851+
if ( compatible )
1852+
{
1853+
return image;
1854+
}
1855+
// TODO replace the old image if it's compatible in the other direction? Not sure if it's safe
18371856
}
18381857
}
18391858

0 commit comments

Comments
 (0)