Skip to content
Closed
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
2 changes: 2 additions & 0 deletions core/src/processing/core/PSurface.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,6 @@ public interface PSurface {
public boolean stopThread();

public boolean isStopped();

public boolean isFboAllowed();
}
4 changes: 4 additions & 0 deletions core/src/processing/core/PSurfaceNone.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ public void setFrameRate(float fps) {
//g.setFrameRate(fps);
}

@Override
public boolean isFboAllowed() {
return true;
}

public class AnimationThread extends Thread {

Expand Down
5 changes: 5 additions & 0 deletions core/src/processing/javafx/PSurfaceFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,11 @@ public boolean isStopped() {
return animation.getStatus() == Animation.Status.STOPPED;
}

@Override
public boolean isFboAllowed() {
return true;
}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Expand Down
11 changes: 7 additions & 4 deletions core/src/processing/opengl/PGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,15 @@ protected void endRender(int windowColor) {
saveFirstFrame();
}

if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) {
enableFBOLayer();
if (SINGLE_BUFFERED) {
createFBOLayer();
if(sketch.getSurface().isFboAllowed()){
if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) {
enableFBOLayer();
if (SINGLE_BUFFERED) {
createFBOLayer();
}
}
}

}
}

Expand Down
71 changes: 71 additions & 0 deletions core/src/processing/opengl/PSurfaceJOGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package processing.opengl;

import java.awt.Component;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
Expand All @@ -35,6 +36,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -109,6 +111,26 @@ public class PSurfaceJOGL implements PSurface {

protected boolean external = false;

/**
* Defines if FBO Layer is allowed in the given environment.
* Using FBO can cause a fatal error during runtime for a
* specific environment, as strongly reported via
* <a href="https://github.com/processing/processing/issues/4104">GitHub</a>.
* The value remains as 'true' as long as the environment detected
* is different from those known by causing the issue.
*/
protected boolean fboAllowed = true;

/**
* Contains information about the environments on which FBO should NOT be used.
* Each position of the array contains a pair of {@link String}s correspondent to
* the operating system (based on {@link PConstants}) and the name of the
* hardware (based on sun.java2d.pipe.hw.ContextCapabilities#adapterId), respectively.
*/
final protected String[][] antiFboEnvironments = new String[][]{
{String.valueOf(PConstants.MACOSX), "Intel HD Graphics 3000"}
};

public PSurfaceJOGL(PGraphics graphics) {
this.graphics = graphics;
this.pgl = (PJOGL) ((PGraphicsOpenGL)graphics).pgl;
Expand Down Expand Up @@ -175,8 +197,57 @@ protected void initDisplay() {
}

displayRect = awtDisplayDevice.getDefaultConfiguration().getBounds();
initFboControl(awtDisplayDevice.getDefaultConfiguration());
}

/**
* Checks the host operating system and hardware against {@link #antiFboEnvironments},
* changing the value of {@link #fboAllowed} to 'false' if there is a pair of match.
* The current logic operates only with Mac, as a safety redundancy.
* If in future this resource must be used by other platforms, the main 'if' clause
* should be removed, allowing direct access to its inner logic.
*/
private void initFboControl(GraphicsConfiguration config) {
if (PApplet.platform == PApplet.MACOSX) {
try {
String adapterId = getAdapterId(config);
for (String[] pair : antiFboEnvironments) {
if (pair[0].equals(String.valueOf(PApplet.platform))) {
if (adapterId.toLowerCase().contains(pair[1].toLowerCase())) {
this.fboAllowed = false;
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

/**
* Evaluates the graphics configuration through reflection to safely get the adapter
* id from the hardware detected.
*
* @param config graphics configuration
* @return the name of the adapter id as a String
* @throws Exception when there is a problem with reflection
*/
private String getAdapterId(GraphicsConfiguration config) throws Exception {
Class cglClass = Class.forName("sun.java2d.opengl.CGLGraphicsConfig");
Class ctcClass = Class.forName("sun.java2d.pipe.hw.ContextCapabilities");
Method cglMethod = cglClass.getMethod("getContextCapabilities");
Method ctcMethod = ctcClass.getMethod("getAdapterId");
Object cglInstance = cglClass.cast(config);
Object ctcInstance = cglMethod.invoke(cglInstance);
Object idInstance = ctcMethod.invoke(ctcInstance);
return String.valueOf(idInstance);
}

@Override
public boolean isFboAllowed(){
return this.fboAllowed;
}

protected void initGL() {
// System.out.println("*******************************");
Expand Down