From 3089e60fbd1acd0a41e4ce049adefd3b7ead4012 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 16 Sep 2010 03:48:19 +0200 Subject: [PATCH] Everyone needs to be able to split BPPs these days. --- src/cocoa/cocoa_window.m | 4 +--- src/fullscreen.c | 29 +++++++++++++++++++++++++++++ src/internal.h | 3 +++ src/win32/win32_fullscreen.c | 28 ++-------------------------- src/x11/x11_fullscreen.c | 27 ++------------------------- 5 files changed, 37 insertions(+), 54 deletions(-) diff --git a/src/cocoa/cocoa_window.m b/src/cocoa/cocoa_window.m index 4353a216..941f24ba 100644 --- a/src/cocoa/cocoa_window.m +++ b/src/cocoa/cocoa_window.m @@ -792,9 +792,7 @@ void _glfwPlatformRefreshWindowParams(void) forAttribute:NSOpenGLPFAColorSize forVirtualScreen:0]; value -= window->alphaBits; - window->redBits = value / 3; - window->greenBits = value / 3; - window->blueBits = value / 3; + _glfwSplitBPP(value, &window->redBits, &window->greenBits, &window->blueBits); [window->NSGL.pixelFormat getValues:&value forAttribute:NSOpenGLPFADepthSize diff --git a/src/fullscreen.c b/src/fullscreen.c index 55e9c548..8b706a9d 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -63,6 +63,35 @@ static int compareVideoModes(const void* firstPtr, const void* secondPtr) return firstSize - secondSize; } + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Convert BPP to RGB bits based on "best guess" +//======================================================================== + +void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) +{ + int delta; + + // We assume that by 32 they really meant 24 + if (bpp == 32) + bpp = 24; + + // Convert "bits per pixel" to red, green & blue sizes + + *red = *green = *blue = bpp / 3; + delta = bpp - (*red * 3); + if (delta >= 1) + *green = *green + 1; + + if (delta == 2) + *red = *red + 1; +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/internal.h b/src/internal.h index 3d71baac..52b5bdff 100644 --- a/src/internal.h +++ b/src/internal.h @@ -284,6 +284,9 @@ void* _glfwPlatformGetProcAddress(const char* procname); // Prototypes for platform independent internal functions //======================================================================== +// Fullscren management (fullscreen.c) +void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); + // Error handling void _glfwSetError(int error); diff --git a/src/win32/win32_fullscreen.c b/src/win32/win32_fullscreen.c index 58f262b1..3604b8d1 100644 --- a/src/win32/win32_fullscreen.c +++ b/src/win32/win32_fullscreen.c @@ -34,30 +34,6 @@ #include -//======================================================================== -// Convert BPP to RGB bits based on "best guess" -//======================================================================== - -static void bpp2rgb(int bpp, int* r, int* g, int* b) -{ - int delta; - - // We assume that by 32 they really meant 24 - if (bpp == 32) - bpp = 24; - - // Convert "bits per pixel" to red, green & blue sizes - - *r = *g = *b = bpp / 3; - delta = bpp - (*r * 3); - if (delta >= 1) - *g = *g + 1; - - if (delta == 2) - *r = *r + 1; -} - - //======================================================================== // Return closest video mode by dimensions, refresh rate and bits per pixel //======================================================================== @@ -226,7 +202,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) if (success && dm.dmBitsPerPel >= 15) { // Convert to RGB, and back to bpp ("mask out" alpha bits etc) - bpp2rgb(dm.dmBitsPerPel, &r, &g, &b); + _glfwSplitBPP(dm.dmBitsPerPel, &r, &g, &b); bpp = r + g + b; // Mode "code" for this mode @@ -289,6 +265,6 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode) // Return desktop mode parameters mode->width = dm.dmPelsWidth; mode->height = dm.dmPelsHeight; - bpp2rgb(dm.dmBitsPerPel, &mode->redBits, &mode->greenBits, &mode->blueBits); + _glfwSplitBPP(dm.dmBitsPerPel, &mode->redBits, &mode->greenBits, &mode->blueBits); } diff --git a/src/x11/x11_fullscreen.c b/src/x11/x11_fullscreen.c index 5a584636..a80ed918 100644 --- a/src/x11/x11_fullscreen.c +++ b/src/x11/x11_fullscreen.c @@ -34,29 +34,6 @@ #include -//======================================================================== -// Convert BPP to RGB bits (based on "best guess") -//======================================================================== - -static void bpp2rgb(int bpp, int* r, int* g, int* b) -{ - int delta; - - // Special case: BPP = 32 (I don't think this is necessary for X11??) - if (bpp == 32) - bpp = 24; - - // Convert "bits per pixel" to red, green & blue sizes - *r = *g = *b = bpp / 3; - delta = bpp - (*r * 3); - if (delta >= 1) - *g = *g + 1; - - if (delta == 2) - *r = *r + 1; -} - - ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// @@ -391,7 +368,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) depth = vislist[k].depth; // Convert to RGB - bpp2rgb(depth, &r, &g, &b); + _glfwSplitBPP(depth, &r, &g, &b); depth = (r << 16) | (g << 8) | b; // Is this mode unique? @@ -516,7 +493,7 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode) bpp = DefaultDepth(dpy, screen); // Convert BPP to RGB bits - bpp2rgb(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits); + _glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits); #if defined(_GLFW_HAS_XRANDR) if (_glfwLibrary.X11.XRandR.available)