When I’m attaching a texture or detaching the previous one the detached texture is reset to zero. Strictly speaking there are not only zero values. There are some garbage values too. Is it Ok? I can’t find anything about it in opengl reference.
//pseudocode:
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 1);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 1, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glReadBuffer(GL_NONE);
GLenum fbStatus = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
glViewport(0, 0, WIDTH, HEIGHT);
glClear(GL_COLOR_BUFFER_BIT);
… do rendering here … // no the texture #1 contains the proper result
// If I uncomment one of the following lines then the texture #1 will be reset.
// glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); // detaching the texture
// glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 2, 0); // attaching another texture