mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 14:24:35 +00:00
Simplified Win32 video mode enumeration.
This commit is contained in:
parent
c68a4aa2ef
commit
9498ac52b9
@ -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)
|
|
||||||
break;
|
|
||||||
|
|
||||||
result = EnumDisplaySettings(wideName, deviceModeNum, &deviceMode);
|
ZeroMemory(&deviceMode, sizeof(DEVMODE));
|
||||||
free(wideName);
|
deviceMode.dmSize = sizeof(DEVMODE);
|
||||||
|
|
||||||
if (!result)
|
if (!EnumDisplaySettings(deviceName, deviceModeIndex, &deviceMode))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (vidModesCount >= maxcount)
|
deviceModeIndex++;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user