Skip to content
Permalink
Browse files

R_FindCubeImage: fix irregular skyboxes, fix DaemonEngine#142

  • Loading branch information...
illwieckz committed Mar 6, 2019
1 parent 7d06c05 commit 3058765d0c83976a9865f865fef1e0a322e7524b
Showing with 61 additions and 16 deletions.
  1. +61 −16 src/engine/renderer/tr_image.cpp
@@ -2040,9 +2040,15 @@ static const multifileCubeMapFormat_t multifileCubeMapFormats[] =

static int numMultifileCubeMapFormats = ARRAY_LEN( multifileCubeMapFormats );

struct face_t
{
int width;
int height;
};

image_t *R_FindCubeImage( const char *imageName, int bits, filterType_t filterType, wrapType_t wrapType )
{
int i, f;
int i, j, f;
image_t *image = nullptr;
int width = 0, height = 0, numLayers = 0, numMips = 0;
byte *pic[ MAX_TEXTURE_MIPS * MAX_TEXTURE_LAYERS ];
@@ -2095,6 +2101,9 @@ image_t *R_FindCubeImage( const char *imageName, int bits, filterType_t filterTy

for ( f = 0; f < numMultifileCubeMapFormats; f++ )
{
int greaterEdge = 0;
face_t faces[6];

for ( i = 0; i < 6; i++ )
{
Com_sprintf( filename, sizeof( filename ), "%s_%s", buffer, multifileCubeMapFormats[ f ].suffixes[ i ] );
@@ -2123,32 +2132,68 @@ image_t *R_FindCubeImage( const char *imageName, int bits, filterType_t filterTy
break;
}

if ( width != height )
if ( width > greaterEdge )
{
Log::Warn("cubemap face '%s' is not a square with %d×%d dimension", filename, width, height);
break;
}

if ( multifileCubeMapFormats[ f ].flipX[ i ] )
{
R_Flip( pic[ i ], width, height );
greaterEdge = width;
}

if ( multifileCubeMapFormats[ f ].flipY[ i ] )
if ( height > greaterEdge )
{
R_Flop( pic[ i ], width, height );
greaterEdge = height;
}

if ( multifileCubeMapFormats[ f ].rot[ i ] != 0 )
{
R_Rotate( pic[ i ], width, height, multifileCubeMapFormats[ f ].rot[ i ] );
}
faces[ i ].width = width;
faces[ i ].height = height;
}

if ( i == 6 )
{

for ( j = 0; j < 6; j++ )
{
width = faces[ j ].width;
height = faces[ j ].height;

bool badSize = false;

if ( width != height )
{
Log::Warn("cubemap face '%s_%s' is not a square with %d×%d dimension, resizing to %d×%d",
imageName, multifileCubeMapFormats[ f ].suffixes[ j ], width, height, greaterEdge, greaterEdge );
badSize = true;
}

if ( width < greaterEdge || height < greaterEdge )
{
Log::Warn("cubemap face '%s_%s' is too small with %d×%d dimension, resizing to %d×%d",
imageName, multifileCubeMapFormats[ f ].suffixes[ j ], width, height, greaterEdge, greaterEdge );
badSize = true;
}

// make face square before doing other operations like rotation
if ( badSize )
{
pic[ j ] = R_Resize( pic[ j ], width, height, greaterEdge, greaterEdge );
}

if ( multifileCubeMapFormats[ f ].flipX[ j ] )
{
R_Flip( pic[ j ], width, height );
}

if ( multifileCubeMapFormats[ f ].flipY[ j ] )
{
R_Flop( pic[ j ], width, height );
}

if ( multifileCubeMapFormats[ f ].rot[ j ] != 0 )
{
R_Rotate( pic[ j ], width, height, multifileCubeMapFormats[ f ].rot[ j ] );
}
}

Log::Debug( "found %s multifile cube map '%s'", multifileCubeMapFormats[ f ].name, imageName );
image = R_CreateCubeImage( ( char * ) buffer, ( const byte ** ) pic, width, height, bits, filterType, wrapType );
image = R_CreateCubeImage( ( char * ) buffer, ( const byte ** ) pic, greaterEdge, greaterEdge, bits, filterType, wrapType );
R_FreeCubePics( pic, i );
return image;
}

0 comments on commit 3058765

Please sign in to comment.
You can’t perform that action at this time.