Alternative for glBlitFrameBuffer() in OpenGL ES 2.0
Asked Answered
C

2

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?

Cortneycorty answered 22/8, 2014 at 3:34 Comment(0)
O
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
Ovida answered 24/8, 2014 at 13:13 Comment(0)
P
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.

Preinstruct answered 8/1, 2016 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.