add flag to check whether draw/readBuffer() functions are available

This commit is contained in:
codeanticode
2015-10-12 16:58:18 +01:00
parent ac7e037bec
commit 6444ee35dc
3 changed files with 30 additions and 8 deletions
+19 -1
View File
@@ -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);
@@ -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);
+2 -2
View File
@@ -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);