From fddfab508b83aea40e5b52c13d2d2c0193ddecbf Mon Sep 17 00:00:00 2001 From: rti Date: Wed, 4 Aug 2010 21:28:07 +0200 Subject: [PATCH] Fixed: #1004 updated get display modes implementation to use more current apis --- .../3d/driver/opengl/driver_opengl_mac.cpp | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_mac.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_mac.cpp index 9ed18ba9d..7886c52ce 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_mac.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_mac.cpp @@ -16,15 +16,19 @@ using namespace NL3D; namespace NL3D { -static int numberForKey( CFDictionaryRef desc, CFStringRef key ) +static int bppFromDisplayMode(CGDisplayModeRef mode) { - CFNumberRef value; - int num = 0; - - if ( (value = (CFNumberRef)CFDictionaryGetValue(desc, key)) == NULL ) - return 0; - CFNumberGetValue(value, kCFNumberIntType, &num); - return num; + 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) @@ -40,41 +44,43 @@ bool getMacModes(std::vector &modes) return false; } - nldebug("3D: %d displays found\n", (int)numDisplays); + nldebug("3D: %d displays found", (int)numDisplays); for (CGDisplayCount i = 0; i < numDisplays; ++i) { CGDirectDisplayID dspy = display[i]; - - CFArrayRef modeList = CGDisplayAvailableModes(dspy); + CFArrayRef modeList = CGDisplayCopyAllDisplayModes(dspy, NULL); + if (modeList == NULL) { nlwarning("Display is invalid"); continue; } - CFIndex cnt = CFArrayGetCount(modeList); - nldebug("3D: Display 0x%x has %d modes:", (unsigned int)dspy, (int)cnt); - for (CFIndex j = 0; j < cnt; ++j) - { - CFDictionaryRef desc = (CFDictionaryRef)CFArrayGetValueAtIndex(modeList, j); - - int w = numberForKey(desc, kCGDisplayWidth); - int h = numberForKey(desc, kCGDisplayHeight); - int bpp = numberForKey(desc, kCGDisplayBitsPerPixel); - int freq = numberForKey(desc, kCGDisplayRefreshRate); + 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; - mode.Frequency = freq; + + // 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( " > Mode %d: %dx%d, %d BPP, %d Hz", j, w, h, bpp, freq); + nldebug( " Display 0x%x: Mode %dx%d, %d BPP", dspy, w, h, bpp); + } } } return true;