Skip to content

Commit 239acc2

Browse files
committed
overall gamma-method code refactoring
1 parent e6a3945 commit 239acc2

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed

src/client/cl_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,7 @@ void QDECL CL_RefPrintf( int print_level, const char *fmt, ...) {
26142614
char msg[MAXPRINTMSG];
26152615

26162616
va_start (argptr,fmt);
2617-
vsprintf (msg,fmt,argptr);
2617+
vsnprintf (msg, sizeof(msg), fmt, argptr);
26182618
va_end (argptr);
26192619

26202620
if ( print_level == PRINT_ALL ) {
@@ -4132,7 +4132,7 @@ void CL_GetVMGLConfig(vmglconfig_t *vmglconfig) {
41324132
vmglconfig->depthBits = cls.glconfig.depthBits;
41334133
vmglconfig->stencilBits = cls.glconfig.stencilBits;
41344134

4135-
vmglconfig->deviceSupportsGamma = cls.glconfig.deviceSupportsGamma;
4135+
vmglconfig->deviceSupportsGamma = (qboolean)(cls.glconfig.deviceSupportsGamma || cls.glconfig.deviceSupportsPostprocessingGamma);
41364136
vmglconfig->textureCompression = cls.glconfig.textureCompression;
41374137
vmglconfig->textureEnvAddAvailable = cls.glconfig.textureEnvAddAvailable;
41384138
vmglconfig->textureFilterAnisotropicAvailable = cls.glconfig.textureFilterAnisotropicMax == 0.0f ? qfalse : qtrue;

src/renderer/tr_backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ const void *RB_SwapBuffers( const void *data ) {
12331233
}
12341234

12351235
// gamma correction
1236-
if (glConfig.deviceSupportsPostprocessingGamma && r_gammamethod->integer == GAMMA_POSTPROCESSING) {
1236+
if (r_gammamethod->integer == GAMMA_POSTPROCESSING) {
12371237
RB_SetGL2D();
12381238

12391239
qglEnable(GL_VERTEX_PROGRAM_ARB);

src/renderer/tr_image.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void R_LightScaleTexture (byte *in, int inwidth, int inheight, qboolean only_gam
311311
{
312312
if ( only_gamma )
313313
{
314-
if ( !glConfig.deviceSupportsGamma )
314+
if ( r_gammamethod->integer == GAMMA_NONE )
315315
{
316316
int i, c;
317317
byte *p;
@@ -336,7 +336,7 @@ void R_LightScaleTexture (byte *in, int inwidth, int inheight, qboolean only_gam
336336

337337
c = inwidth*inheight;
338338

339-
if ( glConfig.deviceSupportsGamma )
339+
if ( r_gammamethod->integer )
340340
{
341341
for (i=0 ; i<c ; i++, p+=4)
342342
{
@@ -2611,11 +2611,16 @@ void R_SetColorMappings( void ) {
26112611
// setup the overbright lighting
26122612
tr.overbrightBits = r_overBrightBits->integer;
26132613

2614-
if (!glConfig.isFullscreen && r_gammamethod->integer != GAMMA_POSTPROCESSING)
2614+
if (r_gammamethod->integer == GAMMA_NONE)
26152615
{
26162616
tr.overbrightBits = 0;
26172617
}
26182618

2619+
// never overbright in windowed mode
2620+
if (r_gammamethod->integer == GAMMA_HARDWARE && !glConfig.isFullscreen) {
2621+
tr.overbrightBits = 0;
2622+
}
2623+
26192624
if ( tr.overbrightBits > 1 ) {
26202625
tr.overbrightBits = 1;
26212626
}
@@ -2698,7 +2703,7 @@ void R_SetColorMappings( void ) {
26982703
}
26992704

27002705
// gamma correction
2701-
if (glConfig.deviceSupportsGamma && r_gammamethod->integer == GAMMA_HARDWARE) {
2706+
if (r_gammamethod->integer == GAMMA_HARDWARE) {
27022707
WIN_SetGamma( &glConfig, s_gammatable, s_gammatable, s_gammatable );
27032708
}
27042709
}
@@ -2710,7 +2715,7 @@ R_InitImages
27102715
*/
27112716
void R_InitImages( void ) {
27122717
// gamma render target
2713-
if (glConfig.deviceSupportsPostprocessingGamma && r_gammamethod->integer == GAMMA_POSTPROCESSING) {
2718+
if (r_gammamethod->integer == GAMMA_POSTPROCESSING) {
27142719
qglEnable(GL_TEXTURE_3D);
27152720
tr.gammaLUTImage = 1024 + giTextureBindNum++;
27162721
qglBindTexture(GL_TEXTURE_3D, tr.gammaLUTImage);

src/renderer/tr_init.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ static void InitOpenGL(void) {
638638
// initialize extensions
639639
GLimp_InitExtensions();
640640

641+
WIN_InitGammaMethod(&glConfig);
642+
641643
// set default state
642644
GL_SetDefaultState();
643645
} else {
@@ -1104,11 +1106,12 @@ void GfxInfo_f( void )
11041106
}
11051107

11061108
// gamma correction
1107-
if (glConfig.deviceSupportsPostprocessingGamma) {
1108-
ri.Printf(PRINT_ALL, "GAMMA_METHOD: postprocessing\n");
1109-
}
1110-
if (glConfig.deviceSupportsGamma) {
1111-
ri.Printf(PRINT_ALL, "GAMMA_METHOD: hardware\n");
1109+
if (r_gammamethod->integer == GAMMA_POSTPROCESSING) {
1110+
ri.Printf(PRINT_ALL, "gamma method: postprocessing\n");
1111+
} else if (r_gammamethod->integer == GAMMA_HARDWARE) {
1112+
ri.Printf(PRINT_ALL, "gamma method: hardware\n");
1113+
} else {
1114+
ri.Printf(PRINT_ALL, "gamma method: none\n");
11121115
}
11131116

11141117
// rendering primitives
@@ -1428,11 +1431,6 @@ void R_Init( void ) {
14281431
}
14291432
InitOpenGL();
14301433

1431-
// gamma correction
1432-
if (r_gammamethod->integer == GAMMA_POSTPROCESSING && !glConfig.deviceSupportsPostprocessingGamma) {
1433-
r_gammamethod->integer = GAMMA_HARDWARE; // temporary fallback to hardware gamma
1434-
}
1435-
14361434
R_InitImages();
14371435
R_InitShaders();
14381436
R_InitSkins();

src/renderer/tr_shader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4213,7 +4213,7 @@ static void CreateInternalShaders( void ) {
42134213

42144214
#ifndef DEDICATED
42154215
// gamma correction
4216-
if (glConfig.deviceSupportsPostprocessingGamma && r_gammamethod->integer == GAMMA_POSTPROCESSING) {
4216+
if (r_gammamethod->integer == GAMMA_POSTPROCESSING) {
42174217
if (MV_GammaGenerateProgram()) {
42184218
ri.Printf(PRINT_WARNING, "WARNING: failed initializing gamma program... falling back to hardware gamma correction\n");
42194219
glConfig.deviceSupportsPostprocessingGamma = qfalse;

src/sdl/sdl_window.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,6 @@ window_t WIN_Init( const windowDesc_t *windowDesc, glconfig_t *glConfig )
768768
}
769769
}
770770

771-
glConfig->deviceSupportsGamma =
772-
(qboolean)(r_gammamethod->integer == GAMMA_HARDWARE && SDL_SetWindowBrightness( screen, 1.0f ) >= 0);
773-
774771
// This depends on SDL_INIT_VIDEO, hence having it here
775772
IN_Init( screen );
776773

@@ -799,6 +796,21 @@ window_t WIN_Init( const windowDesc_t *windowDesc, glconfig_t *glConfig )
799796
return window;
800797
}
801798

799+
void WIN_InitGammaMethod(glconfig_t *glConfig) {
800+
if (r_gammamethod->integer == GAMMA_POSTPROCESSING && !glConfig->deviceSupportsPostprocessingGamma) {
801+
Com_Printf("postprocessing gamma correction not supported, falling back to hardware gamma...\n");
802+
r_gammamethod->integer = GAMMA_HARDWARE;
803+
}
804+
805+
if (r_gammamethod->integer == GAMMA_HARDWARE) {
806+
glConfig->deviceSupportsGamma = (qboolean)(SDL_SetWindowBrightness(screen, 1.0f) >= 0);
807+
if (!glConfig->deviceSupportsGamma) {
808+
Com_Printf("hardware gamma correction not supported, proceeding without gamma correction...\n");
809+
r_gammamethod->integer = GAMMA_NONE;
810+
}
811+
}
812+
}
813+
802814
/*
803815
===============
804816
GLimp_Shutdown
@@ -828,7 +840,7 @@ void WIN_SetGamma( glconfig_t *glConfig, byte red[256], byte green[256], byte bl
828840
Uint16 table[3][256];
829841
int i, j;
830842

831-
if( !glConfig->deviceSupportsGamma || r_gammamethod->integer != GAMMA_HARDWARE )
843+
if( r_gammamethod->integer != GAMMA_HARDWARE )
832844
return;
833845

834846
for (i = 0; i < 256; i++)

src/sys/sys_public.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ typedef struct windowDesc_s
170170
} windowDesc_t;
171171

172172
window_t WIN_Init( const windowDesc_t *desc, glconfig_t *glConfig );
173+
void WIN_InitGammaMethod(glconfig_t *glConfig);
173174
void WIN_Present( window_t *window );
174175
void WIN_SetGamma( glconfig_t *glConfig, byte red[256], byte green[256], byte blue[256] );
175176
void WIN_Shutdown( void );

0 commit comments

Comments
 (0)