diff --git a/src/platformsupport/cglconvenience/cglconvenience.mm b/src/platformsupport/cglconvenience/cglconvenience.mm index 6b0354834d..280baf48a5 100644 --- a/src/platformsupport/cglconvenience/cglconvenience.mm +++ b/src/platformsupport/cglconvenience/cglconvenience.mm @@ -42,6 +42,7 @@ #include "cglconvenience_p.h" #include #include +#include void (*qcgl_getProcAddress(const QByteArray &procName))() { @@ -81,26 +82,36 @@ QSurfaceFormat qcgl_surfaceFormat() return format; } -void *qcgl_createNSOpenGLPixelFormat() +void *qcgl_createNSOpenGLPixelFormat(const QSurfaceFormat &format) { - NSOpenGLPixelFormatAttribute attrs[] = - { - NSOpenGLPFADoubleBuffer, - NSOpenGLPFADepthSize, 32, - NSOpenGLPFAMultisample, - NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1, - NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute) 8, - 0 - }; - NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; + QVector attrs; + + attrs.append(NSOpenGLPFADoubleBuffer); + + if (format.depthBufferSize() > 0) + attrs << NSOpenGLPFADepthSize << format.depthBufferSize(); + if (format.stencilBufferSize() > 0) + attrs << NSOpenGLPFAStencilSize << format.stencilBufferSize(); + if (format.alphaBufferSize() > 0) + attrs << NSOpenGLPFAAlphaSize << format.alphaBufferSize(); + + if (format.samples() > 0) { + attrs << NSOpenGLPFAMultisample + << NSOpenGLPFASampleBuffers << (NSOpenGLPixelFormatAttribute) 1 + << NSOpenGLPFASamples << (NSOpenGLPixelFormatAttribute) format.samples(); + } + + attrs << 0; + + NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs.constData()]; return pixelFormat; } CGLContextObj qcgl_createGlContext() { CGLContextObj context; - NSOpenGLPixelFormat *format = reinterpret_cast(qcgl_createNSOpenGLPixelFormat()); + NSOpenGLPixelFormat *format = reinterpret_cast(qcgl_createNSOpenGLPixelFormat(qcgl_surfaceFormat())); CGLPixelFormatObj cglFormat = static_cast([format CGLPixelFormatObj]); CGLCreateContext(cglFormat ,NULL, &context); return context; diff --git a/src/platformsupport/cglconvenience/cglconvenience_p.h b/src/platformsupport/cglconvenience/cglconvenience_p.h index 96433b69d0..facf8c9b7f 100644 --- a/src/platformsupport/cglconvenience/cglconvenience_p.h +++ b/src/platformsupport/cglconvenience/cglconvenience_p.h @@ -48,7 +48,7 @@ void (*qcgl_getProcAddress(const QByteArray &procName))(); QSurfaceFormat qcgl_surfaceFormat(); -void *qcgl_createNSOpenGLPixelFormat(); +void *qcgl_createNSOpenGLPixelFormat(const QSurfaceFormat &format); CGLContextObj qcgl_createGlContext(); #endif // QMACGLCONVENIENCE_H diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h index 0cc2c2c2bd..dc8a428a91 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.h +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h @@ -68,7 +68,7 @@ public: void update(); - static NSOpenGLPixelFormat *createNSOpenGLPixelFormat(); + static NSOpenGLPixelFormat *createNSOpenGLPixelFormat(const QSurfaceFormat &format); NSOpenGLContext *nsOpenGLContext() const; private: diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index 20b637a668..bc9f55df62 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -53,7 +53,7 @@ QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLCo { QCocoaAutoReleasePool pool; // For the SG Canvas render thread. - NSOpenGLPixelFormat *pixelFormat = static_cast (qcgl_createNSOpenGLPixelFormat()); + NSOpenGLPixelFormat *pixelFormat = static_cast (qcgl_createNSOpenGLPixelFormat(format)); NSOpenGLContext *actualShare = share ? static_cast(share)->m_context : 0; m_context = [NSOpenGLContext alloc]; @@ -128,9 +128,9 @@ void QCocoaGLContext::update() [m_context update]; } -NSOpenGLPixelFormat *QCocoaGLContext::createNSOpenGLPixelFormat() +NSOpenGLPixelFormat *QCocoaGLContext::createNSOpenGLPixelFormat(const QSurfaceFormat &format) { - return static_cast(qcgl_createNSOpenGLPixelFormat()); + return static_cast(qcgl_createNSOpenGLPixelFormat(format)); } NSOpenGLContext *QCocoaGLContext::nsOpenGLContext() const