Skip to content

Commit

Permalink
Drop glClear() to preserve pixel buffer
Browse files Browse the repository at this point in the history
According to the OpenGL ES specification, using the discard keyword
should not update the buffer. So glClear() needs to be dropped because
it clears the buffer between renders.
  • Loading branch information
markusfisch committed Jan 4, 2016
1 parent 531e8e7 commit bba8c4e
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,18 @@ public void onDrawFrame( GL10 gl )
(float)level/scale );
}

if( fb[0] == 0 )
createTargets(
(int)resolution[0],
(int)resolution[1] );

// first draw custom shader in framebuffer
GLES20.glViewport(
0,
0,
(int)resolution[0],
(int)resolution[1] );

if( fb[0] == 0 )
createTargets(
(int)resolution[0],
(int)resolution[1] );

if( backBufferLoc > -1 )
{
GLES20.glUniform1i(
Expand All @@ -322,13 +323,12 @@ public void onDrawFrame( GL10 gl )
GLES20.GL_FRAMEBUFFER,
fb[frontTarget] );

GLES20.glClear(
GLES20.GL_COLOR_BUFFER_BIT );
GLES20.glDrawArrays(
GLES20.GL_TRIANGLE_STRIP,
0,
4 );

// then draw framebuffer on screen
GLES20.glBindFramebuffer(
GLES20.GL_FRAMEBUFFER,
0 );
Expand Down Expand Up @@ -664,8 +664,8 @@ private void createTargets( int width, int height )
createTarget( frontTarget, width, height );
createTarget( backTarget, width, height );

// unbind textures that were bound in createTarget()
GLES20.glBindTexture( GLES20.GL_TEXTURE_2D, 0 );
GLES20.glBindFramebuffer( GLES20.GL_FRAMEBUFFER, 0 );
}

private void createTarget( int idx, int width, int height )
Expand Down

0 comments on commit bba8c4e

Please sign in to comment.