Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -82,6 +87,20 @@ public GLCanvas (Composite parent, int style, GLData data) {
attrib [pos++] = data.stencilSize;
}

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 || data.profile == Profile.CORE) {
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,
Expand Down Expand Up @@ -195,6 +214,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}
}