| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifdef USE_INTERNAL_SDL_HEADERS |
| 24 |
# include "SDL.h" |
| 25 |
#else |
| 26 |
# include <SDL.h> |
| 27 |
#endif |
| 28 |
|
| 29 |
#include "../renderercommon/tr_common.h" |
| 30 |
#include "../qcommon/qcommon.h" |
| 31 |
|
| 32 |
extern SDL_Window *SDL_window; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] ) |
| 40 |
{ |
| 41 |
Uint16 table[3][256]; |
| 42 |
int i, j; |
| 43 |
|
| 44 |
if( !glConfig.deviceSupportsGamma || r_ignorehwgamma->integer > 0 ) |
| 45 |
return; |
| 46 |
|
| 47 |
for (i = 0; i < 256; i++) |
| 48 |
{ |
| 49 |
table[0][i] = ( ( ( Uint16 ) red[i] ) << 8 ) | red[i]; |
| 50 |
table[1][i] = ( ( ( Uint16 ) green[i] ) << 8 ) | green[i]; |
| 51 |
table[2][i] = ( ( ( Uint16 ) blue[i] ) << 8 ) | blue[i]; |
| 52 |
} |
| 53 |
|
| 54 |
#ifdef _WIN32 |
| 55 |
|
| 56 |
ri.Printf( PRINT_DEVELOPER, "performing gamma clamp.\n" ); |
| 57 |
for( j = 0 ; j < 3 ; j++ ) |
| 58 |
{ |
| 59 |
for( i = 0 ; i < 128 ; i++ ) |
| 60 |
{ |
| 61 |
if( table[ j ][ i ] > ( ( 128 + i ) << 8 ) ) |
| 62 |
table[ j ][ i ] = ( 128 + i ) << 8; |
| 63 |
} |
| 64 |
|
| 65 |
if( table[ j ][ 127 ] > 254 << 8 ) |
| 66 |
table[ j ][ 127 ] = 254 << 8; |
| 67 |
} |
| 68 |
#endif |
| 69 |
|
| 70 |
|
| 71 |
for (j = 0; j < 3; j++) |
| 72 |
{ |
| 73 |
for (i = 1; i < 256; i++) |
| 74 |
{ |
| 75 |
if (table[j][i] < table[j][i-1]) |
| 76 |
table[j][i] = table[j][i-1]; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
if (SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]) < 0) |
| 81 |
{ |
| 82 |
ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowGammaRamp() failed: %s\n", SDL_GetError() ); |
| 83 |
} |
| 84 |
} |
| 85 |
|