PDA

View Full Version : glBlitFramebuffer of GL_DEPTH_STENCIL_ATTACHMENT is not working



saski
02-28-2017, 12:21 AM
Hi,

I've been working on some transparent postprocessing to my deferred render engine. However blitting the framebuffer gives me a headeache.

My FBO Depth/Stencil buffer setup looks line this:



// depth/stencil
glBindTexture(GL_TEXTURE_2D, ids[depthbuffer]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, scrdim[0], scrdim[1], 0,
GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, ids[depthbuffer], 0);


After the deferred process I need to blit the framebuffer from the FBO to the "screen buffer" in order to do the transparent pass in forward render mode.



glBindFramebuffer(GL_READ_FRAMEBUFFER, ids[fbocontainer]);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, scrdim[0], scrdim[1], 0, 0,
scrdim[0], scrdim[1],
GL_DEPTH_BUFFER_BIT,
GL_NEAREST);


This however generates an GL_INVALID_OPERATION on my NVIDIA card (WIN64). With the Intel GPU (Linux) on the other hand this works nice.
Any clues what I'm doing wrong here?

Thx in advance
Saski

Dark Photon
02-28-2017, 05:58 AM
After the deferred process I need to blit the framebuffer from the FBO to the "screen buffer" in order to do the transparent pass in forward render mode. ... This however generates an GL_INVALID_OPERATION on my NVIDIA card (WIN64). With the Intel GPU (Linux) on the other hand this works nice.
Any clues what I'm doing wrong here?

The system framebuffer (provided by the window system) can be finicky because you don't always have complete control over its format like you do FBOs.

You might check to ensure that this does not apply in your circumstance:



GL_INVALID_OPERATION is generated if mask contains GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT and the source and destination depth and stencil formats do not match.

That means since you're using DEPTH24_STENCIL8 for your source, you should be using that for your window system framebuffer (as best as you can request anyway).


If all else fails, you can just do your transparency pass on a 2nd FBO (where you have complete control of the framebuffer format) rather than on the system framebuffer. Then at the end, blit color alone from there to the system framebuffer. Another pro for you for that approach is that, so long as your blit source is single-sampled, that obviates the need to blit the depth attachment completely (as you can just attach your depth buffer to the 2nd FBO and proceed with transparency rendering).


... which brings me to: why do you need to blit anything to do your transparency pass? Why not perform that rendering on top of the FBO you already have? Then blit just the color buffer to the system framebuffer at the end.