Skip to content

Commit cc39c94

Browse files
committed
fix for #50, alternate solution but based on #75
1 parent 5a2705c commit cc39c94

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ public abstract class PGL {
170170
* Using FBO can cause a fatal error during runtime for
171171
* Intel HD Graphics 3000 chipsets (commonly used on older MacBooks)
172172
* <a href="https://github.com/processing/processing/issues/4104">#4104</a>
173-
* The value remains as 'true' unless set false during init.
174-
* TODO There's already code in here to enable/disable the FBO properly,
175-
* this should be making use of that mechanism instead. [fry 191007]
173+
* Changed to private because needs to be accessed via isFboAllowed().
174+
* <a href="https://github.com/processing/processing4/pull/76">#76</a> and
175+
* <a href="https://github.com/processing/processing4/issues/50">#50</a>
176176
*/
177-
protected boolean fboAllowed = true;
177+
private Boolean fboAllowed = true;
178178

179179
// ........................................................
180180

@@ -863,7 +863,7 @@ protected void endRender(int windowColor) {
863863
saveFirstFrame();
864864
}
865865

866-
if (fboAllowed) {
866+
if (isFboAllowed()) {
867867
if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) {
868868
enableFBOLayer();
869869
if (SINGLE_BUFFERED) {
@@ -2304,6 +2304,28 @@ protected int getMaxTexUnits() {
23042304
}
23052305

23062306

2307+
public boolean isFboAllowed() {
2308+
if (fboAllowed == null) {
2309+
if (PApplet.platform == PConstants.MACOS) {
2310+
try {
2311+
String hardware = getString(PGL.RENDERER);
2312+
if (hardware != null && hardware.contains("Intel HD Graphics 3000")) {
2313+
fboAllowed = false;
2314+
return false;
2315+
}
2316+
} catch (RuntimeException e) {
2317+
System.err.println("Could not read renderer name. FBOs disabled. Reason: " + e);
2318+
// disable for now, but will try again on next isFboAllowed() call
2319+
return false;
2320+
}
2321+
}
2322+
// all other scenarios allow for FBOs
2323+
fboAllowed = true;
2324+
}
2325+
return fboAllowed;
2326+
}
2327+
2328+
23072329
protected static ByteBuffer allocateDirectByteBuffer(int size) {
23082330
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_BYTE;
23092331
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder());

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.io.FileInputStream;
3939
import java.io.IOException;
4040
import java.io.InputStream;
41-
import java.lang.reflect.Method;
4241
import java.nio.ByteBuffer;
4342
import java.util.HashMap;
4443
import java.util.Map;
@@ -255,22 +254,6 @@ protected void initDisplay() {
255254

256255
GraphicsConfiguration config = awtDisplayDevice.getDefaultConfiguration();
257256
displayRect = config.getBounds();
258-
259-
/** See explanation at {@link PGL#fboAllowed} in PGL */
260-
if (PApplet.platform == PConstants.MACOS) {
261-
try {
262-
Class<?> cglClass = Class.forName("sun.java2d.opengl.CGLGraphicsConfig");
263-
Method cglMethod = cglClass.getMethod("getContextCapabilities");
264-
Class<?> ctcClass = Class.forName("sun.java2d.pipe.hw.ContextCapabilities");
265-
Method ctcMethod = ctcClass.getMethod("getAdapterId");
266-
Object cglInstance = cglClass.cast(config);
267-
Object ctcInstance = cglMethod.invoke(cglInstance);
268-
Object idInstance = ctcMethod.invoke(ctcInstance);
269-
if (String.valueOf(idInstance).contains("Intel HD Graphics 3000")) {
270-
pgl.fboAllowed = false;
271-
}
272-
} catch (Exception e) { }
273-
}
274257
}
275258

276259

todo.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ X https://github.com/processing/processing4/pull/96
2424
X Debug button in the toolbar is currently broken
2525
X https://github.com/processing/processing4/issues/94
2626
X https://github.com/processing/processing4/pull/95
27-
27+
X Fix WARNING: Illegal reflective access by processing.opengl.PSurfaceJOGL” on getContextCapabilities()
28+
X https://github.com/processing/processing4/issues/50
29+
X https://github.com/processing/processing4/pull/76
2830

2931
before final release
3032
_ Update graphics and visual design elements for 4.x

0 commit comments

Comments
 (0)