1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -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)
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
int _glfwCompareVideoModes(const void* firstPtr, const void* secondPtr);
// Error handling (error.c)
void _glfwSetError(int error, const char* description);

View File

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