diff --git a/bundles/org.eclipse.swt/Eclipse SWT OpenGL/cocoa/org/eclipse/swt/opengl/GLCanvas.java b/bundles/org.eclipse.swt/Eclipse SWT OpenGL/cocoa/org/eclipse/swt/opengl/GLCanvas.java index e5a11132cce..5c24f7d02c9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT OpenGL/cocoa/org/eclipse/swt/opengl/GLCanvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OpenGL/cocoa/org/eclipse/swt/opengl/GLCanvas.java @@ -34,6 +34,11 @@ public class GLCanvas extends Canvas { static final int MAX_ATTRIBUTES = 32; static final String GLCONTEXT_KEY = "org.eclipse.swt.internal.cocoa.glcontext"; //$NON-NLS-1$ + static final int NSOpenGLPFAOpenGLProfile = 99; + static final int NSOpenGLProfileVersion3_2Core = 0x3200; + static final int NSOpenGLProfileVersionLegacy = 0x1000; + static final int NSOpenGLProfileVersion4_1Core = 0x4100; + /** * Create a GLCanvas widget using the attributes described in the GLData * object provided. @@ -82,6 +87,26 @@ public GLCanvas (Composite parent, int style, GLData data) { attrib [pos++] = data.stencilSize; } + if (data.profile == Profile.CORE) { + attrib[pos++] = NSOpenGLPFAOpenGLProfile; + attrib[pos++] = NSOpenGLProfileVersion3_2Core; + } + if (data.profile == Profile.COMPATIBILITY) { + attrib[pos++] = NSOpenGLPFAOpenGLProfile; + attrib[pos++] = NSOpenGLProfileVersionLegacy; + } else { + if (data.majorVersion >= 4) { + attrib[pos++] = NSOpenGLPFAOpenGLProfile; + attrib[pos++] = NSOpenGLProfileVersion4_1Core; + } else if (data.majorVersion >= 3) { + attrib[pos++] = NSOpenGLPFAOpenGLProfile; + attrib[pos++] = NSOpenGLProfileVersion3_2Core; + } else { + attrib[pos++] = NSOpenGLPFAOpenGLProfile; + attrib[pos++] = NSOpenGLProfileVersionLegacy; + } + } + /* * Feature in Cocoa: NSOpenGL/CoreOpenGL only supports specifying the total number of bits * 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 () { data.accumBlueSize = accumColorSize; data.accumAlphaSize = accumColorSize; + pixelFormat.getValues(value, NSOpenGLPFAOpenGLProfile, 0); + if (value[0] == NSOpenGLProfileVersion3_2Core) { + data.majorVersion = 3; + data.minorVersion = 2; + data.profile = Profile.CORE; + } else if (value[0] == NSOpenGLProfileVersionLegacy) { + data.profile = Profile.COMPATIBILITY; + } else if (value[0] == NSOpenGLProfileVersion4_1Core) { + data.majorVersion = 4; + data.minorVersion = 1; + data.profile = Profile.CORE; + } + pixelFormat.getValues(value, OS.NSOpenGLPFASampleBuffers, 0); data.sampleBuffers = (int)value [0]; pixelFormat.getValues(value, OS.NSOpenGLPFASamples, 0); diff --git a/bundles/org.eclipse.swt/Eclipse SWT OpenGL/common/org/eclipse/swt/opengl/GLData.java b/bundles/org.eclipse.swt/Eclipse SWT OpenGL/common/org/eclipse/swt/opengl/GLData.java index 041218a4efb..89eee4a0b96 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT OpenGL/common/org/eclipse/swt/opengl/GLData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OpenGL/common/org/eclipse/swt/opengl/GLData.java @@ -25,6 +25,11 @@ */ public class GLData { + + public static enum Profile { + CORE, COMPATIBILITY; + } + /** * Specifies a double-buffered surface. During context * creation, only double-buffered formats are considered @@ -133,6 +138,24 @@ public class GLData { */ public GLCanvas shareContext; + /** + * The major GL context version to use. It defaults to 0 for + * "not specified". + */ + public int majorVersion; + + /** + * The minor GL context version to use. If {@link #majorVersion} + * is 0 this field is unused. + */ + public int minorVersion; + + /** + * The profile to use. This is only valid when + * ({@link #majorVersion}.{@link #minorVersion}) is at least 3.0. + */ + public Profile profile; + /** * Returns a string containing a concise, human-readable * description of the receiver. @@ -146,6 +169,7 @@ public String toString() { "r:" + redSize + " g:" + greenSize + " b:" + blueSize + " a:" + alphaSize + "," + "depth:" + depthSize + ",stencil:" + stencilSize + ",accum r:" + accumRedSize + "g:" + accumGreenSize + "b:" + accumBlueSize + "a:" + accumAlphaSize + - ",sampleBuffers:" + sampleBuffers + ",samples:" + samples; + ",sampleBuffers:" + sampleBuffers + ",samples:" + samples + + ",majorVersion:" + majorVersion + ",minorVersion:" + minorVersion + ",profile:" + profile; } }