Hello! Faced a strange problem when I decided to render the background (skybox) after rendering the scene. There are 4 textures attached to the framebuffer. First I fill them out when rendering the scene. After, I fill in the 0th and 2nd during the rendering of the skybox.
uint colorAttachment02[3] = { GL_COLOR_ATTACHMENT0, GL_NONE, GL_COLOR_ATTACHMENT2 };
uint colorAttachment0123[4] = {
GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3
};
...
glDrawBuffers(4, colorAttachment0123);
glUseProgram(cs.programId);
// sending lamps parameters to fragment shader
sendLampsData();
// drawing
for (size_t i = 0; i < MODELS_COUNT; i++) drawModel(models[i]);
for (size_t i = 0; i < POINT_LAMPS_COUNT + DIR_LAMPS_COUNT; i++) drawModel(lamps[i]);
// render skybox
glDepthFunc(GL_LEQUAL);
glDrawBuffers(3, colorAttachment02);
useShaderProgram(skyboxShader.programId);
glUniformMatrix3fv(skyboxShader.matView, 1, GL_FALSE, glm::value_ptr(glm::mat3(camera.getViewMatrix())));
setMat4(skyboxShader.matTransform, camera.getProjectionMatrix() * glm::mat4(glm::mat3(camera.getViewMatrix())));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox);
skyboxRenderer.render();
glDepthFunc(GL_LESS);
...
// another fbo...
The strange thing is that if do not reset to the initial buffers (that is, add the line glDrawBuffers(4, colorAttachment0123)), then with a sharp turn of the camera, something like the previous frame will be noticeable...
Why is this happening? Thank you in advance for your answers.