Skip to content

Commit d234c01

Browse files
committed
#2490 Added version and profile information to GLData, MacOS uses this to request a specific GL version.
1 parent 108533e commit d234c01

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

  • bundles/org.eclipse.swt/Eclipse SWT OpenGL

bundles/org.eclipse.swt/Eclipse SWT OpenGL/cocoa/org/eclipse/swt/opengl/GLCanvas.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

bundles/org.eclipse.swt/Eclipse SWT OpenGL/common/org/eclipse/swt/opengl/GLData.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
*/
2626

2727
public class GLData {
28+
29+
public static enum Profile {
30+
CORE, COMPATIBILITY;
31+
}
32+
2833
/**
2934
* Specifies a double-buffered surface. During context
3035
* creation, only double-buffered formats are considered
@@ -133,6 +138,24 @@ public class GLData {
133138
*/
134139
public GLCanvas shareContext;
135140

141+
/**
142+
* The major GL context version to use. It defaults to 0 for
143+
* "not specified".
144+
*/
145+
public int majorVersion;
146+
147+
/**
148+
* The minor GL context version to use. If {@link #majorVersion}
149+
* is 0 this field is unused.
150+
*/
151+
public int minorVersion;
152+
153+
/**
154+
* The profile to use. This is only valid when
155+
* ({@link #majorVersion}.{@link #minorVersion}) is at least 3.0.
156+
*/
157+
public Profile profile;
158+
136159
/**
137160
* Returns a string containing a concise, human-readable
138161
* description of the receiver.
@@ -146,6 +169,7 @@ public String toString() {
146169
"r:" + redSize + " g:" + greenSize + " b:" + blueSize + " a:" + alphaSize + "," +
147170
"depth:" + depthSize + ",stencil:" + stencilSize +
148171
",accum r:" + accumRedSize + "g:" + accumGreenSize + "b:" + accumBlueSize + "a:" + accumAlphaSize +
149-
",sampleBuffers:" + sampleBuffers + ",samples:" + samples;
172+
",sampleBuffers:" + sampleBuffers + ",samples:" + samples +
173+
",majorVersion:" + majorVersion + ",minorVersion:" + minorVersion + ",profile:" + profile;
150174
}
151175
}

0 commit comments

Comments
 (0)