I'm trying to use framebuffer in OpenGL to get an output texture out of a shader and use it in another shader in order to achieve blur effect.
I followed these tutorials to add frame buffers in my project. http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/ http://opengles2learning.blogspot.com/2014/02/render-to-texture-rtt.html
As a result I have:
int[] temp = new int[1];
int FramebufferName = 0;
GLES20.glGenFramebuffers(1, temp, FramebufferName);
fboID = temp[0];
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, FramebufferName);
GLES20.glGenRenderbuffers(1, temp, FramebufferName);
int renderBufferId = temp[0];
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, FramebufferName);
GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, 1080, 1920);
GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER,
GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renderBufferId);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, newTextureID2, 0);
in the initialization.
and in OnDrawFrame method I have:
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboId);
GLES20.glViewport(0, 0, 1080, 1920);
But I get glError 1286 which is invalid frame buffer error. I think the problem maybe related to the texture not being power of 2. However my camera from ARCore returns 1080 x 1920. I'm getting the camera data as a bitmap by using glreadPixel. Is there a way to modify the dimension of the bitmap or the camera from ARCore?
EDIT: I actually checked for glerror after buffer initialization and I'm getting glError 1282. I'm not sure what's wrong now.
Achieved framebuffer by using render-to-texture instead of using Renderbuffer.
Here's my working framebuffer initialization:
mFrameBuffers = new int[1];
mFrameBufferTextures = new int[1];
GLES20.glGenFramebuffers(1, mFrameBuffers, 0);
GLES20.glGenTextures(1, mFrameBufferTextures, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mFrameBufferTextures[0]);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0,
GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[0]);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
GLES20.GL_TEXTURE_2D, mFrameBufferTextures[0], 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
Also this problem had nothing to do with ARCore. Hope this helps someone!