summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaglcontext.mm
blob: 505be4a9dec58953b9157549f40053f89f68f50e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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;
}