Mercurial > sdl-ios-xcode
comparison src/video/windx5/SDL_dx5video.c @ 1295:c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
From: Per Inge Mathisen
Subject: [SDL] Fullscreen refresh on win32
Windows has a terrible default for fullscreen 3D apps of 60mhz refresh
rate. This can be fixed by the user by going into his driver's
control panel and forcing the refresh rate higher. However, this not a
very user friendly way about it, and in any case SDL contains no code
that could figure out this that condition has afflicted the user.
So the question is, could SDL fix this for the user? It is possible
under Windows to request a higher refresh rate. The danger is of
course that if the user has an old monitor, and you request a too high
refresh rate, the monitor could be damaged. However, I believe there
might be a way around that: Check before switching what refresh rate
the user's desktop runs in, and if our fullscreen dimensions are equal
or less than those of the desktop, use the higher refresh rate of 60
and the desktop rate.
Since most users run their desktops in the same or higher resolution
something sane, this should fix this problem for most users.
Thoughts?
An alternative is to add an SDL_GL_GetAttribute(SDL_GL_REFRESH_RATE)
option so that programs can bitch at their users at their own
convenience.
- Per
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 30 Jan 2006 06:56:10 +0000 |
parents | 31331c444ea2 |
children | c9b51268668f |
comparison
equal
deleted
inserted
replaced
1294:1760ceb23bc6 | 1295:c3e36ac8a94c |
---|---|
654 int refreshRate = desc->u2.dwRefreshRate; | 654 int refreshRate = desc->u2.dwRefreshRate; |
655 #else | 655 #else |
656 int bpp = desc->ddpfPixelFormat.dwRGBBitCount; | 656 int bpp = desc->ddpfPixelFormat.dwRGBBitCount; |
657 int refreshRate = desc->dwRefreshRate; | 657 int refreshRate = desc->dwRefreshRate; |
658 #endif | 658 #endif |
659 int maxRefreshRate; | |
660 | |
661 if ( desc->dwWidth <= SDL_desktop_mode.dmPelsWidth && | |
662 desc->dwHeight <= SDL_desktop_mode.dmPelsHeight ) { | |
663 maxRefreshRate = SDL_desktop_mode.dmDisplayFrequency; | |
664 } else { | |
665 maxRefreshRate = 85; /* safe value? */ | |
666 } | |
659 | 667 |
660 switch (bpp) { | 668 switch (bpp) { |
661 case 8: | 669 case 8: |
662 case 16: | 670 case 16: |
663 case 24: | 671 case 24: |
665 bpp /= 8; --bpp; | 673 bpp /= 8; --bpp; |
666 if ( enumlists[bpp] && | 674 if ( enumlists[bpp] && |
667 enumlists[bpp]->r.w == (Uint16)desc->dwWidth && | 675 enumlists[bpp]->r.w == (Uint16)desc->dwWidth && |
668 enumlists[bpp]->r.h == (Uint16)desc->dwHeight ) { | 676 enumlists[bpp]->r.h == (Uint16)desc->dwHeight ) { |
669 if ( refreshRate > enumlists[bpp]->refreshRate && | 677 if ( refreshRate > enumlists[bpp]->refreshRate && |
670 refreshRate <= 85 /* safe value? */ ) { | 678 refreshRate <= maxRefreshRate ) { |
671 enumlists[bpp]->refreshRate = refreshRate; | 679 enumlists[bpp]->refreshRate = refreshRate; |
672 #ifdef DDRAW_DEBUG | 680 #ifdef DDRAW_DEBUG |
673 fprintf(stderr, "New refresh rate for %d bpp: %dx%d at %d Hz\n", (bpp+1)*8, (int)desc->dwWidth, (int)desc->dwHeight, refreshRate); | 681 fprintf(stderr, "New refresh rate for %d bpp: %dx%d at %d Hz\n", (bpp+1)*8, (int)desc->dwWidth, (int)desc->dwHeight, refreshRate); |
674 #endif | 682 #endif |
675 } | 683 } |
923 /* Determine the screen depth */ | 931 /* Determine the screen depth */ |
924 hdc = GetDC(SDL_Window); | 932 hdc = GetDC(SDL_Window); |
925 vformat->BitsPerPixel = GetDeviceCaps(hdc,PLANES) * | 933 vformat->BitsPerPixel = GetDeviceCaps(hdc,PLANES) * |
926 GetDeviceCaps(hdc,BITSPIXEL); | 934 GetDeviceCaps(hdc,BITSPIXEL); |
927 ReleaseDC(SDL_Window, hdc); | 935 ReleaseDC(SDL_Window, hdc); |
936 | |
937 #ifndef NO_CHANGEDISPLAYSETTINGS | |
938 /* Query for the desktop resolution */ | |
939 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode); | |
940 #endif | |
928 | 941 |
929 /* Enumerate the available fullscreen modes */ | 942 /* Enumerate the available fullscreen modes */ |
930 for ( i=0; i<NUM_MODELISTS; ++i ) | 943 for ( i=0; i<NUM_MODELISTS; ++i ) |
931 enumlists[i] = NULL; | 944 enumlists[i] = NULL; |
932 | 945 |
1091 change to the desired resolution here. | 1104 change to the desired resolution here. |
1092 FIXME: Should we do a closest match? | 1105 FIXME: Should we do a closest match? |
1093 */ | 1106 */ |
1094 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | 1107 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { |
1095 DEVMODE settings; | 1108 DEVMODE settings; |
1109 BOOL changed; | |
1096 | 1110 |
1097 memset(&settings, 0, sizeof(DEVMODE)); | 1111 memset(&settings, 0, sizeof(DEVMODE)); |
1098 settings.dmSize = sizeof(DEVMODE); | 1112 settings.dmSize = sizeof(DEVMODE); |
1099 settings.dmBitsPerPel = video->format->BitsPerPixel; | 1113 settings.dmBitsPerPel = video->format->BitsPerPixel; |
1100 settings.dmPelsWidth = width; | 1114 settings.dmPelsWidth = width; |
1101 settings.dmPelsHeight = height; | 1115 settings.dmPelsHeight = height; |
1102 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; | 1116 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; |
1103 if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) { | 1117 if ( width <= SDL_desktop_mode.dmPelsWidth && height <= SDL_desktop_mode.dmPelsHeight ) { |
1118 settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency; | |
1119 settings.dmFields |= DM_DISPLAYFREQUENCY; | |
1120 } | |
1121 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); | |
1122 if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { | |
1123 settings.dmFields &= ~DM_DISPLAYFREQUENCY; | |
1124 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); | |
1125 } | |
1126 if ( changed ) { | |
1104 video->flags |= SDL_FULLSCREEN; | 1127 video->flags |= SDL_FULLSCREEN; |
1105 SDL_fullscreen_mode = settings; | 1128 SDL_fullscreen_mode = settings; |
1106 } | 1129 } |
1107 } | 1130 } |
1108 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | 1131 #endif /* !NO_CHANGEDISPLAYSETTINGS */ |