Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

win_gamma.c File Reference

#include <assert.h>
#include "../renderer/tr_local.h"
#include "../qcommon/qcommon.h"
#include "glw_win.h"
#include "win_local.h"

Include dependency graph for win_gamma.c:

Include dependency graph

Go to the source code of this file.

Functions

void GLimp_SetGamma (unsigned char red[256], unsigned char green[256], unsigned char blue[256])
void WG_CheckHardwareGamma (void)
void WG_RestoreGamma (void)

Variables

unsigned short s_oldHardwareGamma [3][256]


Function Documentation

void GLimp_SetGamma unsigned char  red[256],
unsigned char  green[256],
unsigned char  blue[256]
 

Definition at line 133 of file win_gamma.c.

References blue, Com_DPrintf(), Com_Printf(), glconfig_t::deviceSupportsGamma, glwstate_t::display, glwgamma_t::display, err(), glConfig, glw_state, green, glwstate_t::hDC, i, glwstate_t::inGameTable, cvar_s::integer, j, r_ignorehwgamma, Sys_GetGammaTable(), and table.

Referenced by R_SetColorMappings().

00133                                                                                                  {
00134     unsigned short table[3][256];
00135     int     i, j;
00136     int     ret;
00137     OSVERSIONINFO   vinfo;
00138 
00139     if ( !glConfig.deviceSupportsGamma || r_ignorehwgamma->integer || !glw_state.hDC ) {
00140         return;
00141     }
00142 
00143 //mapGammaMax();
00144 
00145     for ( i = 0; i < 256; i++ ) {
00146         table[0][i] = ( ( ( unsigned short ) red[i] ) << 8 ) | red[i];
00147         table[1][i] = ( ( ( unsigned short ) green[i] ) << 8 ) | green[i];
00148         table[2][i] = ( ( ( unsigned short ) blue[i] ) << 8 ) | blue[i];
00149     }
00150 
00151     // Win2K puts this odd restriction on gamma ramps...
00152     vinfo.dwOSVersionInfoSize = sizeof(vinfo);
00153     GetVersionEx( &vinfo );
00154     if ( vinfo.dwMajorVersion == 5 && vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) {
00155         Com_DPrintf( "performing W2K gamma clamp.\n" );
00156         for ( j = 0 ; j < 3 ; j++ ) {
00157             for ( i = 0 ; i < 128 ; i++ ) {
00158                 if ( table[j][i] > ( (128+i) << 8 ) ) {
00159                     table[j][i] = (128+i) << 8;
00160                 }
00161             }
00162             if ( table[j][127] > 254<<8 ) {
00163                 table[j][127] = 254<<8;
00164             }
00165         }
00166     } else {
00167         Com_DPrintf( "skipping W2K gamma clamp.\n" );
00168     }
00169 
00170     // enforce constantly increasing
00171     for ( j = 0 ; j < 3 ; j++ ) {
00172         for ( i = 1 ; i < 256 ; i++ ) {
00173             if ( table[j][i] < table[j][i-1] ) {
00174                 table[j][i] = table[j][i-1];
00175             }
00176         }
00177     }
00178 
00179 
00180     if ( qwglSetDeviceGammaRamp3DFX )
00181     {
00182         qwglSetDeviceGammaRamp3DFX( glw_state.hDC, table );
00183     }
00184     else
00185     {
00186         ret = SetDeviceGammaRamp( glw_state.hDC, table );
00187         if ( !ret ) {
00188             Com_Printf( "SetDeviceGammaRamp failed.\n" );
00189         }
00190     }
00191 }

Here is the call graph for this function:

void WG_CheckHardwareGamma void   ) 
 

Definition at line 38 of file win_gamma.c.

References glconfig_t::deviceSupportsGamma, glconfig_t::driverType, g(), glConfig, HDC(), HIBYTE, cvar_s::integer, PRINT_WARNING, r_ignorehwgamma, ri, and s_oldHardwareGamma.

Referenced by GLimp_Init().

