nguoitotkhomaisao
nguoitotkhomaisao

Reputation: 1245

Alternative for glBlitFrameBuffer() in OpenGL ES 2.0

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?

Upvotes: 12

Views: 3984

Answers (2)

rharter
rharter

Reputation: 2495

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.

Upvotes: 0

ivaigult
ivaigult

Reputation: 6667

  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

Upvotes: 2

Related Questions