From e4f066c7d5438c5b18d16a50dcae4a0819adf789 Mon Sep 17 00:00:00 2001 From: rti Date: Wed, 4 Aug 2010 22:12:54 +0200 Subject: [PATCH] Fixed: #1053 Move mac screen mode retrieval to cocoa_adapter --- .../3d/driver/opengl/driver_opengl_mac.cpp | 91 ------------------- .../3d/driver/opengl/driver_opengl_window.cpp | 5 +- .../src/3d/driver/opengl/mac/cocoa_adapter.h | 3 + .../src/3d/driver/opengl/mac/cocoa_adapter.mm | 75 +++++++++++++++ 4 files changed, 79 insertions(+), 95 deletions(-) delete mode 100644 code/nel/src/3d/driver/opengl/driver_opengl_mac.cpp diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_mac.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_mac.cpp deleted file mode 100644 index 7886c52ce..000000000 --- a/code/nel/src/3d/driver/opengl/driver_opengl_mac.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "stdopengl.h" - -#include - -#ifdef NL_OS_MAC - -#include - -#include -#include - -using namespace std; -using namespace NLMISC; -using namespace NL3D; - -namespace NL3D -{ - -static int bppFromDisplayMode(CGDisplayModeRef mode) -{ - CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode); - - if(CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), - kCFCompareCaseInsensitive) == kCFCompareEqualTo) - return 32; - - else if(CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), - kCFCompareCaseInsensitive) == kCFCompareEqualTo) - return 16; - - return 0; -} - -bool getMacModes(std::vector &modes) -{ - static const CGDisplayCount kMaxDisplays = 16; - CGDirectDisplayID display[kMaxDisplays]; - CGDisplayCount numDisplays; - - CGDisplayErr err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays); - if (err != CGDisplayNoErr) - { - nlwarning("Cannot get displays (%d)", err); - return false; - } - - nldebug("3D: %d displays found", (int)numDisplays); - - for (CGDisplayCount i = 0; i < numDisplays; ++i) - { - CGDirectDisplayID dspy = display[i]; - CFArrayRef modeList = CGDisplayCopyAllDisplayModes(dspy, NULL); - - if (modeList == NULL) - { - nlwarning("Display is invalid"); - continue; - } - - for (CFIndex j = 0; j < CFArrayGetCount(modeList); ++j) - { - CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modeList, j); - int bpp = bppFromDisplayMode(mode); - - if (bpp >= 16) - { - int w = CGDisplayModeGetWidth(mode); - int h = CGDisplayModeGetHeight(mode); - - // Add this mode - GfxMode mode; - mode.Width = (uint16)w; - mode.Height = (uint16)h; - mode.Depth = (uint8)bpp; - - // frequency stays at 0 because on mac cocoa, display resolution - // is never really changed. if rendering resolution < display resolution - // cocoa interpolates and keeps the display at it's original resolution - mode.Frequency = 0; - modes.push_back (mode); - - nldebug( " Display 0x%x: Mode %dx%d, %d BPP", dspy, w, h, bpp); - } - } - } - return true; -} - -} - -#endif diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp index 8107f3c6c..69d88c17c 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -1581,10 +1581,7 @@ bool CDriverGL::getModes(std::vector &modes) modeIndex++; } #elif defined(NL_OS_MAC) - getMacModes(modes); -#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE) -# warning "OpenGL Driver: Missing Mac Implementation" - nlwarning("OpenGL Driver: Missing Mac Implementation"); + NL3D::MAC::getModes(modes); #elif defined (NL_OS_UNIX) diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.h b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.h index 457c35793..d7e66cfe5 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.h +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.h @@ -70,6 +70,9 @@ bool setWindowStyle(nlWindow wnd, bool fullscreen); /// mac specific stuff while calling CDriverGL::getCurrentScreenMode() void getCurrentScreenMode(nlWindow wnd, GfxMode& mode); +/// mac specific stuff while calling CDriverGL::getModes() +bool getModes(std::vector &modes); + /// mac specific stuff while calling CDriverGL::getWindowSize() void getWindowSize(nlWindow wnd, uint32 &width, uint32 &height); diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm index d4e5dfea0..81fed89c1 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm @@ -386,6 +386,81 @@ void getCurrentScreenMode(nlWindow wnd, GfxMode& mode) } } +/// helper to extract bits per pixel value from screen mode, only 16 or 32 bits +static int bppFromDisplayMode(CGDisplayModeRef mode) +{ + CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode); + + if(CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), + kCFCompareCaseInsensitive) == kCFCompareEqualTo) + return 32; + + else if(CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), + kCFCompareCaseInsensitive) == kCFCompareEqualTo) + return 16; + + return 0; +} + +/// get the list of available screen modes +bool getModes(std::vector &modes) +{ + static const CGDisplayCount kMaxDisplays = 16; + CGDirectDisplayID display[kMaxDisplays]; + CGDisplayCount numDisplays; + + CGDisplayErr err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays); + if(err != CGDisplayNoErr) + { + nlwarning("Cannot get displays (%d)", err); + return false; + } + + nldebug("3D: %d displays found", (int)numDisplays); + + for (CGDisplayCount i = 0; i < numDisplays; ++i) + { + CGDirectDisplayID dspy = display[i]; + CFArrayRef modeList = CGDisplayCopyAllDisplayModes(dspy, NULL); + + if (modeList == NULL) + { + nlwarning("Display is invalid"); + continue; + } + + for (CFIndex j = 0; j < CFArrayGetCount(modeList); ++j) + { + CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modeList, j); + uint8 bpp = bppFromDisplayMode(mode); + + if (bpp >= 16) + { + uint16 w = CGDisplayModeGetWidth(mode); + uint16 h = CGDisplayModeGetHeight(mode); + + // Add this mode + GfxMode mode; + mode.Width = w; + mode.Height = h; + mode.Depth = bpp; + + // Frequency stays at 0 because on mac cocoa, display resolution + // is never really changed. if rendering res < display res, + // cocoa interpolates and keeps the display at it's original res. + // In case of x11 on mac, fullscreen is not supported, so again, no + // mode switching is done. + mode.Frequency = 0; + modes.push_back (mode); + + nldebug(" Display 0x%x: Mode %dx%d, %d BPP", dspy, w, h, bpp); + } + } + } + + return true; +} + /// get the size of the window's content area void getWindowSize(nlWindow wnd, uint32 &width, uint32 &height) {