0

In OpenGL ES, is it possible to call glReadPixels and glDrawArrays on a FBO several times one after the other? The issue I'm facing is that I'm getting the image all garbled.

Sample Code:

// Activate Off-Screen FBO
glBindFramebuffer(GL_FRAMEBUFFER, fboHandle);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textureHandle);
glViewport(0, 0, 640, 480);

// 1st Render
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(filter_A);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640, 480, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgb_pixels_A);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glReadPixels(0, 0, 640, 480, GL_RGBA, GL_UNSIGNED_BYTE, pixels_A);

// 2st Render
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(filter_B);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640, 480, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgb_pixels_B);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glReadPixels(0, 0, 640, 480, GL_RGBA, GL_UNSIGNED_BYTE, pixels_B);

// Back to the screen FB
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glActiveTexture(GL_TEXTURE0);
Christian Rau
  • 45,360
  • 10
  • 108
  • 185
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127

1 Answers1

0

A call to eglSwapBuffers() is required between rendering with glDrawArrays() and reading with glReadPixels(). This is because most OpenGL ES GPUs do tile-based deferred rendering. This article should help:

http://processors.wiki.ti.com/index.php/Render_to_Texture_with_OpenGL_ES

ClayMontgomery
  • 2,786
  • 1
  • 15
  • 14