I'm trying to copy a texture into another using 'glBlitFramebuffer', I'm working on the classic open gl example hello-gl2 from android ndk-samples. I changed the shaders to support texture and i can correctly render a textured triangle. I also changed the opengl es version requested on the java side so to request opengl-es3 and i updated the Cmakelists file to link the right library. After calling glBlitFramebuffer(0,0,tw, th, 0, 0, tw, th, GL_COLOR_BUFFER_BIT, GL_LINEAR); i get the after blitTexture glBlitFramebuffer() glError (0x502) error. What is the root cause for that?
Code I use:
To generate the textures:
void createTexture(GLuint &tex, int width, int height, int r){
    int rowlen = width * 3;
    unsigned char buf[width*3*height];
    for (int i=0; i<rowlen; i+=3)
        for (int j=0; j<height; j++) {
            int col = ((int (i/(3*r))) + (int (j/r)))%2;
            buf[i+j*rowlen] = buf[i+1+j*rowlen] = buf[i+2+j*rowlen] = col * 255;
        }
    glGenTextures(1, &tex);
    glBindTexture(GL_TEXTURE_2D, tex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buf);
    // set the texture wrapping/filtering options (on the currently bound texture object)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    LOGI("DEBUG C++ Texture created [%d]", tex);
}
to setup the framebuffer:
bool SetupFramebuffer(GLuint tex, int width, int height)
{
    if (fb == 0)
    {
        glGenFramebuffers(1, &fb);
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb);
        glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                               GL_TEXTURE_2D, tex, 0);
        GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
        if (status != GL_FRAMEBUFFER_COMPLETE)
        {
            LOGE("Incomplete frame buffer object!");
            return false;
        }
        LOGI("Created FBO %d for texture %d.",
             fb, tex);
    }
    return true;
}
to build the array of textures inside the setupGraphics function:
    createTexture(tex, tw, th, 6);
    for (int i = 0; i<25; i++) createTexture(aniTex[i], tw, th, 3+i);
    SetupFramebuffer(tex, tw, th);
and finally to blit the framebuffer:
const GLenum attachment[1] = { GL_COLOR_ATTACHMENT0 };
void blitTexture() {
    static int time = 0;
    glBindFramebuffer(GL_FRAMEBUFFER, fb);
    checkGlError("blitTexture glBindFramebuffer");
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
                           GL_TEXTURE_2D, aniTex[time], 0);
    checkGlError("blitTexture glFramebufferTexture2D");
    glReadBuffer(GL_COLOR_ATTACHMENT1);
    checkGlError("blitTexture glReadBuffer");
    glDrawBuffers(1, attachment);
    checkGlError("blitTexture glDrawBuffers");
    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE) LOGE("Incomplete frame buffer object!");
    glBlitFramebuffer(0,0,tw, th, 0, 0, tw, th, GL_COLOR_BUFFER_BIT, GL_LINEAR);
    checkGlError("blitTexture glBlitFramebuffer");
    int samples;
    glGetFramebufferParameteriv(GL_READ_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, &samples);
    LOGI("SAMPLES draw buffer %d", samples);
    time = ++time%25;
}
full project can be found here: https://github.com/AndrewBloom/BlitFramebufferExample