00039 {
00040     HDC         hDC;
00041 
00042     glConfig.deviceSupportsGamma = qfalse;
00043 
00044     if ( qwglSetDeviceGammaRamp3DFX )
00045     {
00046         glConfig.deviceSupportsGamma = qtrue;
00047 
00048         hDC = GetDC( GetDesktopWindow() );
00049         glConfig.deviceSupportsGamma = qwglGetDeviceGammaRamp3DFX( hDC, s_oldHardwareGamma );
00050         ReleaseDC( GetDesktopWindow(), hDC );
00051 
00052         return;
00053     }
00054 
00055     // non-3Dfx standalone drivers don't support gamma changes, period
00056     if ( glConfig.driverType == GLDRV_STANDALONE )
00057     {
00058         return;
00059     }
00060 
00061     if ( !r_ignorehwgamma->integer )
00062     {
00063         hDC = GetDC( GetDesktopWindow() );
00064         glConfig.deviceSupportsGamma = GetDeviceGammaRamp( hDC, s_oldHardwareGamma );
00065         ReleaseDC( GetDesktopWindow(), hDC );
00066 
00067         if ( glConfig.deviceSupportsGamma )
00068         {
00069             //
00070             // do a sanity check on the gamma values
00071             //
00072             if ( ( HIBYTE( s_oldHardwareGamma[0][255] ) <= HIBYTE( s_oldHardwareGamma[0][0] ) ) ||
00073                  ( HIBYTE( s_oldHardwareGamma[1][255] ) <= HIBYTE( s_oldHardwareGamma[1][0] ) ) ||
00074                  ( HIBYTE( s_oldHardwareGamma[2][255] ) <= HIBYTE( s_oldHardwareGamma[2][0] ) ) )
00075             {
00076                 glConfig.deviceSupportsGamma = qfalse;
00077                 ri.Printf( PRINT_WARNING, "WARNING: device has broken gamma support, generated gamma.dat\n" );
00078             }
00079 
00080             //
00081             // make sure that we didn't have a prior crash in the game, and if so we need to
00082             // restore the gamma values to at least a linear value
00083             //
00084             if ( ( HIBYTE( s_oldHardwareGamma[0][181] ) == 255 ) )
00085             {
00086                 int g;
00087 
00088                 ri.Printf( PRINT_WARNING, "WARNING: suspicious gamma tables, using linear ramp for restoration\n" );
00089 
00090                 for ( g = 0; g < 255; g++ )
00091                 {
00092                     s_oldHardwareGamma[0][g] = g << 8;
00093                     s_oldHardwareGamma[1][g] = g << 8;
00094                     s_oldHardwareGamma[2][g] = g << 8;
00095                 }
00096             }
00097         }
00098     }
00099 }

Here is the call graph for this function:

void WG_RestoreGamma void   ) 
 

Definition at line 196 of file win_gamma.c.

References glconfig_t::deviceSupportsGamma, glConfig, glw_state, glwstate_t::hDC, HDC(), and s_oldHardwareGamma.

Referenced by GLimp_Shutdown().

00197 {
00198     if ( glConfig.deviceSupportsGamma )
00199     {
00200         if ( qwglSetDeviceGammaRamp3DFX )
00201         {
00202             qwglSetDeviceGammaRamp3DFX( glw_state.hDC, s_oldHardwareGamma );
00203         }
00204         else
00205         {
00206             HDC hDC;
00207             
00208             hDC = GetDC( GetDesktopWindow() );
00209             SetDeviceGammaRamp( hDC, s_oldHardwareGamma );
00210             ReleaseDC( GetDesktopWindow(), hDC );
00211         }
00212     }
00213 }

Here is the call graph for this function:


Variable Documentation

unsigned short s_oldHardwareGamma[3][256] [static]
 

Definition at line 31 of file win_gamma.c.

Referenced by WG_CheckHardwareGamma(), and WG_RestoreGamma().


Generated on Thu Aug 25 15:40:06 2005 for Quake III Arena by  doxygen 1.3.9.1