renderergl2: allow DDS fallback when r_ext_compressed_textures=0
R_LoadImage now tries .dds as a final fallback when compressed textures are disabled. This allows assets to ship as DDS-only without requiring duplicate PNG/TGA for every texture. Fixes #583.
This commit is contained in:
parent
453705553b
commit
4f9e3b96e0
|
|
@ -2410,7 +2410,9 @@ void R_LoadImage( const char *name, byte **pic, int *width, int *height, GLenum
|
|||
qboolean orgNameFailed = qfalse;
|
||||
int orgLoader = -1;
|
||||
int i;
|
||||
char base[ MAX_QPATH ];
|
||||
char localName[ MAX_QPATH ];
|
||||
char ddsName[ MAX_QPATH ];
|
||||
const char *ext;
|
||||
char *altName;
|
||||
|
||||
|
|
@ -2420,80 +2422,83 @@ void R_LoadImage( const char *name, byte **pic, int *width, int *height, GLenum
|
|||
*picFormat = GL_RGBA8;
|
||||
*numMips = 0;
|
||||
|
||||
Q_strncpyz( localName, name, MAX_QPATH );
|
||||
|
||||
Q_strncpyz(localName, name, sizeof(localName));
|
||||
ext = COM_GetExtension(localName);
|
||||
COM_StripExtension(name, base, sizeof(base));
|
||||
|
||||
// If compressed textures are enabled, try loading a DDS first, it'll load fastest
|
||||
if (r_ext_compressed_textures->integer)
|
||||
{
|
||||
char ddsName[MAX_QPATH];
|
||||
|
||||
COM_StripExtension(name, ddsName, MAX_QPATH);
|
||||
Q_strcat(ddsName, MAX_QPATH, ".dds");
|
||||
// Build DDS name
|
||||
Q_strncpyz(ddsName, base, sizeof(ddsName));
|
||||
Q_strcat(ddsName, sizeof(ddsName), ".dds");
|
||||
|
||||
if (r_ext_compressed_textures->integer) {
|
||||
// Try DDS first
|
||||
R_LoadDDS(ddsName, pic, width, height, picFormat, numMips);
|
||||
if (*pic) return;
|
||||
|
||||
// If loaded, we're done.
|
||||
if (*pic)
|
||||
return;
|
||||
}
|
||||
|
||||
if( *ext )
|
||||
{
|
||||
// Look for the correct loader and use it
|
||||
for( i = 0; i < numImageLoaders; i++ )
|
||||
{
|
||||
if( !Q_stricmp( ext, imageLoaders[ i ].ext ) )
|
||||
{
|
||||
// Load
|
||||
// Then try explicitly requested extension (if not DDS)
|
||||
if (ext && *ext && Q_stricmp(ext, "dds")) {
|
||||
for (i = 0; i < numImageLoaders; i++) {
|
||||
if (!Q_stricmp(ext, imageLoaders[i].ext)) {
|
||||
imageLoaders[i].ImageLoader(localName, pic, width, height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// A loader was found
|
||||
if( i < numImageLoaders )
|
||||
{
|
||||
if( *pic == NULL )
|
||||
{
|
||||
// Loader failed, most likely because the file isn't there;
|
||||
// try again without the extension
|
||||
if (*pic) return;
|
||||
orgNameFailed = qtrue;
|
||||
orgLoader = i;
|
||||
COM_StripExtension( name, localName, MAX_QPATH );
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Something loaded
|
||||
}
|
||||
COM_StripExtension(name, localName, sizeof(localName));
|
||||
}
|
||||
|
||||
// Then probe all supported formats except the failed one
|
||||
for (i = 0; i < numImageLoaders; i++) {
|
||||
if (i == orgLoader)
|
||||
continue;
|
||||
altName = va("%s.%s", localName, imageLoaders[i].ext);
|
||||
imageLoaders[i].ImageLoader(altName, pic, width, height);
|
||||
if (*pic) {
|
||||
if (orgNameFailed)
|
||||
ri.Printf(PRINT_DEVELOPER, "WARNING: %s not present, using %s instead\n", name, altName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Try and find a suitable match using all
|
||||
// the image formats supported
|
||||
for( i = 0; i < numImageLoaders; i++ )
|
||||
{
|
||||
if (i == orgLoader)
|
||||
continue;
|
||||
|
||||
altName = va( "%s.%s", localName, imageLoaders[ i ].ext );
|
||||
|
||||
// Load
|
||||
imageLoaders[ i ].ImageLoader( altName, pic, width, height );
|
||||
|
||||
if( *pic )
|
||||
{
|
||||
if( orgNameFailed )
|
||||
{
|
||||
ri.Printf( PRINT_DEVELOPER, "WARNING: %s not present, using %s instead\n",
|
||||
name, altName );
|
||||
}
|
||||
|
||||
// Explicit non-dds extension requested, so try its image loader
|
||||
if (ext && *ext && Q_stricmp(ext, "dds")) {
|
||||
for (i = 0; i < numImageLoaders; i++) {
|
||||
if (!Q_stricmp(ext, imageLoaders[i].ext)) {
|
||||
imageLoaders[i].ImageLoader(localName, pic, width, height);
|
||||
if (*pic) return;
|
||||
orgNameFailed = qtrue;
|
||||
orgLoader = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
COM_StripExtension(name, localName, sizeof(localName));
|
||||
}
|
||||
|
||||
// Try all other uncompressed formats
|
||||
for (i = 0; i < numImageLoaders; i++) {
|
||||
if (i == orgLoader)
|
||||
continue;
|
||||
if (!Q_stricmp(imageLoaders[i].ext, "dds"))
|
||||
continue;
|
||||
altName = va("%s.%s", localName, imageLoaders[i].ext);
|
||||
imageLoaders[i].ImageLoader(altName, pic, width, height);
|
||||
if (*pic) {
|
||||
if (orgNameFailed)
|
||||
ri.Printf(PRINT_DEVELOPER, "WARNING: %s not present, using %s instead\n", name, altName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, allow DDS fallback even when compressed textures are off
|
||||
if (!*pic) {
|
||||
R_LoadDDS(ddsName, pic, width, height, picFormat, numMips);
|
||||
if (*pic) ri.Printf(PRINT_DEVELOPER, "WARNING: falling back to compressed texture %s when r_ext_compressed_textures=0\n", ddsName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user