Support r_srgb even without hardware support. Also tweak default autoexposure/tonemap settings to look good on both r_srgb 0 and 1.

This commit is contained in:
James Canete 2012-12-18 06:15:38 +00:00
parent 26b1fcc471
commit 78b4a3bb7a
5 changed files with 38 additions and 31 deletions

View file

@ -1747,7 +1747,7 @@ const void *RB_PostProcess(const void *data)
autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer; autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer;
RB_ToneMap(srcFbo, autoExposure); RB_ToneMap(srcFbo, autoExposure);
} }
else if (!glRefConfig.framebuffer_srgb && r_cameraExposure->value == 0.0f) else if (r_cameraExposure->value == 0.0f)
{ {
FBO_FastBlit(srcFbo, NULL, tr.screenScratchFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST); FBO_FastBlit(srcFbo, NULL, tr.screenScratchFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }

View file

@ -608,21 +608,6 @@ void GLimp_InitExtraExtensions()
ri.Printf(PRINT_ALL, result[2], extension); ri.Printf(PRINT_ALL, result[2], extension);
} }
// GL_EXT_framebuffer_sRGB
extension = "GL_EXT_framebuffer_sRGB";
glRefConfig.framebuffer_srgb = qfalse;
if (GLimp_HaveExtension(extension))
{
if (r_srgb->integer)
glRefConfig.framebuffer_srgb = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.framebuffer_srgb], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
glRefConfig.textureCompression = TCR_NONE; glRefConfig.textureCompression = TCR_NONE;
// GL_EXT_texture_compression_latc // GL_EXT_texture_compression_latc

View file

@ -2152,6 +2152,26 @@ static void Upload32( byte *data, int width, int height, imgType_t type, imgFlag
} }
} }
// Convert to RGB if sRGB textures aren't supported in hardware
if (!glRefConfig.texture_srgb && (flags & IMGFLAG_SRGB))
{
byte *in = data;
int c = width * height;
while (c--)
{
for (i = 0; i < 3; i++)
{
float x = ByteToFloat(in[i]);
x = sRGBtoRGB(x);
in[i] = FloatToByte(x);
}
in += 4;
}
// FIXME: Probably should mark the image as non-sRGB as well
flags &= ~IMGFLAG_SRGB;
}
// normals are always swizzled // normals are always swizzled
if (type == IMGTYPE_NORMAL || type == IMGTYPE_NORMALHEIGHT) if (type == IMGTYPE_NORMAL || type == IMGTYPE_NORMALHEIGHT)
{ {
@ -2947,9 +2967,6 @@ void R_CreateBuiltinImages( void ) {
{ {
int format; int format;
if (glRefConfig.texture_srgb && glRefConfig.framebuffer_srgb)
format = GL_SRGB8_ALPHA8_EXT;
else
format = GL_RGBA8; format = GL_RGBA8;
tr.screenScratchImage = R_CreateImage("*screenScratch", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, format); tr.screenScratchImage = R_CreateImage("*screenScratch", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, format);
@ -3085,10 +3102,21 @@ void R_SetColorMappings( void ) {
} }
for ( i = 0; i < 256; i++ ) { for ( i = 0; i < 256; i++ ) {
int i2;
if (r_srgb->integer)
{
i2 = 255 * RGBtosRGB(i/255.0f) + 0.5f;
}
else
{
i2 = i;
}
if ( g == 1 ) { if ( g == 1 ) {
inf = i; inf = i2;
} else { } else {
inf = 255 * pow ( i/255.0f, 1.0f / g ) + 0.5f; inf = 255 * pow ( i2/255.0f, 1.0f / g ) + 0.5f;
} }
inf <<= shift; inf <<= shift;
if (inf < 0) { if (inf < 0) {

View file

@ -934,11 +934,6 @@ void GL_SetDefaultState( void )
glState.currentVBO = NULL; glState.currentVBO = NULL;
glState.currentIBO = NULL; glState.currentIBO = NULL;
if (glRefConfig.framebuffer_srgb)
{
qglEnable(GL_FRAMEBUFFER_SRGB_EXT);
}
qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
qglDepthMask( GL_TRUE ); qglDepthMask( GL_TRUE );
qglDisable( GL_DEPTH_TEST ); qglDisable( GL_DEPTH_TEST );
@ -1159,9 +1154,9 @@ void R_Register( void )
r_toneMap = ri.Cvar_Get( "r_toneMap", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_toneMap = ri.Cvar_Get( "r_toneMap", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_forceToneMap = ri.Cvar_Get( "r_forceToneMap", "0", CVAR_CHEAT ); r_forceToneMap = ri.Cvar_Get( "r_forceToneMap", "0", CVAR_CHEAT );
r_forceToneMapMin = ri.Cvar_Get( "r_forceToneMapMin", "-3.25", CVAR_CHEAT ); r_forceToneMapMin = ri.Cvar_Get( "r_forceToneMapMin", "-8.0", CVAR_CHEAT );
r_forceToneMapAvg = ri.Cvar_Get( "r_forceToneMapAvg", "-1.0", CVAR_CHEAT ); r_forceToneMapAvg = ri.Cvar_Get( "r_forceToneMapAvg", "-2.0", CVAR_CHEAT );
r_forceToneMapMax = ri.Cvar_Get( "r_forceToneMapMax", "1.0", CVAR_CHEAT ); r_forceToneMapMax = ri.Cvar_Get( "r_forceToneMapMax", "0.0", CVAR_CHEAT );
r_autoExposure = ri.Cvar_Get( "r_autoExposure", "1", CVAR_ARCHIVE ); r_autoExposure = ri.Cvar_Get( "r_autoExposure", "1", CVAR_ARCHIVE );
r_forceAutoExposure = ri.Cvar_Get( "r_forceAutoExposure", "0", CVAR_CHEAT ); r_forceAutoExposure = ri.Cvar_Get( "r_forceAutoExposure", "0", CVAR_CHEAT );

View file

@ -1711,7 +1711,6 @@ typedef struct {
qboolean framebufferBlit; qboolean framebufferBlit;
qboolean texture_srgb; qboolean texture_srgb;
qboolean framebuffer_srgb;
qboolean depthClamp; qboolean depthClamp;
} glRefConfig_t; } glRefConfig_t;