Hi!
SOLVED: For anyone stumbling onto this issue. When you are using glDrawBuffers() and using a call to glDrawBuffer() you are overwriting your glDrawBuffers() state. It needs to be reset to its orignal glDrawBuffers() state.
I am wondering if someone can help me out.
I have 2 FBOs + MRT and they have identical attachments(4 color attachments each). using glBlitFrameBuffer works as expected for the depth buffer and for one color_attachment. However, when i blit multiple color attachments, things go bad. I have done a lot of research and tried a lot of different methods, none works. I am not using renderBufferStorage because my textures have different internalFormats(RGBA and RGB16F). This sounds like the same problem, except i am not using multisampling, only MRT.
OpenGL version 4.3
Why: I want to create a state of the terrain pre- lighting calculations so that i only need to render the terrain if there are changes(ie. camera movement). This is for deferred shading→ another deferred renderer which combines these FBO's and then runs through the lighting pass.
At first i expected that i should use glDrawBuffers which i am using in the initial setup, but there is no glReadBuffers and therefore i am assuming i have no way to link them. I might be wrong here, not an expert yet ?
//CODE
//FBO - Original code writting in Golang, should be easily tranferable to C++(will translate if requested)
gl.GenFramebuffers(1, &gb.ID)
gl.BindFramebuffer(gl.FRAMEBUFFER, gb.ID)
//setting up color attachments
gl.GenTextures(1, &gb.Position)
gl.BindTexture(gl.TEXTURE_2D, gb.Position)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGB16F, windowWidth, windowHeight, 0, gl.RGB, gl.FLOAT, nil)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, gb.Position, 0)
//repeated 3 times for the additional color attachments
var attachments = [4]uint32{gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1, gl.COLOR_ATTACHMENT2, gl.COLOR_ATTACHMENT3}
gl.DrawBuffers(4, &attachments[0])
gl.GenRenderbuffers(1, &gb.DepthBuffer)
gl.BindRenderbuffer(gl.RENDERBUFFER, gb.DepthBuffer)
gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT, windowWidth, windowHeight)
gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, gb.DepthBuffer)
gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
//Blitting - translated to C++ for easier readability for most.
glBindFramebuffer(GL_READ_FRAMEBUFFER, INbufferID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OUTbufferID);
//works
glBlitFramebuffer(0, 0, windowWidth, windowHeight, 0, 0, windowWidth, windowHeight, GL_DEPTH_BUFFERBIT, GL_NEAREST);
//works
glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, windowWidth, windowHeight, 0, 0, windowWidth, windowHeight, GL_COLOR_BUFFER _BIT, GL_LINEAR);
//now it fails - no errors, just way off from expected result and same goes for the next two.
glReadBuffer(GL_COLOR_ATTACHMENT1);
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, 0, windowWidth, windowHeight, 0, 0, windowWidth, windowHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
Any thoughts? A geek losing his mind here =)