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?
- Bind texture that used as collor attachment on source frame buffer
- Bind destination framebuffer
- Draw full screen quad (if you need stretch or offseted reading manipulate with vertex/tex coordinates)
- Fetch data from bound texture in frament shader and put it to gl_FragColor
Answer:
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.
Tags: androidandroid, opengl