summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaglcontext.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaglcontext.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.mm78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
new file mode 100644
index 0000000000..505be4a9de
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -0,0 +1,78 @@
+#include "qcocoaglcontext.h"
+#include <qdebug.h>
+#include <QtCore/private/qcore_mac_p.h>
+
+#import <Cocoa/Cocoa.h>
+
+QCocoaGLContext::QCocoaGLContext(NSOpenGLView *glView)
+:m_glView(glView)
+{
+
+}
+
+void QCocoaGLContext::makeCurrent()
+{
+ [[m_glView openGLContext] makeCurrentContext];
+}
+void QCocoaGLContext::doneCurrent()
+{
+ [NSOpenGLContext clearCurrentContext];
+}
+
+void QCocoaGLContext::swapBuffers()
+{
+ [[m_glView openGLContext] flushBuffer];
+}
+
+void* QCocoaGLContext::getProcAddress(const QString& procName)
+{
+ CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
+ CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, false);
+ CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url);
+ CFStringRef procNameCF = QCFString::toCFStringRef(procName);
+ void *proc = CFBundleGetFunctionPointerForName(bundle, procNameCF);
+ CFRelease(url);
+ CFRelease(bundle);
+ CFRelease(procNameCF);
+ return proc;
+}
+
+// Match up with createNSOpenGLPixelFormat below!
+QWindowFormat QCocoaGLContext::windowFormat() const
+{
+ QWindowFormat format;
+ format.setRedBufferSize(8);
+ format.setGreenBufferSize(8);
+ format.setBlueBufferSize(8);
+ format.setAlphaBufferSize(8);
+
+/*
+ format.setDepthBufferSize(24);
+ format.setAccumBufferSize(0);
+ format.setStencilBufferSize(8);
+ format.setSampleBuffers(false);
+ format.setSamples(1);
+ format.setDepth(true);
+ format.setRgba(true);
+ format.setAlpha(true);
+ format.setAccum(false);
+ format.setStencil(true);
+ format.setStereo(false);
+ format.setDirectRendering(false);
+*/
+ return format;
+}
+
+NSOpenGLPixelFormat *QCocoaGLContext::createNSOpenGLPixelFormat()
+{
+ NSOpenGLPixelFormatAttribute attrs[] =
+ {
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFADepthSize, 32,
+ 0
+ };
+
+ NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
+ return pixelFormat;
+}
+