diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index bef26d45b..29ef0a482 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -959,7 +959,7 @@ public abstract class PGL { protected void saveFirstFrame() { firstFrame = allocateDirectIntBuffer(graphics.width * graphics.height); - readBuffer(BACK); + if (hasReadBuffer()) readBuffer(BACK); readPixelsImpl(0, 0, graphics.width, graphics.height, RGBA, UNSIGNED_BYTE, firstFrame); } @@ -2188,6 +2188,24 @@ public abstract class PGL { } + protected boolean hasReadBuffer() { + int[] version = getGLVersion(); + if (isES()) { + return version[0] >= 3; + } + return version[0] > 2; + } + + + protected boolean hasDrawBuffer() { + int[] version = getGLVersion(); + if (isES()) { + return version[0] >= 3; + } + return version[0] > 2; + } + + protected int maxSamples() { intBuffer.rewind(); getIntegerv(MAX_SAMPLES, intBuffer); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 7506da91c..02e0b7035 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -117,6 +117,8 @@ public class PGraphicsOpenGL extends PGraphics { static public boolean packedDepthStencilSupported; static public boolean anisoSamplingSupported; static public boolean blendEqSupported; + static public boolean readBufferSupported; + static public boolean drawBufferSupported; /** Some hardware limits */ static public int maxTextureSize; @@ -1682,7 +1684,7 @@ public class PGraphicsOpenGL extends PGraphics { FrameBuffer fb = getCurrentFB(); if (fb != null) { fb.bind(); - pgl.drawBuffer(fb.getDefaultDrawBuffer()); + if (drawBufferSupported) pgl.drawBuffer(fb.getDefaultDrawBuffer()); } } @@ -1757,9 +1759,9 @@ public class PGraphicsOpenGL extends PGraphics { // We read from/write to the draw buffer. if (op == OP_READ) { - pgl.readBuffer(getCurrentFB().getDefaultDrawBuffer()); + if (readBufferSupported) pgl.readBuffer(getCurrentFB().getDefaultDrawBuffer()); } else if (op == OP_WRITE) { - pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer()); + if (drawBufferSupported) pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer()); } pixelsOp = op; @@ -1774,8 +1776,8 @@ public class PGraphicsOpenGL extends PGraphics { } // Restoring default read/draw buffer configuration. - pgl.readBuffer(getCurrentFB().getDefaultReadBuffer()); - pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer()); + if (readBufferSupported) pgl.readBuffer(getCurrentFB().getDefaultReadBuffer()); + if (drawBufferSupported) pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer()); pixelsOp = OP_NONE; } @@ -6864,6 +6866,8 @@ public class PGraphicsOpenGL extends PGraphics { fboMultisampleSupported = pgl.hasFboMultisampleSupport(); packedDepthStencilSupported = pgl.hasPackedDepthStencilSupport(); anisoSamplingSupported = pgl.hasAnisoSamplingSupport(); + readBufferSupported = pgl.hasReadBuffer(); + drawBufferSupported = pgl.hasDrawBuffer(); try { pgl.blendEquation(PGL.FUNC_ADD); diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index a982996c2..5528f338d 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -295,7 +295,7 @@ public class PJOGL extends PGL { // https://www.opengl.org/wiki/Default_Framebuffer // so it is copied to the front texture of the FBO layer: if (pclearColor || 0 < pgeomCount || !sketch.isLooping()) { - readBuffer(FRONT); + if (hasReadBuffer()) readBuffer(FRONT); } else { // ...except when the previous frame has not been cleared and nothing was // rendered while looping. In this case the back buffer, which holds the @@ -306,7 +306,7 @@ public class PJOGL extends PGL { bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0)); framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D, glColorTex.get(frontTex), 0); - drawBuffer(COLOR_ATTACHMENT0); + if (hasDrawBuffer()) drawBuffer(COLOR_ATTACHMENT0); blitFramebuffer(0, 0, fboWidth, fboHeight, 0, 0, fboWidth, fboHeight, COLOR_BUFFER_BIT, NEAREST);