Enforce OpenGL context creation under Cocoa

We don't support other context types, so fail in those cases.
Also, return OpenGL as the rendereable type of our surface.

Change-Id: I3d5632eb8555d73ed14837b662c7450589a8681f
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
This commit is contained in:
Giuseppe D'Angelo 2013-02-20 14:00:52 +01:00 committed by The Qt Project
parent 3b5600f6ee
commit 7e57501016
2 changed files with 11 additions and 2 deletions

View File

@ -61,6 +61,7 @@ void (*qcgl_getProcAddress(const QByteArray &procName))()
QSurfaceFormat qcgl_surfaceFormat()
{
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setRedBufferSize(8);
format.setGreenBufferSize(8);
format.setBlueBufferSize(8);

View File

@ -49,11 +49,19 @@
#import <Cocoa/Cocoa.h>
QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share)
: m_format(format)
: m_context(nil),
m_shareContext(nil),
m_format(format)
{
// we only support OpenGL contexts under Cocoa
if (m_format.renderableType() == QSurfaceFormat::DefaultRenderableType)
m_format.setRenderableType(QSurfaceFormat::OpenGL);
if (m_format.renderableType() != QSurfaceFormat::OpenGL)
return;
QCocoaAutoReleasePool pool; // For the SG Canvas render thread
NSOpenGLPixelFormat *pixelFormat = static_cast <NSOpenGLPixelFormat *>(qcgl_createNSOpenGLPixelFormat(format));
NSOpenGLPixelFormat *pixelFormat = static_cast <NSOpenGLPixelFormat *>(qcgl_createNSOpenGLPixelFormat(m_format));
m_shareContext = share ? static_cast<QCocoaGLContext *>(share)->nsOpenGLContext() : nil;
m_context = [NSOpenGLContext alloc];