I'm having trouble with the msaa depth buffer resolving to a depth texture. I create my glTexImage2d for both my color texture and my depth texture and bind them to the "resolve" ( non-msaa ) framebuffer. Then I create and bind another framebuffer and create my multisampled renderbuffers ( both color and depth ). I know to get my color texture information from the multisampled renderbuffer I just blit with the write buffer being my color texture framebuffer and the read buffer being my msaa-framebuffer. My question is how do I blit my multisampled depth buffer to my depth texture.
Asked
Active
Viewed 5,532 times
1 Answers
4
You would do this the same way you would do for the color buffer, only you would use GL_DEPTH_BUFFER_BIT
and make sure you use GL_NEAREST
for the filter mode. If you want linear filtering on a depth/stencil buffer, for whatever reason, you can actually do this in GLSL if you use a depth texture (of course this still remains invalid for MSAA textures) - but it is invalid to do this using glBlitFramebuffer (...)
.
You do not have to do any of the glReadBuffer (...)
nonsense like you do when you want to select an individual color buffer, glBlitFramebuffer (...)
will copy the depth buffer from the bound GL_READ_FRAMEBUFFER
to the bound GL_DRAW_FRAMEBUFFER
.

Andon M. Coleman
- 42,359
- 2
- 81
- 106
-
So if I'm blitting the color buffer like... glDrawBuffer( GL_COLOR_ATTACHMENT0 ); glReadBuffer( GL_COLOR_ATTACHMENT0 ); glBlitFrameBuffer( 0, 0, mWidth, mHeight, 0, 0, mWidth, mHeight, GL_COLOR_BUFFERBIT, GL_NEAREST );...can I just add the depth buffer bit to the BlitFrameBuffer like so... glBlitFrameBuffer( 0, 0, mWidth, mHeight, 0, 0, mWidth, mHeight, GL_COLOR_BUFFERBIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST );...and gl will figure it out? – Ryan Bartley Sep 18 '13 at 15:37
-
That _should_ work. Provided your read and draw framebuffers both have a color attachment 0 and a depth buffer. Things might get hairy if you have a color buffer and depth buffer that have differing dimensions (yes, this is possible) or if your depth buffer is a packed depth/stencil (as is usually the case if you want to blit directly to the window). – Andon M. Coleman Sep 18 '13 at 16:40
-
I should add to this that MSAA depth textures are a Shader Model 4.1 feature (that is to say, they were not ***required*** until SM 4.1). They are not supported on a lot of hardware older than AMD Radeon HD 3xxx or GeForce 2xx. In theory, this should only affect you if you were going the opposite direction - trying to blit from an MSAA depth texture to a single-sampled renderbuffer/texture, but you never know. – Andon M. Coleman Sep 18 '13 at 16:55
-
Let me know what hardware you are using, I am curious to know if this is the culprit; I have my own theories. – Andon M. Coleman Sep 18 '13 at 17:07
-
Thank you so much. I'm sorry it took so long. That worked. For some reason I was just really twisted by whether or not I needed to set glReadBuffer and glDrawBuffer to the GL_DEPTH_COMPONENT and then blit it. I appreciate you getting back to me so fast. – Ryan Bartley Sep 23 '13 at 20:02
-
That worked for me too! I got (resolved) color texture anti-aliased, but depth texture aliased. What's the problem? I use Intel HD3000 GPU. – Alexey S. Mar 31 '18 at 09:24