Skip to content
Open
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 NSOpenGLProfileVersionLegacy = 0x1000;
static final int NSOpenGLProfileVersion3_2Core = 0x3200;
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,17 @@ public GLCanvas (Composite parent, int style, GLData data) {
attrib [pos++] = data.stencilSize;
}

if (data.profile == Profile.LEGACY) {
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;
}
Comment on lines +90 to +99

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Would there be a down side to making legacy the default even in circumstances where nothing is specified? And requiring an explicit Profile.CORE in addition to the version numbers? IOW,

Suggested change
if (data.profile == Profile.LEGACY) {
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;
}
if (data.profile == Profile.CORE) {
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;
}
} else {
attrib[pos++] = NSOpenGLPFAOpenGLProfile;
attrib[pos++] = NSOpenGLProfileVersionLegacy;
}

(Then you wouldn't technically even need Profile.LEGACY, except to have a value other than Profile.CORE that can be stuck in data.profile. But just not setting it would get you the same thing, so it doesn't have to be explicit.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But overall it looks workable to me as-is, too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it might be good that it works exactly like before if you don't specify anything.


/*
* 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 +211,19 @@ public GLData getGLData () {
data.accumBlueSize = accumColorSize;
data.accumAlphaSize = accumColorSize;

pixelFormat.getValues(value, NSOpenGLPFAOpenGLProfile, 0);
if (value[0] == NSOpenGLProfileVersionLegacy) {
data.profile = Profile.LEGACY;
} else if (value[0] == NSOpenGLProfileVersion3_2Core) {
data.majorVersion = 3;
data.minorVersion = 2;
data.profile = Profile.CORE;
} 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, LEGACY;
}

/**
* 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 GL profile to use, {@link Profile#CORE} is only valid when
* ({@link #majorVersion}.{@link #minorVersion}) is at least 3.0.
*/
public Profile profile;
Comment on lines +153 to +157

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment here is technically no longer correct, since LEGACY is one of the enum members and that's used to signal a version less than 3.0.

Profile.CORE is only valid when ({@link #majorVersion}.{@link #minorVersion}) is at least 3.0.


/**
* 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;
}
}
Loading