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,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;
}
}

Comment on lines +90 to +109
Copy link
Copy Markdown

@ferdnyc ferdnyc May 7, 2026

Choose a reason for hiding this comment

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

If data.profile == Profile.CORE, you're going to end up adding two profile attribute pairs to the array.

  1. First on lines 91-92, you'll add this pair:
    • (NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core)
  2. Then when the test at line 94 fails you'll take the else path at line 97, and depending what data.majorVersion contains, you'll also add one of these three pairs:
    • (NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core)
    • (NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core) (again!)
    • (NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy)

That doesn't seem like what you'd want. Should line 94 be an else if? Or does the logic here need to be more robust? (The code starting at line 223 makes it seem like Profile.CORE should only be used with numbered versions, and Profile.COMPATIBILITY should be 1:1 with VersionLegacy, but that's not at all what the code here does.)

And then the comments even farther down claim that Profile is only valid if the major+minor version is at least 3.0. Meaning Profile.COMPATIBILITY is never actually a valid profile, because it's used when the version is "Legacy" (which seems implicitly to mean "less than 3.0")?

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