Advertisement

Strange glDrawBuffers behavior

Started by August 11, 2019 06:20 PM
3 comments, last by Green_Baron 5 years, 5 months ago

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

Spoiler
 
 
 
 
Spoiler

Screenshot_20190811_211803.thumb.png.85da496cb784fe3cc9f316a90980d9ee.pngScreenshot_20190811_211844.thumb.png.12c30a04db00108d10dfbec06ad66dc2.png

Why is this happening? Thank you in advance for your answers.

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.

Advertisement
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

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

This topic is closed to new replies.

Advertisement