Mercurial > sdl-ios-xcode
changeset 338:518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 11 Apr 2002 15:23:07 +0000 |
parents | 9154ec9ca3d2 |
children | eed579d059ef |
files | src/video/wincommon/SDL_lowvideo.h src/video/wincommon/SDL_sysevents.c src/video/windib/SDL_dibvideo.c src/video/windib/SDL_dibvideo.h src/video/windx5/SDL_dx5video.c |
diffstat | 5 files changed, 59 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/wincommon/SDL_lowvideo.h Thu Apr 11 14:35:16 2002 +0000 +++ b/src/video/wincommon/SDL_lowvideo.h Thu Apr 11 15:23:07 2002 +0000 @@ -67,9 +67,6 @@ /* Called by windows message loop when the system palette changes */ extern void (*WIN_PaletteChanged)(_THIS, HWND window); -/* Called by windows message loop when losing or gaining gamma focus */ -extern void (*WIN_SwapGamma)(_THIS); - /* Called by windows message loop when a portion of the screen needs update */ extern void (*WIN_WinPAINT)(_THIS, HDC hdc); @@ -93,6 +90,9 @@ extern DEVMODE SDL_fullscreen_mode; #endif +/* The system gamma ramp for GDI modes */ +extern WORD *gamma_saved; + /* This is really from SDL_dx5audio.c */ extern void DX5_SoundFocus(HWND window);
--- a/src/video/wincommon/SDL_sysevents.c Thu Apr 11 14:35:16 2002 +0000 +++ b/src/video/wincommon/SDL_sysevents.c Thu Apr 11 15:23:07 2002 +0000 @@ -60,6 +60,7 @@ #ifndef NO_CHANGEDISPLAYSETTINGS DEVMODE SDL_fullscreen_mode; #endif +WORD *gamma_saved = NULL; /* Functions called by the message processing function */ @@ -67,8 +68,8 @@ (*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL; void (*WIN_RealizePalette)(_THIS); void (*WIN_PaletteChanged)(_THIS, HWND window); -void (*WIN_SwapGamma)(_THIS); void (*WIN_WinPAINT)(_THIS, HDC hdc); +extern void DIB_SwapGamma(_THIS); static void SDL_RestoreGameMode(void) { @@ -198,7 +199,9 @@ WIN_GrabInput(this, SDL_GRAB_ON); } if ( !(SDL_GetAppState()&SDL_APPINPUTFOCUS) ) { - WIN_SwapGamma(this); + if ( ! DDRAW_FULLSCREEN() ) { + DIB_SwapGamma(this); + } if ( WINDIB_FULLSCREEN() ) { SDL_RestoreGameMode(); } @@ -215,7 +218,9 @@ WIN_GrabInput(this, SDL_GRAB_OFF); } if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { - WIN_SwapGamma(this); + if ( ! DDRAW_FULLSCREEN() ) { + DIB_SwapGamma(this); + } if ( WINDIB_FULLSCREEN() ) { SDL_RestoreDesktopMode(); }
--- a/src/video/windib/SDL_dibvideo.c Thu Apr 11 14:35:16 2002 +0000 +++ b/src/video/windib/SDL_dibvideo.c Thu Apr 11 15:23:07 2002 +0000 @@ -61,12 +61,10 @@ static int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); static void DIB_CheckGamma(_THIS); -static void DIB_SwapGamma(_THIS); -static void DIB_QuitGamma(_THIS); -#ifndef NO_GAMMA_SUPPORT -static int DIB_SetGammaRamp(_THIS, Uint16 *ramp); -static int DIB_GetGammaRamp(_THIS, Uint16 *ramp); -#endif +void DIB_SwapGamma(_THIS); +void DIB_QuitGamma(_THIS); +int DIB_SetGammaRamp(_THIS, Uint16 *ramp); +int DIB_GetGammaRamp(_THIS, Uint16 *ramp); static void DIB_VideoQuit(_THIS); /* Hardware surface functions */ @@ -142,10 +140,8 @@ device->UnlockHWSurface = DIB_UnlockHWSurface; device->FlipHWSurface = NULL; device->FreeHWSurface = DIB_FreeHWSurface; -#ifndef NO_GAMMA_SUPPORT device->SetGammaRamp = DIB_SetGammaRamp; device->GetGammaRamp = DIB_GetGammaRamp; -#endif #ifdef HAVE_OPENGL device->GL_LoadLibrary = WIN_GL_LoadLibrary; device->GL_GetProcAddress = WIN_GL_GetProcAddress; @@ -169,7 +165,6 @@ /* Set up the windows message handling functions */ WIN_RealizePalette = DIB_RealizePalette; WIN_PaletteChanged = DIB_PaletteChanged; - WIN_SwapGamma = DIB_SwapGamma; WIN_WinPAINT = DIB_WinPAINT; HandleMessage = DIB_HandleMessage; @@ -807,7 +802,7 @@ ReleaseDC(SDL_Window, hdc); #endif /* !NO_GAMMA_SUPPORT */ } -static void DIB_SwapGamma(_THIS) +void DIB_SwapGamma(_THIS) { #ifndef NO_GAMMA_SUPPORT HDC hdc; @@ -826,7 +821,7 @@ } #endif /* !NO_GAMMA_SUPPORT */ } -static void DIB_QuitGamma(_THIS) +void DIB_QuitGamma(_THIS) { #ifndef NO_GAMMA_SUPPORT if ( gamma_saved ) { @@ -846,10 +841,12 @@ #endif /* !NO_GAMMA_SUPPORT */ } -#ifndef NO_GAMMA_SUPPORT - -static int DIB_SetGammaRamp(_THIS, Uint16 *ramp) +int DIB_SetGammaRamp(_THIS, Uint16 *ramp) { +#ifdef NO_GAMMA_SUPPORT + SDL_SetError("SDL compiled without gamma ramp support"); + return -1; +#else HDC hdc; BOOL succeeded; @@ -872,10 +869,15 @@ succeeded = TRUE; } return succeeded ? 0 : -1; +#endif /* !NO_GAMMA_SUPPORT */ } -static int DIB_GetGammaRamp(_THIS, Uint16 *ramp) +int DIB_GetGammaRamp(_THIS, Uint16 *ramp) { +#ifdef NO_GAMMA_SUPPORT + SDL_SetError("SDL compiled without gamma ramp support"); + return -1; +#else HDC hdc; BOOL succeeded; @@ -884,10 +886,9 @@ succeeded = GetDeviceGammaRamp(hdc, ramp); ReleaseDC(SDL_Window, hdc); return succeeded ? 0 : -1; +#endif /* !NO_GAMMA_SUPPORT */ } -#endif /* !NO_GAMMA_SUPPORT */ - void DIB_VideoQuit(_THIS) { /* Destroy the window and everything associated with it */
--- a/src/video/windib/SDL_dibvideo.h Thu Apr 11 14:35:16 2002 +0000 +++ b/src/video/windib/SDL_dibvideo.h Thu Apr 11 15:23:07 2002 +0000 @@ -38,14 +38,11 @@ #define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */ int SDL_nummodes[NUM_MODELISTS]; SDL_Rect **SDL_modelist[NUM_MODELISTS]; - - WORD *gamma_saved; }; /* Old variable names */ #define screen_bmp (this->hidden->screen_bmp) #define screen_pal (this->hidden->screen_pal) #define SDL_nummodes (this->hidden->SDL_nummodes) #define SDL_modelist (this->hidden->SDL_modelist) -#define gamma_saved (this->hidden->gamma_saved) #endif /* _SDL_dibvideo_h */
--- a/src/video/windx5/SDL_dx5video.c Thu Apr 11 14:35:16 2002 +0000 +++ b/src/video/windx5/SDL_dx5video.c Thu Apr 11 15:23:07 2002 +0000 @@ -404,11 +404,8 @@ static SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); static int DX5_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); -static void DX5_SwapGamma(_THIS); -#ifdef IDirectDrawGammaControl_SetGammaRamp static int DX5_SetGammaRamp(_THIS, Uint16 *ramp); static int DX5_GetGammaRamp(_THIS, Uint16 *ramp); -#endif static void DX5_VideoQuit(_THIS); /* Hardware surface functions */ @@ -430,6 +427,11 @@ static void DX5_PaletteChanged(_THIS, HWND window); static void DX5_WinPAINT(_THIS, HDC hdc); +/* WinDIB driver functions for manipulating gamma ramps */ +extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp); +extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp); +extern void DIB_QuitGamma(_THIS); + /* DX5 driver bootstrap functions */ static int DX5_Available(void) @@ -591,10 +593,8 @@ device->UnlockHWSurface = DX5_UnlockHWSurface; device->FlipHWSurface = DX5_FlipHWSurface; device->FreeHWSurface = DX5_FreeHWSurface; -#ifdef IDirectDrawGammaControl_SetGammaRamp device->SetGammaRamp = DX5_SetGammaRamp; device->GetGammaRamp = DX5_GetGammaRamp; -#endif #ifdef HAVE_OPENGL device->GL_LoadLibrary = WIN_GL_LoadLibrary; device->GL_GetProcAddress = WIN_GL_GetProcAddress; @@ -618,7 +618,6 @@ /* Set up the windows message handling functions */ WIN_RealizePalette = DX5_RealizePalette; WIN_PaletteChanged = DX5_PaletteChanged; - WIN_SwapGamma = DX5_SwapGamma; WIN_WinPAINT = DX5_WinPAINT; HandleMessage = DX5_HandleMessage; @@ -2112,20 +2111,24 @@ return(alloct_all); } -static void DX5_SwapGamma(_THIS) -{ - return; -} - /* Gamma code is only available on DirectX 7 and newer */ -#ifdef IDirectDrawGammaControl_SetGammaRamp - static int DX5_SetGammaRamp(_THIS, Uint16 *ramp) { +#ifdef IDirectDrawGammaControl_SetGammaRamp LPDIRECTDRAWGAMMACONTROL gamma; DDGAMMARAMP gamma_ramp; HRESULT result; +#endif + /* In windowed or OpenGL mode, use windib gamma code */ + if ( ! DDRAW_FULLSCREEN() ) { + return DIB_SetGammaRamp(this, ramp); + } + +#ifndef IDirectDrawGammaControl_SetGammaRamp + SDL_SetError("SDL compiled without DirectX gamma ramp support"); + return -1; +#else /* Check for a video mode! */ if ( ! SDL_primary ) { SDL_SetError("A video mode must be set for gamma correction"); @@ -2152,14 +2155,26 @@ /* Release the interface and return */ IDirectDrawGammaControl_Release(gamma); return (result == DD_OK) ? 0 : -1; +#endif /* !IDirectDrawGammaControl_SetGammaRamp */ } static int DX5_GetGammaRamp(_THIS, Uint16 *ramp) { +#ifdef IDirectDrawGammaControl_SetGammaRamp LPDIRECTDRAWGAMMACONTROL gamma; DDGAMMARAMP gamma_ramp; HRESULT result; +#endif + /* In windowed or OpenGL mode, use windib gamma code */ + if ( ! DDRAW_FULLSCREEN() ) { + return DIB_GetGammaRamp(this, ramp); + } + +#ifndef IDirectDrawGammaControl_SetGammaRamp + SDL_SetError("SDL compiled without DirectX gamma ramp support"); + return -1; +#else /* Check for a video mode! */ if ( ! SDL_primary ) { SDL_SetError("A video mode must be set for gamma correction"); @@ -2187,10 +2202,9 @@ /* Release the interface and return */ IDirectDrawGammaControl_Release(gamma); return (result == DD_OK) ? 0 : -1; +#endif /* !IDirectDrawGammaControl_SetGammaRamp */ } -#endif /* IDirectDrawGammaControl_SetGammaRamp */ - void DX5_VideoQuit(_THIS) { int i, j; @@ -2228,6 +2242,7 @@ } /* Free the window */ + DIB_QuitGamma(this); if ( SDL_Window ) { DX5_DestroyWindow(this); }