1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-27 04:28:52 -05:00

Fixed implementation on win32 platform for iteration of video modes.

This commit is contained in:
Marcel Metz 2011-02-18 22:59:40 -05:00
parent 021ce1f7f4
commit 3cb4dea453
2 changed files with 44 additions and 56 deletions

View File

@ -328,6 +328,7 @@ void _glfwFree(void* ptr);
// Fullscren management (fullscreen.c) // Fullscren management (fullscreen.c)
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
int _glfwCompareVideoModes(const void* firstPtr, const void* secondPtr);
// Error handling (error.c) // Error handling (error.c)
void _glfwSetError(int error, const char* description); void _glfwSetError(int error, const char* description);

View File

@ -184,69 +184,56 @@ void _glfwRestoreVideoMode(void)
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
{ {
int count, success, mode, i, j; DEVMODE deviceMode;
int m1, m2, bpp, r, g, b; DWORD deviceModeNum;
DEVMODE dm;
// Loop through all video modes and extract all the UNIQUE modes GLFWvidmode* vidModes;
count = 0; int vidModesCount;
mode = 0; GLFWvidmode vidMode;
do deviceMode.dmSize = sizeof(DEVMODE);
deviceModeNum = 0;
vidModes = NULL;
vidModesCount = 0;
while (EnumDisplaySettings(NULL, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount)))
{ {
// Get video mode properties deviceModeNum++;
dm.dmSize = sizeof(DEVMODE);
success = EnumDisplaySettings(NULL, mode, &dm);
// Is it a valid mode? (only list depths >= 15 bpp) if (deviceMode.dmBitsPerPel < 15)
if (success && dm.dmBitsPerPel >= 15)
{ {
// Convert to RGB, and back to bpp ("mask out" alpha bits etc) continue;
_glfwSplitBPP(dm.dmBitsPerPel, &r, &g, &b);
bpp = r + g + b;
// Mode "code" for this mode
m1 = (bpp << 25) | (dm.dmPelsWidth * dm.dmPelsHeight);
// Insert mode in list (sorted), and avoid duplicates
for (i = 0; i < count; i++)
{
// Mode "code" for already listed mode
bpp = list[i].redBits + list[i].greenBits + list[i].blueBits;
m2 = (bpp << 25) | (list[i].width * list[i].height);
if (m1 <= m2)
break;
}
// New entry at the end of the list?
if (i >= count)
{
list[count].width = dm.dmPelsWidth;
list[count].height = dm.dmPelsHeight;
list[count].redBits = r;
list[count].greenBits = g;
list[count].blueBits = b;
count ++;
}
// Insert new entry in the list?
else if (m1 < m2)
{
for (j = count; j > i; j--)
list[j] = list[j - 1];
list[i].width = dm.dmPelsWidth;
list[i].height = dm.dmPelsHeight;
list[i].redBits = r;
list[i].greenBits = g;
list[i].blueBits = b;
count++;
}
} }
mode++;
}
while (success && (count < maxcount));
return count; vidMode.height = deviceMode.dmPelsHeight;
vidMode.width = deviceMode.dmPelsWidth;
// Convert to RGB, and back to bpp ("mask out" alpha bits etc)
_glfwSplitBPP(deviceMode.dmBitsPerPel,
&vidMode.redBits,
&vidMode.greenBits,
&vidMode.blueBits);
// skip duplicates.
if (vidModes && bsearch(&vidMode, vidModes, vidModesCount, sizeof(GLFWvidmode), _glfwCompareVideoModes))
{
continue;
}
vidModes = realloc(vidModes, sizeof(GLFWvidmode) * ++vidModesCount);
memcpy(vidModes + (vidModesCount - 1), &vidMode, sizeof(GLFWvidmode));
qsort(vidModes, vidModesCount, sizeof(GLFWvidmode), _glfwCompareVideoModes);
}
if (list && maxcount)
{
memcpy(list, vidModes, sizeof(GLFWvidmode) * min(vidModesCount, maxcount));
}
free(vidModes);
return vidModesCount;
} }