SDL layer: don't call SDL_SetGammaRamp() if there would be no change.

This is in the similar vein as the set-palette deferring and it's this
that fixes the low FPS in the radioactively contaminated area in AMC TC:
Megabase (since setgamma() is called from setbrightness()).

Again, update issues might be expected, but changing focus between EDuke32
and the desktop and back seems to restore the gamma settings properly on
Kubuntu. Looks like X (or whatever above handles this stuff) maintains it
on a per-application basis.

git-svn-id: https://svn.eduke32.com/eduke32@2222 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-12-28 20:34:57 +00:00
parent 4ae50ef22a
commit 92e5d8214d
1 changed files with 21 additions and 2 deletions

View File

@ -11,7 +11,7 @@
#include "compat.h"
#include "sdlayer.h"
#include "cache1d.h"
#include "pragmas.h"
//#include "pragmas.h"
#include "a.h"
#include "build.h"
#include "osd.h"
@ -77,6 +77,9 @@ char nogl=0;
#endif
int32_t vsync=0;
// last gamma, contrast, brightness
static float lastvidgcb[3];
//#define KEY_PRINT_DEBUG
#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3)
@ -998,6 +1001,9 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
if (bpp > 8 && sdl_surface) polymost_glreset();
#endif
// clear last gamma/contrast/brightness so that it will be set anew
lastvidgcb[0] = lastvidgcb[1] = lastvidgcb[2] = 0.0f;
// restore gamma before we change video modes if it was changed
if (sdl_surface && gammabrightness)
{
@ -1524,6 +1530,9 @@ int32_t setgamma(void)
if (novideo) return 0;
if (lastvidgcb[0]==gamma && lastvidgcb[1]==contrast && lastvidgcb[2]==bright)
return 0;
// This formula is taken from Doomsday
for (i = 0; i < 256; i++)
@ -1534,7 +1543,17 @@ int32_t setgamma(void)
gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (uint16_t)max(0.f,(double)min(0xffff,val*256));
}
return SDL_SetGammaRamp(&gammaTable[0],&gammaTable[256],&gammaTable[512]);
i = SDL_SetGammaRamp(&gammaTable[0],&gammaTable[256],&gammaTable[512]);
if (i != -1)
{
lastvidgcb[0] = gamma;
lastvidgcb[1] = contrast;
lastvidgcb[2] = bright;
}
return i;
}
#ifndef __APPLE__