12

My Android program must use glBlitFrameBuffer() function to copy FrameBuffer object. But glBlitFrameBuffer() function is only supported on OpenGL ES 3.0+ devices. I want to support OpenGL ES 2.0+ devices.

Is there any solution/alternative for this function?

genpfault
  • 51,148
  • 11
  • 85
  • 139
nguoitotkhomaisao
  • 1,247
  • 1
  • 13
  • 24

2 Answers2

2
  1. Bind texture that used as collor attachment on source frame buffer
  2. Bind destination framebuffer
  3. Draw full screen quad (if you need stretch or offseted reading manipulate with vertex/tex coordinates)
  4. Fetch data from bound texture in frament shader and put it to gl_FragColor
ivaigult
  • 6,198
  • 5
  • 38
  • 66
0

I've created a CopyShader that simply uses a shader to copy from a texture to a framebuffer.

private static final String SHADER_VERTEX = ""
      + "attribute vec4 a_Position;\n"
      + "varying highp vec2 v_TexCoordinate;\n"
      + "void main() {\n"
      + "  v_TexCoordinate = a_Position.xy * 0.5 + 0.5;\n"
      + "  gl_Position = a_Position;\n"
      + "}\n";

  private static final String SHADER_FRAGMENT = ""
      + ""
      + "uniform sampler2D u_Texture;\n"
      + "varying highp vec2 v_TexCoordinate;\n"
      + "void main() {\n"
      + "  gl_FragColor = texture2D(u_Texture, v_TexCoordinate);\n"
      + "}\n”;

Use these as your shaders, and then just set u_Texture to the texture you want to copy from, and bind the framebuffer you want to write to, and you should be set.

rharter
  • 2,495
  • 18
  • 34