1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Simplified Win32 video mode enumeration.

This commit is contained in:
Camilla Berglund 2012-07-06 22:52:53 +02:00
parent c68a4aa2ef
commit 9498ac52b9

View File

@ -184,64 +184,50 @@ void _glfwRestoreVideoMode(void)
int _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, GLFWvidmode* list, int maxcount) int _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, GLFWvidmode* list, int maxcount)
{ {
DEVMODE deviceMode; DWORD deviceModeIndex = 0;
DWORD deviceModeNum; int modeCount = 0;
GLFWvidmode* vidModes; WCHAR* deviceName = _glfwCreateWideStringFromUTF8(monitor->Win32.name);
int vidModesCount; if (!deviceName)
GLFWvidmode vidMode; return 0;
deviceMode.dmSize = sizeof(DEVMODE);
deviceModeNum = 0;
vidModes = NULL;
vidModesCount = 0;
for (;;) for (;;)
{ {
BOOL result; GLFWvidmode mode;
WCHAR* wideName = _glfwCreateWideStringFromUTF8(monitor->Win32.name); DEVMODE deviceMode;
if (!wideName)
ZeroMemory(&deviceMode, sizeof(DEVMODE));
deviceMode.dmSize = sizeof(DEVMODE);
if (!EnumDisplaySettings(deviceName, deviceModeIndex, &deviceMode))
break; break;
result = EnumDisplaySettings(wideName, deviceModeNum, &deviceMode); deviceModeIndex++;
free(wideName);
if (!result)
break;
if (vidModesCount >= maxcount)
break;
deviceModeNum++;
if (deviceMode.dmBitsPerPel < 15) if (deviceMode.dmBitsPerPel < 15)
continue; continue;
vidMode.height = deviceMode.dmPelsHeight; mode.height = deviceMode.dmPelsHeight;
vidMode.width = deviceMode.dmPelsWidth; mode.width = deviceMode.dmPelsWidth;
// Convert to RGB, and back to bpp ("mask out" alpha bits etc)
_glfwSplitBPP(deviceMode.dmBitsPerPel, _glfwSplitBPP(deviceMode.dmBitsPerPel,
&vidMode.redBits, &mode.redBits,
&vidMode.greenBits, &mode.greenBits,
&vidMode.blueBits); &mode.blueBits);
// skip duplicates. // Skip duplicate modes
if (vidModes && bsearch(&vidMode, vidModes, vidModesCount, sizeof(GLFWvidmode), _glfwCompareVideoModes)) if (bsearch(&mode, list, modeCount, sizeof(GLFWvidmode), _glfwCompareVideoModes))
continue; continue;
vidModes = realloc(vidModes, sizeof(GLFWvidmode) * ++vidModesCount); list[modeCount] = mode;
memcpy(vidModes + (vidModesCount - 1), &vidMode, sizeof(GLFWvidmode)); modeCount++;
qsort(vidModes, vidModesCount, sizeof(GLFWvidmode), _glfwCompareVideoModes); qsort(list, modeCount, sizeof(GLFWvidmode), _glfwCompareVideoModes);
if (modeCount >= maxcount)
break;
} }
if (list && maxcount) free(deviceName);
memcpy(list, vidModes, sizeof(GLFWvidmode) * ((vidModesCount < maxcount) ? vidModesCount : maxcount)); return modeCount;
free(vidModes);
return vidModesCount;
} }