2011-10-01 17:42:59 +00:00
|
|
|
//========================================================================
|
|
|
|
// GLFW - An OpenGL library
|
|
|
|
// Platform: X11 (Unix)
|
|
|
|
// API version: 3.0
|
|
|
|
// WWW: http://www.glfw.org/
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
|
|
|
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-09-12 19:04:24 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <malloc.h>
|
2011-10-01 17:42:59 +00:00
|
|
|
|
2012-09-12 18:46:54 +00:00
|
|
|
// These constants are missing on MinGW
|
2011-10-06 21:28:56 +00:00
|
|
|
#ifndef EDS_ROTATEDMODE
|
2012-09-12 18:46:54 +00:00
|
|
|
#define EDS_ROTATEDMODE 0x00000004
|
2011-10-06 21:28:56 +00:00
|
|
|
#endif
|
2012-01-31 22:47:01 +00:00
|
|
|
#ifndef DISPLAY_DEVICE_ACTIVE
|
2012-09-12 18:46:54 +00:00
|
|
|
#define DISPLAY_DEVICE_ACTIVE 0x00000001
|
2012-01-31 22:47:01 +00:00
|
|
|
#endif
|
|
|
|
|
2011-10-01 17:42:59 +00:00
|
|
|
|
2012-09-12 19:04:24 +00:00
|
|
|
//========================================================================
|
2012-12-31 01:06:19 +00:00
|
|
|
// Return closest video mode by dimensions and bits per pixel
|
2012-09-12 19:04:24 +00:00
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
static GLboolean getClosestVideoMode(int* width, int* height,
|
2012-12-31 01:06:19 +00:00
|
|
|
int* bpp, GLboolean exactBPP)
|
2012-09-12 19:04:24 +00:00
|
|
|
{
|
2012-12-31 01:06:19 +00:00
|
|
|
int mode, bestWidth = 0, bestHeight = 0, bestBPP = 0;
|
|
|
|
unsigned int sizeDiff, leastSizeDiff;
|
2012-09-12 19:04:24 +00:00
|
|
|
GLboolean foundMode = GL_FALSE;
|
|
|
|
DEVMODE dm;
|
|
|
|
|
2012-12-31 01:06:19 +00:00
|
|
|
leastSizeDiff = UINT_MAX;
|
2012-09-12 19:04:24 +00:00
|
|
|
|
|
|
|
for (mode = 0; ; mode++)
|
|
|
|
{
|
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
|
|
|
if (!EnumDisplaySettings(NULL, mode, &dm))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (exactBPP && dm.dmBitsPerPel != *bpp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sizeDiff = (abs(dm.dmBitsPerPel - *bpp) << 25) |
|
|
|
|
((dm.dmPelsWidth - *width) *
|
|
|
|
(dm.dmPelsWidth - *width) +
|
|
|
|
(dm.dmPelsHeight - *height) *
|
|
|
|
(dm.dmPelsHeight - *height));
|
|
|
|
|
2012-12-31 01:06:19 +00:00
|
|
|
// We match BPP first, then screen area
|
2012-09-12 19:04:24 +00:00
|
|
|
|
2012-12-31 01:06:19 +00:00
|
|
|
if ((sizeDiff < leastSizeDiff) || (sizeDiff == leastSizeDiff))
|
2012-09-12 19:04:24 +00:00
|
|
|
{
|
|
|
|
bestWidth = dm.dmPelsWidth;
|
|
|
|
bestHeight = dm.dmPelsHeight;
|
|
|
|
bestBPP = dm.dmBitsPerPel;
|
|
|
|
|
|
|
|
leastSizeDiff = sizeDiff;
|
|
|
|
|
|
|
|
foundMode = GL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundMode)
|
|
|
|
return GL_FALSE;
|
|
|
|
|
|
|
|
*width = bestWidth;
|
|
|
|
*height = bestHeight;
|
|
|
|
*bpp = bestBPP;
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Change the current video mode
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwSetVideoMode(int* width, int* height,
|
2012-12-31 01:06:19 +00:00
|
|
|
int* bpp, GLboolean exactBPP)
|
2012-09-12 19:04:24 +00:00
|
|
|
{
|
|
|
|
DEVMODE dm;
|
2012-12-31 01:06:19 +00:00
|
|
|
int closestWidth, closestHeight, closestBPP;
|
2012-09-12 19:04:24 +00:00
|
|
|
|
|
|
|
closestWidth = *width;
|
|
|
|
closestHeight = *height;
|
|
|
|
closestBPP = *bpp;
|
|
|
|
|
|
|
|
if (getClosestVideoMode(&closestWidth, &closestHeight,
|
2012-12-31 01:06:19 +00:00
|
|
|
&closestBPP, exactBPP))
|
2012-09-12 19:04:24 +00:00
|
|
|
{
|
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
|
|
|
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
|
|
|
|
dm.dmPelsWidth = closestWidth;
|
|
|
|
dm.dmPelsHeight = closestHeight;
|
|
|
|
dm.dmBitsPerPel = closestBPP;
|
|
|
|
|
|
|
|
if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
|
|
|
|
{
|
2012-12-31 01:06:19 +00:00
|
|
|
*width = closestWidth;
|
|
|
|
*height = closestHeight;
|
|
|
|
*bpp = closestBPP;
|
2012-09-12 19:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
|
|
|
EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm);
|
|
|
|
|
2012-12-31 01:06:19 +00:00
|
|
|
*width = dm.dmPelsWidth;
|
|
|
|
*height = dm.dmPelsHeight;
|
|
|
|
*bpp = dm.dmBitsPerPel;
|
2012-09-12 19:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Restore the previously saved (original) video mode
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwRestoreVideoMode(void)
|
|
|
|
{
|
|
|
|
ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-01 17:42:59 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-07-06 12:36:29 +00:00
|
|
|
//========================================================================
|
2012-09-12 17:35:52 +00:00
|
|
|
// Return a list of available monitors
|
2012-07-06 12:36:29 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
2011-10-01 17:42:59 +00:00
|
|
|
{
|
2012-09-12 17:35:52 +00:00
|
|
|
int size = 0, found = 0;
|
|
|
|
_GLFWmonitor** monitors = NULL;
|
|
|
|
DWORD adapterIndex = 0;
|
2011-10-01 17:42:59 +00:00
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2012-09-12 18:54:12 +00:00
|
|
|
// Enumerate display adapters
|
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
DISPLAY_DEVICE adapter, monitor;
|
|
|
|
DEVMODE settings;
|
|
|
|
const char* name;
|
|
|
|
HDC dc;
|
2011-10-01 17:42:59 +00:00
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
ZeroMemory(&adapter, sizeof(DISPLAY_DEVICE));
|
|
|
|
adapter.cb = sizeof(DISPLAY_DEVICE);
|
2011-10-01 17:42:59 +00:00
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
if (!EnumDisplayDevices(NULL, adapterIndex, &adapter, 0))
|
|
|
|
break;
|
2011-10-01 17:42:59 +00:00
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
adapterIndex++;
|
2011-10-02 20:13:47 +00:00
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
if ((adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) ||
|
|
|
|
!(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
ZeroMemory(&settings, sizeof(DEVMODE));
|
|
|
|
settings.dmSize = sizeof(DEVMODE);
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
EnumDisplaySettingsEx(adapter.DeviceName,
|
|
|
|
ENUM_CURRENT_SETTINGS,
|
|
|
|
&settings,
|
|
|
|
EDS_ROTATEDMODE);
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
name = _glfwCreateUTF8FromWideString(adapter.DeviceName);
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
// TODO: wat
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
if (found == size)
|
|
|
|
{
|
|
|
|
if (size)
|
|
|
|
size *= 2;
|
|
|
|
else
|
|
|
|
size = 4;
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
monitors = (_GLFWmonitor**) realloc(monitors, sizeof(_GLFWmonitor*) * size);
|
|
|
|
if (!monitors)
|
2012-09-12 17:35:52 +00:00
|
|
|
{
|
|
|
|
// TODO: wat
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-09-12 20:51:55 +00:00
|
|
|
}
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
ZeroMemory(&monitor, sizeof(DISPLAY_DEVICE));
|
|
|
|
monitor.cb = sizeof(DISPLAY_DEVICE);
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0);
|
|
|
|
dc = CreateDC(L"DISPLAY", monitor.DeviceString, NULL, NULL);
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-13 15:46:40 +00:00
|
|
|
const GLboolean primary = adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE;
|
|
|
|
|
|
|
|
monitors[found] = _glfwCreateMonitor(name, primary,
|
2012-09-12 20:51:55 +00:00
|
|
|
GetDeviceCaps(dc, HORZSIZE),
|
|
|
|
GetDeviceCaps(dc, VERTSIZE),
|
|
|
|
settings.dmPosition.x,
|
|
|
|
settings.dmPosition.y);
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
DeleteDC(dc);
|
2012-09-12 17:35:52 +00:00
|
|
|
|
2012-09-12 20:51:55 +00:00
|
|
|
if (!monitors[found])
|
|
|
|
{
|
|
|
|
// TODO: wat
|
|
|
|
return NULL;
|
2012-09-12 17:35:52 +00:00
|
|
|
}
|
2012-09-12 20:51:55 +00:00
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
monitors[found]->win32.name = _wcsdup(adapter.DeviceName);
|
2012-09-12 20:51:55 +00:00
|
|
|
found++;
|
2012-09-12 17:35:52 +00:00
|
|
|
}
|
2012-07-06 11:55:54 +00:00
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
*count = found;
|
|
|
|
return monitors;
|
2011-10-01 17:42:59 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 12:36:29 +00:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Destroy a monitor struct
|
|
|
|
//========================================================================
|
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
void _glfwPlatformDestroyMonitor(_GLFWmonitor* monitor)
|
2011-10-01 17:42:59 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
free(monitor->win32.name);
|
2011-10-01 17:42:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 19:04:24 +00:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Get a list of available video modes
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
|
|
|
|
{
|
|
|
|
int modeIndex = 0, count = 0;
|
|
|
|
GLFWvidmode* result = NULL;
|
|
|
|
|
|
|
|
*found = 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GLFWvidmode mode;
|
|
|
|
DEVMODE dm;
|
|
|
|
|
|
|
|
ZeroMemory(&dm, sizeof(DEVMODE));
|
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (!EnumDisplaySettings(monitor->win32.name, modeIndex, &dm))
|
2012-09-12 19:04:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
modeIndex++;
|
|
|
|
|
|
|
|
if (dm.dmBitsPerPel < 15)
|
|
|
|
{
|
|
|
|
// Skip modes with less than 15 BPP
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode.width = dm.dmPelsWidth;
|
|
|
|
mode.height = dm.dmPelsHeight;
|
|
|
|
_glfwSplitBPP(dm.dmBitsPerPel,
|
2012-09-12 21:03:15 +00:00
|
|
|
&mode.redBits,
|
|
|
|
&mode.greenBits,
|
|
|
|
&mode.blueBits);
|
2012-09-12 19:04:24 +00:00
|
|
|
|
|
|
|
for (i = 0; i < *found; i++)
|
|
|
|
{
|
|
|
|
if (_glfwCompareVideoModes(result + i, &mode) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < *found)
|
|
|
|
{
|
|
|
|
// This is a duplicate, so skip it
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*found == count)
|
|
|
|
{
|
|
|
|
void* larger;
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
count *= 2;
|
|
|
|
else
|
|
|
|
count = 128;
|
|
|
|
|
|
|
|
larger = realloc(result, count * sizeof(GLFWvidmode));
|
|
|
|
if (!larger)
|
|
|
|
{
|
|
|
|
free(result);
|
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
|
2012-09-12 19:04:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = (GLFWvidmode*) larger;
|
|
|
|
}
|
|
|
|
|
|
|
|
result[*found] = mode;
|
|
|
|
(*found)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Get the current video mode for the specified monitor
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
|
|
|
|
{
|
|
|
|
DEVMODE dm;
|
|
|
|
|
|
|
|
ZeroMemory(&dm, sizeof(DEVMODE));
|
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
EnumDisplaySettings(monitor->win32.name, ENUM_REGISTRY_SETTINGS, &dm);
|
2012-09-12 19:04:24 +00:00
|
|
|
|
|
|
|
mode->width = dm.dmPelsWidth;
|
|
|
|
mode->height = dm.dmPelsHeight;
|
|
|
|
_glfwSplitBPP(dm.dmBitsPerPel,
|
|
|
|
&mode->redBits,
|
|
|
|
&mode->greenBits,
|
|
|
|
&mode->blueBits);
|
|
|
|
}
|
|
|
|
|