@@ -34,6 +34,11 @@ public class GLCanvas extends Canvas {
3434 static final int MAX_ATTRIBUTES = 32 ;
3535 static final String GLCONTEXT_KEY = "org.eclipse.swt.internal.cocoa.glcontext" ; //$NON-NLS-1$
3636
37+ static final int NSOpenGLPFAOpenGLProfile = 99 ;
38+ static final int NSOpenGLProfileVersion3_2Core = 0x3200 ;
39+ static final int NSOpenGLProfileVersionLegacy = 0x1000 ;
40+ static final int NSOpenGLProfileVersion4_1Core = 0x4100 ;
41+
3742/**
3843 * Create a GLCanvas widget using the attributes described in the GLData
3944 * object provided.
@@ -82,6 +87,26 @@ public GLCanvas (Composite parent, int style, GLData data) {
8287 attrib [pos ++] = data .stencilSize ;
8388 }
8489
90+ if (data .profile == Profile .CORE ) {
91+ attrib [pos ++] = NSOpenGLPFAOpenGLProfile ;
92+ attrib [pos ++] = NSOpenGLProfileVersion3_2Core ;
93+ }
94+ if (data .profile == Profile .COMPATIBILITY ) {
95+ attrib [pos ++] = NSOpenGLPFAOpenGLProfile ;
96+ attrib [pos ++] = NSOpenGLProfileVersionLegacy ;
97+ } else {
98+ if (data .majorVersion >= 4 ) {
99+ attrib [pos ++] = NSOpenGLPFAOpenGLProfile ;
100+ attrib [pos ++] = NSOpenGLProfileVersion4_1Core ;
101+ } else if (data .majorVersion >= 3 ) {
102+ attrib [pos ++] = NSOpenGLPFAOpenGLProfile ;
103+ attrib [pos ++] = NSOpenGLProfileVersion3_2Core ;
104+ } else {
105+ attrib [pos ++] = NSOpenGLPFAOpenGLProfile ;
106+ attrib [pos ++] = NSOpenGLProfileVersionLegacy ;
107+ }
108+ }
109+
85110 /*
86111 * Feature in Cocoa: NSOpenGL/CoreOpenGL only supports specifying the total number of bits
87112 * in the size of the color accumulator component. If specified, the color size is the sum of the red, green,
@@ -195,6 +220,19 @@ public GLData getGLData () {
195220 data .accumBlueSize = accumColorSize ;
196221 data .accumAlphaSize = accumColorSize ;
197222
223+ pixelFormat .getValues (value , NSOpenGLPFAOpenGLProfile , 0 );
224+ if (value [0 ] == NSOpenGLProfileVersion3_2Core ) {
225+ data .majorVersion = 3 ;
226+ data .minorVersion = 2 ;
227+ data .profile = Profile .CORE ;
228+ } else if (value [0 ] == NSOpenGLProfileVersionLegacy ) {
229+ data .profile = Profile .COMPATIBILITY ;
230+ } else if (value [0 ] == NSOpenGLProfileVersion4_1Core ) {
231+ data .majorVersion = 4 ;
232+ data .minorVersion = 1 ;
233+ data .profile = Profile .CORE ;
234+ }
235+
198236 pixelFormat .getValues (value , OS .NSOpenGLPFASampleBuffers , 0 );
199237 data .sampleBuffers = (int )value [0 ];
200238 pixelFormat .getValues (value , OS .NSOpenGLPFASamples , 0 );
0 commit comments