Video mode setting cleanup.

This commit is contained in:
Camilla Berglund 2013-04-21 21:28:07 +02:00
parent b0ae7a6957
commit f5ba0d9f22
7 changed files with 16 additions and 25 deletions

View File

@ -152,12 +152,13 @@ static void endFadeReservation(CGDisplayFadeReservationToken token)
// Change the current video mode // Change the current video mode
// //
GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, int* width, int* height, int* bpp) GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
CGDisplayModeRef bestMode = NULL; CGDisplayModeRef bestMode = NULL;
CFArrayRef modes; CFArrayRef modes;
CFIndex count, i; CFIndex count, i;
unsigned int leastSizeDiff = UINT_MAX; unsigned int leastSizeDiff = UINT_MAX;
const int bpp = desired->redBits - desired->greenBits - desired->blueBits;
modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL); modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
count = CFArrayGetCount(modes); count = CFArrayGetCount(modes);
@ -185,14 +186,13 @@ GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, int* width, int* height, int*
int modeWidth = (int) CGDisplayModeGetWidth(mode); int modeWidth = (int) CGDisplayModeGetWidth(mode);
int modeHeight = (int) CGDisplayModeGetHeight(mode); int modeHeight = (int) CGDisplayModeGetHeight(mode);
unsigned int sizeDiff = (abs(modeBPP - *bpp) << 25) | unsigned int sizeDiff = (abs(modeBPP - bpp) << 25) |
((modeWidth - *width) * (modeWidth - *width) + ((modeWidth - desired->width) * (modeWidth - desired->width) +
(modeHeight - *height) * (modeHeight - *height)); (modeHeight - desired->height) * (modeHeight - desired->height));
if (sizeDiff < leastSizeDiff) if (sizeDiff < leastSizeDiff)
{ {
bestMode = mode; bestMode = mode;
leastSizeDiff = sizeDiff; leastSizeDiff = sizeDiff;
} }
} }

View File

@ -138,7 +138,7 @@ void _glfwInitJoysticks(void);
void _glfwTerminateJoysticks(void); void _glfwTerminateJoysticks(void);
// Fullscreen // Fullscreen
GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, int* width, int* height, int* bpp); GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoMode(_GLFWmonitor* monitor); void _glfwRestoreVideoMode(_GLFWmonitor* monitor);
// OpenGL support // OpenGL support

View File

@ -767,13 +767,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
return GL_FALSE; return GL_FALSE;
} }
// Mac OS X needs non-zero color size, so set resonable values
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
if (colorBits == 0)
colorBits = 24;
else if (colorBits < 15)
colorBits = 15;
// Don't use accumulation buffer support; it's not accelerated // Don't use accumulation buffer support; it's not accelerated
// Aux buffers probably aren't accelerated either // Aux buffers probably aren't accelerated either
@ -787,9 +780,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (wndconfig->monitor) if (wndconfig->monitor)
{ {
int bpp = colorBits + fbconfig->alphaBits; if (!_glfwSetVideoMode(window->monitor, &window->videoMode))
if (!_glfwSetVideoMode(window->monitor, &window->videoMode.width, &window->videoMode.height, &bpp))
return GL_FALSE; return GL_FALSE;
_glfwPlatformShowWindow(window); _glfwPlatformShowWindow(window);

View File

@ -50,13 +50,13 @@
// Change the current video mode // Change the current video mode
// //
int _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* mode) GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
GLFWvidmode current; GLFWvidmode current;
const GLFWvidmode* best; const GLFWvidmode* best;
DEVMODE dm; DEVMODE dm;
best = _glfwChooseVideoMode(monitor, mode); best = _glfwChooseVideoMode(monitor, desired);
_glfwPlatformGetVideoMode(monitor, &current); _glfwPlatformGetVideoMode(monitor, &current);
if (_glfwCompareVideoModes(&current, best) == 0) if (_glfwCompareVideoModes(&current, best) == 0)

View File

@ -247,7 +247,7 @@ int _glfwAnalyzeContext(const _GLFWwindow* window,
const _GLFWfbconfig* fbconfig); const _GLFWfbconfig* fbconfig);
// Fullscreen support // Fullscreen support
int _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* mode); GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoMode(_GLFWmonitor* monitor); void _glfwRestoreVideoMode(_GLFWmonitor* monitor);

View File

@ -41,7 +41,7 @@
// Set the current video mode for the specified monitor // Set the current video mode for the specified monitor
// //
void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* mode) void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
if (_glfw.x11.randr.available) if (_glfw.x11.randr.available)
{ {
@ -82,10 +82,10 @@ void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* mode)
if (mi->modeFlags & RR_Interlace) if (mi->modeFlags & RR_Interlace)
continue; continue;
unsigned int sizeDiff = (mi->width - mode->width) * unsigned int sizeDiff = (mi->width - desired->width) *
(mi->width - mode->width) + (mi->width - desired->width) +
(mi->height - mode->height) * (mi->height - desired->height) *
(mi->height - mode->height); (mi->height - desired->height);
if (sizeDiff < leastSizeDiff) if (sizeDiff < leastSizeDiff)
{ {

View File

@ -229,7 +229,7 @@ int _glfwCreateContext(_GLFWwindow* window,
void _glfwDestroyContext(_GLFWwindow* window); void _glfwDestroyContext(_GLFWwindow* window);
// Fullscreen support // Fullscreen support
void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* mode); void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoMode(_GLFWmonitor* monitor); void _glfwRestoreVideoMode(_GLFWmonitor* monitor);
// Joystick input // Joystick input