Skip to content

Commit ab1fd33

Browse files
committed
add flag to check whether draw/readBuffer() functions are available
1 parent 68397e8 commit ab1fd33

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ private void createFBOLayer() {
959959

960960
protected void saveFirstFrame() {
961961
firstFrame = allocateDirectIntBuffer(graphics.width * graphics.height);
962-
readBuffer(BACK);
962+
if (hasReadBuffer()) readBuffer(BACK);
963963
readPixelsImpl(0, 0, graphics.width, graphics.height, RGBA, UNSIGNED_BYTE, firstFrame);
964964
}
965965

@@ -2188,6 +2188,24 @@ protected boolean hasPBOs() {
21882188
}
21892189

21902190

2191+
protected boolean hasReadBuffer() {
2192+
int[] version = getGLVersion();
2193+
if (isES()) {
2194+
return version[0] >= 3;
2195+
}
2196+
return version[0] > 2;
2197+
}
2198+
2199+
2200+
protected boolean hasDrawBuffer() {
2201+
int[] version = getGLVersion();
2202+
if (isES()) {
2203+
return version[0] >= 3;
2204+
}
2205+
return version[0] > 2;
2206+
}
2207+
2208+
21912209
protected int maxSamples() {
21922210
intBuffer.rewind();
21932211
getIntegerv(MAX_SAMPLES, intBuffer);

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public class PGraphicsOpenGL extends PGraphics {
117117
static public boolean packedDepthStencilSupported;
118118
static public boolean anisoSamplingSupported;
119119
static public boolean blendEqSupported;
120+
static public boolean readBufferSupported;
121+
static public boolean drawBufferSupported;
120122

121123
/** Some hardware limits */
122124
static public int maxTextureSize;
@@ -1682,7 +1684,7 @@ protected void restoreGL() {
16821684
FrameBuffer fb = getCurrentFB();
16831685
if (fb != null) {
16841686
fb.bind();
1685-
pgl.drawBuffer(fb.getDefaultDrawBuffer());
1687+
if (drawBufferSupported) pgl.drawBuffer(fb.getDefaultDrawBuffer());
16861688
}
16871689
}
16881690

@@ -1757,9 +1759,9 @@ protected void beginPixelsOp(int op) {
17571759

17581760
// We read from/write to the draw buffer.
17591761
if (op == OP_READ) {
1760-
pgl.readBuffer(getCurrentFB().getDefaultDrawBuffer());
1762+
if (readBufferSupported) pgl.readBuffer(getCurrentFB().getDefaultDrawBuffer());
17611763
} else if (op == OP_WRITE) {
1762-
pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer());
1764+
if (drawBufferSupported) pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer());
17631765
}
17641766

17651767
pixelsOp = op;
@@ -1774,8 +1776,8 @@ protected void endPixelsOp() {
17741776
}
17751777

17761778
// Restoring default read/draw buffer configuration.
1777-
pgl.readBuffer(getCurrentFB().getDefaultReadBuffer());
1778-
pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer());
1779+
if (readBufferSupported) pgl.readBuffer(getCurrentFB().getDefaultReadBuffer());
1780+
if (drawBufferSupported) pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer());
17791781

17801782
pixelsOp = OP_NONE;
17811783
}
@@ -6864,6 +6866,8 @@ protected void getGLParameters() {
68646866
fboMultisampleSupported = pgl.hasFboMultisampleSupport();
68656867
packedDepthStencilSupported = pgl.hasPackedDepthStencilSupport();
68666868
anisoSamplingSupported = pgl.hasAnisoSamplingSupport();
6869+
readBufferSupported = pgl.hasReadBuffer();
6870+
drawBufferSupported = pgl.hasDrawBuffer();
68676871

68686872
try {
68696873
pgl.blendEquation(PGL.FUNC_ADD);

core/src/processing/opengl/PJOGL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ protected void initFBOLayer() {
295295
// https://www.opengl.org/wiki/Default_Framebuffer
296296
// so it is copied to the front texture of the FBO layer:
297297
if (pclearColor || 0 < pgeomCount || !sketch.isLooping()) {
298-
readBuffer(FRONT);
298+
if (hasReadBuffer()) readBuffer(FRONT);
299299
} else {
300300
// ...except when the previous frame has not been cleared and nothing was
301301
// rendered while looping. In this case the back buffer, which holds the
@@ -306,7 +306,7 @@ protected void initFBOLayer() {
306306
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
307307
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
308308
TEXTURE_2D, glColorTex.get(frontTex), 0);
309-
drawBuffer(COLOR_ATTACHMENT0);
309+
if (hasDrawBuffer()) drawBuffer(COLOR_ATTACHMENT0);
310310
blitFramebuffer(0, 0, fboWidth, fboHeight,
311311
0, 0, fboWidth, fboHeight,
312312
COLOR_BUFFER_BIT, NEAREST);

0 commit comments

Comments
 (0)