-
- if (!force && !gamma_forcenextframe && !gamma_changed)
- return;
-
- gamma_forcenextframe = false;
-
- if (cachehwgamma)
- {
- if (!vid_usinghwgamma)
- {
- vid_usinghwgamma = true;
- if (vid_gammarampsize != rampsize || !vid_gammaramps)
- {
- vid_gammarampsize = rampsize;
- if (vid_gammaramps)
- Z_Free(vid_gammaramps);
- vid_gammaramps = (unsigned short *)Z_Malloc(6 * vid_gammarampsize * sizeof(unsigned short));
- vid_systemgammaramps = vid_gammaramps + 3 * vid_gammarampsize;
- }
- VID_GetGamma(vid_systemgammaramps, vid_gammarampsize);
- }
-
- VID_BuildGammaTables(vid_gammaramps, vid_gammarampsize);
-
- // set vid_hardwaregammasupported to true if VID_SetGamma succeeds, OR if vid_hwgamma is >= 2 (forced gamma - ignores driver return value)
- Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_gammaramps, vid_gammarampsize) || cachehwgamma >= 2);
- // if custom gamma ramps failed (Windows stupidity), restore to system gamma
- if(!vid_hardwaregammasupported.integer)
- {
- if (vid_usinghwgamma)
- {
- vid_usinghwgamma = false;
- VID_SetGamma(vid_systemgammaramps, vid_gammarampsize);
- }
- }
- }
- else
- {
- if (vid_usinghwgamma)
- {
- vid_usinghwgamma = false;
- VID_SetGamma(vid_systemgammaramps, vid_gammarampsize);
- }
- }
-}
-
-void VID_RestoreSystemGamma(void)
-{
- if (vid_usinghwgamma)
- {
- vid_usinghwgamma = false;
- Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_systemgammaramps, vid_gammarampsize));
- // force gamma situation to be reexamined next frame
- gamma_forcenextframe = true;
- }