OpenGL Strange glDrawBuffers behavior

Recommended Posts

Posted (edited)

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);
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...

Spoiler

Spoiler

Edited by congard

Share on other sites

Hard to tell with that little info. To me it looks like you're simply not clearing a buffer correctly, most likely the one for the lighting.

Share on other sites
50 minutes ago, Magogan said:

Hard to tell with that little info. To me it looks like you're simply not clearing a buffer correctly, most likely the one for the lighting.

The strange thing is that if I render the skybox before the scene, then this will not happen

Share on other sites

My bet is on not clearing (all the attachments) too. The Skybox overwrites the whole buffer, i assume.

Create an account

Register a new account

• 9
• 12
• 15
• 12
• 24