Skip to content

Commit b32be39

Browse files
committed
renderer: make possible to compress uncompressed textures
Add: - r_compressColormaps - r_compressSkyboxes
1 parent bcb66ee commit b32be39

4 files changed

Lines changed: 57 additions & 3 deletions

File tree

src/engine/renderer/tr_backend.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,10 @@ static GLint GL_ToSRGB( GLint internalFormat, bool isSRGB )
801801
return GL_SRGB8;
802802
case GL_RGBA8:
803803
return GL_SRGB8_ALPHA8;
804-
#if 0 // Not used in the codebase.
805804
case GL_COMPRESSED_RGB:
806805
return GL_COMPRESSED_SRGB;
807806
case GL_COMPRESSED_RGBA:
808807
return GL_COMPRESSED_SRGB_ALPHA;
809-
#endif
810808
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
811809
return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
812810
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:

src/engine/renderer/tr_image.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class ListImagesCmd : public Cmd::StaticCmd
197197
If internalformat is one of the six generic compressed internal formats, its value is replaced by the symbolic constant
198198
for a specific compressed internal format of the GL’s choosing with the same base internal format."
199199
Use 4x4 blocks with 8 bytes per block here as an estimate: */
200+
{ GL_COMPRESSED_RGB, { "RGBC", 8 } },
200201
{ GL_COMPRESSED_RGBA, { "RGBAC", 8 } },
201202

202203
/* https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
@@ -378,6 +379,7 @@ class ListImagesCmd : public Cmd::StaticCmd
378379
{
379380
switch ( image->internalFormat ) {
380381
// Compressed formats encode blocks of 4x4 texels
382+
case GL_COMPRESSED_RGB:
381383
case GL_COMPRESSED_RGBA:
382384
case GL_COMPRESSED_RED_RGTC1:
383385
case GL_COMPRESSED_SIGNED_RED_RGTC1:
@@ -1203,6 +1205,22 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
12031205
Log::Warn( "An explicit format should be used instead of GL_RGBA for image %s", name );
12041206
}
12051207

1208+
if ( image->bits & IF_COMPRESS )
1209+
{
1210+
switch ( internalFormat )
1211+
{
1212+
case GL_RED:
1213+
case GL_RGB8:
1214+
internalFormat = GL_COMPRESSED_RGB;
1215+
break;
1216+
case GL_RGBA8:
1217+
internalFormat = GL_COMPRESSED_RGBA;
1218+
break;
1219+
default:
1220+
break;
1221+
}
1222+
}
1223+
12061224
Log::Debug( "Uploading image %s (%d×%d, %d layers, %0#x type, %0#x format)", name, scaledWidth, scaledHeight, numLayers, image->type, internalFormat );
12071225

12081226
// 3D textures are uploaded in slices via glTexSubImage3D,

src/engine/renderer/tr_local.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ enum class ssaoMode {
510510
IF_BC5 = BIT( 23 ),
511511
IF_RGBA32UI = BIT( 24 ),
512512
IF_HOMEPATH = BIT( 25 ),
513-
IF_NOALPHA = BIT( 26 )
513+
IF_NOALPHA = BIT( 26 ),
514+
IF_COMPRESS = BIT(27)
514515
};
515516

516517
enum class filterType_t

src/engine/renderer/tr_shader.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ static Cvar::Cvar<float> r_portalDefaultRange(
8787
Cvar::Cvar<bool> r_depthShaders(
8888
"r_depthShaders", "use depth pre-pass shaders", Cvar::CHEAT, true);
8989

90+
Cvar::Cvar<bool> r_compressColormaps(
91+
"r_compressColormaps", "compress uncompressed color maps", Cvar::NONE, false);
92+
Cvar::Cvar<bool> r_compressSkyboxes(
93+
"r_compressSkyboxes", "compress uncompressed skyboxes", Cvar::NONE, false);
94+
9095
struct delayedStageTexture_t {
9196
bool active;
9297
stageType_t type;
@@ -1518,6 +1523,25 @@ static bool LoadMap( shaderStage_t *stage, const char *buffer, stageType_t type,
15181523
}
15191524
}
15201525

1526+
if ( r_compressColormaps.Get() )
1527+
{
1528+
if ( ! ( shader.registerFlags & RSF_2D ) )
1529+
{
1530+
switch ( type )
1531+
{
1532+
case stageType_t::ST_COLORMAP:
1533+
case stageType_t::ST_DIFFUSEMAP:
1534+
case stageType_t::ST_GLOWMAP:
1535+
case stageType_t::ST_REFLECTIONMAP:
1536+
case stageType_t::ST_SKYBOXMAP:
1537+
imageParams.bits |= IF_COMPRESS;
1538+
break;
1539+
default:
1540+
break;
1541+
}
1542+
}
1543+
}
1544+
15211545
// determine image options
15221546
if ( stage->overrideNoPicMip || shader.noPicMip || stage->highQuality || stage->forceHighQuality )
15231547
{
@@ -3719,6 +3743,11 @@ static void ParseSkyParms( const char **text )
37193743
imageParams.bits |= IF_SRGB;
37203744
}
37213745

3746+
if ( r_compressSkyboxes.Get() )
3747+
{
3748+
imageParams.bits |= IF_COMPRESS;
3749+
}
3750+
37223751
shader.sky.outerbox = R_FindCubeImage( prefix, imageParams );
37233752

37243753
if ( !shader.sky.outerbox )
@@ -6410,6 +6439,12 @@ shader_t *R_FindShader( const char *name, int flags )
64106439
imageParams.bits |= IF_SRGB;
64116440
}
64126441

6442+
// HACK: Detect color grade images with RSF_NOMIP.
6443+
if ( r_compressColormaps.Get() && ! ( flags & RSF_NOMIP ) )
6444+
{
6445+
imageParams.bits |= IF_COMPRESS;
6446+
}
6447+
64136448
image = R_FindImageFile( fileName, imageParams );
64146449
}
64156450

@@ -7034,6 +7069,8 @@ void R_InitShaders()
70347069
Cvar::Latch(r_dpMaterial);
70357070
Cvar::Latch(r_depthShaders);
70367071
Cvar::Latch(r_portalDefaultRange);
7072+
Cvar::Latch(r_compressColormaps);
7073+
Cvar::Latch(r_compressSkyboxes);
70377074

70387075
memset( shaderTableHashTable, 0, sizeof( shaderTableHashTable ) );
70397076
memset( shaderHashTable, 0, sizeof( shaderHashTable ) );

0 commit comments

Comments
 (0)