Skip to content

Commit

Permalink
overall gamma-method code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ouned committed May 28, 2016
1 parent e6a3945 commit 239acc2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ void QDECL CL_RefPrintf( int print_level, const char *fmt, ...) {
char msg[MAXPRINTMSG];

va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
vsnprintf (msg, sizeof(msg), fmt, argptr);
va_end (argptr);

if ( print_level == PRINT_ALL ) {
Expand Down Expand Up @@ -4132,7 +4132,7 @@ void CL_GetVMGLConfig(vmglconfig_t *vmglconfig) {
vmglconfig->depthBits = cls.glconfig.depthBits;
vmglconfig->stencilBits = cls.glconfig.stencilBits;

vmglconfig->deviceSupportsGamma = cls.glconfig.deviceSupportsGamma;
vmglconfig->deviceSupportsGamma = (qboolean)(cls.glconfig.deviceSupportsGamma || cls.glconfig.deviceSupportsPostprocessingGamma);
vmglconfig->textureCompression = cls.glconfig.textureCompression;
vmglconfig->textureEnvAddAvailable = cls.glconfig.textureEnvAddAvailable;
vmglconfig->textureFilterAnisotropicAvailable = cls.glconfig.textureFilterAnisotropicMax == 0.0f ? qfalse : qtrue;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ const void *RB_SwapBuffers( const void *data ) {
}

// gamma correction
if (glConfig.deviceSupportsPostprocessingGamma && r_gammamethod->integer == GAMMA_POSTPROCESSING) {
if (r_gammamethod->integer == GAMMA_POSTPROCESSING) {
RB_SetGL2D();

qglEnable(GL_VERTEX_PROGRAM_ARB);
Expand Down
15 changes: 10 additions & 5 deletions src/renderer/tr_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void R_LightScaleTexture (byte *in, int inwidth, int inheight, qboolean only_gam
{
if ( only_gamma )
{
if ( !glConfig.deviceSupportsGamma )
if ( r_gammamethod->integer == GAMMA_NONE )
{
int i, c;
byte *p;
Expand All @@ -336,7 +336,7 @@ void R_LightScaleTexture (byte *in, int inwidth, int inheight, qboolean only_gam

c = inwidth*inheight;

if ( glConfig.deviceSupportsGamma )
if ( r_gammamethod->integer )
{
for (i=0 ; i<c ; i++, p+=4)
{
Expand Down Expand Up @@ -2611,11 +2611,16 @@ void R_SetColorMappings( void ) {
// setup the overbright lighting
tr.overbrightBits = r_overBrightBits->integer;

if (!glConfig.isFullscreen && r_gammamethod->integer != GAMMA_POSTPROCESSING)
if (r_gammamethod->integer == GAMMA_NONE)
{
tr.overbrightBits = 0;
}

// never overbright in windowed mode
if (r_gammamethod->integer == GAMMA_HARDWARE && !glConfig.isFullscreen) {
tr.overbrightBits = 0;
}

if ( tr.overbrightBits > 1 ) {
tr.overbrightBits = 1;
}
Expand Down Expand Up @@ -2698,7 +2703,7 @@ void R_SetColorMappings( void ) {
}

// gamma correction
if (glConfig.deviceSupportsGamma && r_gammamethod->integer == GAMMA_HARDWARE) {
if (r_gammamethod->integer == GAMMA_HARDWARE) {
WIN_SetGamma( &glConfig, s_gammatable, s_gammatable, s_gammatable );
}
}
Expand All @@ -2710,7 +2715,7 @@ R_InitImages
*/
void R_InitImages( void ) {
// gamma render target
if (glConfig.deviceSupportsPostprocessingGamma && r_gammamethod->integer == GAMMA_POSTPROCESSING) {
if (r_gammamethod->integer == GAMMA_POSTPROCESSING) {
qglEnable(GL_TEXTURE_3D);
tr.gammaLUTImage = 1024 + giTextureBindNum++;
qglBindTexture(GL_TEXTURE_3D, tr.gammaLUTImage);
Expand Down
18 changes: 8 additions & 10 deletions src/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ static void InitOpenGL(void) {
// initialize extensions
GLimp_InitExtensions();

WIN_InitGammaMethod(&glConfig);

// set default state
GL_SetDefaultState();
} else {
Expand Down Expand Up @@ -1104,11 +1106,12 @@ void GfxInfo_f( void )
}

// gamma correction
if (glConfig.deviceSupportsPostprocessingGamma) {
ri.Printf(PRINT_ALL, "GAMMA_METHOD: postprocessing\n");
}
if (glConfig.deviceSupportsGamma) {
ri.Printf(PRINT_ALL, "GAMMA_METHOD: hardware\n");
if (r_gammamethod->integer == GAMMA_POSTPROCESSING) {
ri.Printf(PRINT_ALL, "gamma method: postprocessing\n");
} else if (r_gammamethod->integer == GAMMA_HARDWARE) {
ri.Printf(PRINT_ALL, "gamma method: hardware\n");
} else {
ri.Printf(PRINT_ALL, "gamma method: none\n");
}

// rendering primitives
Expand Down Expand Up @@ -1428,11 +1431,6 @@ void R_Init( void ) {
}
InitOpenGL();

// gamma correction
if (r_gammamethod->integer == GAMMA_POSTPROCESSING && !glConfig.deviceSupportsPostprocessingGamma) {
r_gammamethod->integer = GAMMA_HARDWARE; // temporary fallback to hardware gamma
}

R_InitImages();
R_InitShaders();
R_InitSkins();
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4213,7 +4213,7 @@ static void CreateInternalShaders( void ) {

#ifndef DEDICATED
// gamma correction
if (glConfig.deviceSupportsPostprocessingGamma && r_gammamethod->integer == GAMMA_POSTPROCESSING) {
if (r_gammamethod->integer == GAMMA_POSTPROCESSING) {
if (MV_GammaGenerateProgram()) {
ri.Printf(PRINT_WARNING, "WARNING: failed initializing gamma program... falling back to hardware gamma correction\n");
glConfig.deviceSupportsPostprocessingGamma = qfalse;
Expand Down
20 changes: 16 additions & 4 deletions src/sdl/sdl_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,6 @@ window_t WIN_Init( const windowDesc_t *windowDesc, glconfig_t *glConfig )
}
}

glConfig->deviceSupportsGamma =
(qboolean)(r_gammamethod->integer == GAMMA_HARDWARE && SDL_SetWindowBrightness( screen, 1.0f ) >= 0);

// This depends on SDL_INIT_VIDEO, hence having it here
IN_Init( screen );

Expand Down Expand Up @@ -799,6 +796,21 @@ window_t WIN_Init( const windowDesc_t *windowDesc, glconfig_t *glConfig )
return window;
}

void WIN_InitGammaMethod(glconfig_t *glConfig) {
if (r_gammamethod->integer == GAMMA_POSTPROCESSING && !glConfig->deviceSupportsPostprocessingGamma) {
Com_Printf("postprocessing gamma correction not supported, falling back to hardware gamma...\n");
r_gammamethod->integer = GAMMA_HARDWARE;
}

if (r_gammamethod->integer == GAMMA_HARDWARE) {
glConfig->deviceSupportsGamma = (qboolean)(SDL_SetWindowBrightness(screen, 1.0f) >= 0);
if (!glConfig->deviceSupportsGamma) {
Com_Printf("hardware gamma correction not supported, proceeding without gamma correction...\n");
r_gammamethod->integer = GAMMA_NONE;
}
}
}

/*
===============
GLimp_Shutdown
Expand Down Expand Up @@ -828,7 +840,7 @@ void WIN_SetGamma( glconfig_t *glConfig, byte red[256], byte green[256], byte bl
Uint16 table[3][256];
int i, j;

if( !glConfig->deviceSupportsGamma || r_gammamethod->integer != GAMMA_HARDWARE )
if( r_gammamethod->integer != GAMMA_HARDWARE )
return;

for (i = 0; i < 256; i++)
Expand Down
1 change: 1 addition & 0 deletions src/sys/sys_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ typedef struct windowDesc_s
} windowDesc_t;

window_t WIN_Init( const windowDesc_t *desc, glconfig_t *glConfig );
void WIN_InitGammaMethod(glconfig_t *glConfig);
void WIN_Present( window_t *window );
void WIN_SetGamma( glconfig_t *glConfig, byte red[256], byte green[256], byte blue[256] );
void WIN_Shutdown( void );
Expand Down

0 comments on commit 239acc2

Please sign in to comment.