Skip to content

Commit 9d819b8

Browse files
committed
don't use blitFramebuffer to initialize FBO layer
1 parent a29daed commit 9d819b8

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

core/src/processing/opengl/PGL.java

+2-35
Original file line numberDiff line numberDiff line change
@@ -923,45 +923,12 @@ private void createFBOLayer() {
923923
clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT);
924924

925925
bindFramebufferImpl(FRAMEBUFFER, 0);
926-
927-
if (0 < sketch.frameCount) {
928-
// Copy the contents of the front and back screen buffers to the textures
929-
// of the FBO, so they are properly initialized. Note that the front buffer
930-
// of the default framebuffer (the screen) contains the previous frame:
931-
// https://www.opengl.org/wiki/Default_Framebuffer
932-
// so it is copied to the front texture of the FBO layer:
933-
if (pclearColor || 0 < pgeomCount || !sketch.isLooping()) {
934-
readBuffer(FRONT);
935-
} else {
936-
// ...except when the previous frame has not been cleared and nothing was
937-
// renderered while looping. In this case the back buffer, which holds the
938-
// initial state of the previous frame, still contains the most up-to-date
939-
// screen state.
940-
readBuffer(BACK);
941-
}
942-
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
943-
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
944-
TEXTURE_2D, glColorTex.get(frontTex), 0);
945-
drawBuffer(COLOR_ATTACHMENT0);
946-
blitFramebuffer(0, 0, fboWidth, fboHeight,
947-
0, 0, fboWidth, fboHeight,
948-
COLOR_BUFFER_BIT, NEAREST);
949-
950-
readBuffer(BACK);
951-
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
952-
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
953-
TEXTURE_2D, glColorTex.get(backTex), 0);
954-
drawBuffer(COLOR_ATTACHMENT0);
955-
blitFramebuffer(0, 0, fboWidth, fboHeight,
956-
0, 0, fboWidth, fboHeight,
957-
COLOR_BUFFER_BIT, NEAREST);
958-
959-
bindFramebufferImpl(FRAMEBUFFER, 0);
960-
}
926+
initFBOLayer();
961927

962928
fboLayerCreated = true;
963929
}
964930

931+
protected abstract void initFBOLayer();
965932

966933
protected void destroyFBOLayer() {
967934
if (threadIsCurrent() && fboLayerCreated) {

core/src/processing/opengl/PGLES.java

+35
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,41 @@ protected int getGLSLVersion() {
227227
}
228228

229229

230+
@Override
231+
protected void initFBOLayer() {
232+
if (0 < sketch.frameCount) {
233+
IntBuffer buf = null;
234+
buf = allocateDirectIntBuffer(fboWidth * fboHeight);
235+
236+
// Copy the contents of the front and back screen buffers to the textures
237+
// of the FBO, so they are properly initialized. Note that the front buffer
238+
// of the default framebuffer (the screen) contains the previous frame:
239+
// https://www.opengl.org/wiki/Default_Framebuffer
240+
// so it is copied to the front texture of the FBO layer:
241+
if (pclearColor || 0 < pgeomCount || !sketch.isLooping()) {
242+
readBuffer(FRONT);
243+
} else {
244+
// ...except when the previous frame has not been cleared and nothing was
245+
// renderered while looping. In this case the back buffer, which holds the
246+
// initial state of the previous frame, still contains the most up-to-date
247+
// screen state.
248+
readBuffer(BACK);
249+
}
250+
readPixelsImpl(0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
251+
bindTexture(TEXTURE_2D, glColorTex.get(frontTex));
252+
texSubImage2D(TEXTURE_2D, 0, 0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
253+
254+
readBuffer(BACK);
255+
readPixelsImpl(0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
256+
bindTexture(TEXTURE_2D, glColorTex.get(backTex));
257+
texSubImage2D(TEXTURE_2D, 0, 0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
258+
259+
bindTexture(TEXTURE_2D, 0);
260+
bindFramebufferImpl(FRAMEBUFFER, 0);
261+
}
262+
}
263+
264+
230265
///////////////////////////////////////////////////////////
231266

232267
// Android specific classes (Renderer, ConfigChooser)

0 commit comments

Comments
 (0)