Skip to content

Commit 9dee44e

Browse files
committed
implement GLES path for FBO layer init
1 parent a993804 commit 9dee44e

File tree

1 file changed

+52
-30
lines changed

1 file changed

+52
-30
lines changed

core/src/processing/opengl/PJOGL.java

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -289,39 +289,61 @@ protected void swapBuffers() {
289289
@Override
290290
protected void initFBOLayer() {
291291
if (0 < sketch.frameCount) {
292-
// Copy the contents of the front and back screen buffers to the textures
293-
// of the FBO, so they are properly initialized. Note that the front buffer
294-
// of the default framebuffer (the screen) contains the previous frame:
295-
// https://www.opengl.org/wiki/Default_Framebuffer
296-
// so it is copied to the front texture of the FBO layer:
297-
if (pclearColor || 0 < pgeomCount || !sketch.isLooping()) {
298-
if (hasReadBuffer()) readBuffer(FRONT);
299-
} else {
300-
// ...except when the previous frame has not been cleared and nothing was
301-
// rendered while looping. In this case the back buffer, which holds the
302-
// initial state of the previous frame, still contains the most up-to-date
303-
// screen state.
304-
readBuffer(BACK);
305-
}
306-
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
307-
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
308-
TEXTURE_2D, glColorTex.get(frontTex), 0);
309-
if (hasDrawBuffer()) drawBuffer(COLOR_ATTACHMENT0);
310-
blitFramebuffer(0, 0, fboWidth, fboHeight,
311-
0, 0, fboWidth, fboHeight,
312-
COLOR_BUFFER_BIT, NEAREST);
292+
if (isES()) initFBOLayerES();
293+
else initFBOLayerGL();
294+
}
295+
}
296+
297+
298+
private void initFBOLayerES() {
299+
IntBuffer buf = allocateDirectIntBuffer(fboWidth * fboHeight);
313300

301+
if (hasReadBuffer()) readBuffer(BACK);
302+
readPixelsImpl(0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
303+
bindTexture(TEXTURE_2D, glColorTex.get(frontTex));
304+
texSubImage2D(TEXTURE_2D, 0, 0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
305+
306+
bindTexture(TEXTURE_2D, glColorTex.get(backTex));
307+
texSubImage2D(TEXTURE_2D, 0, 0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
308+
309+
bindTexture(TEXTURE_2D, 0);
310+
bindFramebufferImpl(FRAMEBUFFER, 0);
311+
}
312+
313+
314+
private void initFBOLayerGL() {
315+
// Copy the contents of the front and back screen buffers to the textures
316+
// of the FBO, so they are properly initialized. Note that the front buffer
317+
// of the default framebuffer (the screen) contains the previous frame:
318+
// https://www.opengl.org/wiki/Default_Framebuffer
319+
// so it is copied to the front texture of the FBO layer:
320+
if (pclearColor || 0 < pgeomCount || !sketch.isLooping()) {
321+
if (hasReadBuffer()) readBuffer(FRONT);
322+
} else {
323+
// ...except when the previous frame has not been cleared and nothing was
324+
// rendered while looping. In this case the back buffer, which holds the
325+
// initial state of the previous frame, still contains the most up-to-date
326+
// screen state.
314327
readBuffer(BACK);
315-
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
316-
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
317-
TEXTURE_2D, glColorTex.get(backTex), 0);
318-
drawBuffer(COLOR_ATTACHMENT0);
319-
blitFramebuffer(0, 0, fboWidth, fboHeight,
320-
0, 0, fboWidth, fboHeight,
321-
COLOR_BUFFER_BIT, NEAREST);
322-
323-
bindFramebufferImpl(FRAMEBUFFER, 0);
324328
}
329+
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
330+
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
331+
TEXTURE_2D, glColorTex.get(frontTex), 0);
332+
if (hasDrawBuffer()) drawBuffer(COLOR_ATTACHMENT0);
333+
blitFramebuffer(0, 0, fboWidth, fboHeight,
334+
0, 0, fboWidth, fboHeight,
335+
COLOR_BUFFER_BIT, NEAREST);
336+
337+
readBuffer(BACK);
338+
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
339+
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
340+
TEXTURE_2D, glColorTex.get(backTex), 0);
341+
drawBuffer(COLOR_ATTACHMENT0);
342+
blitFramebuffer(0, 0, fboWidth, fboHeight,
343+
0, 0, fboWidth, fboHeight,
344+
COLOR_BUFFER_BIT, NEAREST);
345+
346+
bindFramebufferImpl(FRAMEBUFFER, 0);
325347
}
326348

327349

0 commit comments

Comments
 (0)