Skip to content

Commit d436770

Browse files
committed
Allow loading an image multiple times with different params
E.g. different nopicmip or imageMaxDimension. Fixes Unvanquished/Unvanquished#2801
1 parent 6353c46 commit d436770

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/engine/renderer/tr_image.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3034
int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
3135
int 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

src/engine/renderer/tr_local.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,20 @@ enum class ssaoMode {
523523
wrapType_t wrapType;
524524
int minDimension = 0;
525525
int maxDimension = 0;
526+
527+
bool operator==(const imageParams_t &o) const
528+
{
529+
return o.bits == bits && o.filterType == filterType && o.wrapType == wrapType
530+
&& o.minDimension == minDimension && o.maxDimension == maxDimension;
531+
}
526532
};
527533

528534
struct image_t
529535
{
530536
char name[ MAX_QPATH ];
531537

538+
imageParams_t initialParams; // may not match final values
539+
532540
GLenum type;
533541
GLuint texnum; // gl texture binding
534542
Texture *texture;

0 commit comments

Comments
 (0)