How do I render color and depth in a multiprocessor texture?

To implement "deep peeling", I make my OpenGL scene a series of framebuffers, each with an rgba texture and depth texture. This works great if I'm not interested in anti-aliasing. If so, then it seems like the right thing to do is include GL_MULTISAMPLING

and use GL_TEXTURE_2D_MULTISAMPLE

instead GL_TEXTURE_2D

. But I'm confused about what other calls need to be replaced.

Specifically, how do I adapt the framebuffer construct to use glTexImage2DMultisample

instead glTexImage2D

?

Do I need to change calls to glFramebufferTexture2D

after use GL_TEXTURE_2D_MULTISAMPLE

instead GL_TEXTURE_2D

?

If I handle both color and depth in textures, do I need to make a call glRenderbufferStorageMultisample

?

Finally, is there something glBlit*

I need to do in addition to setting up textures to render the framebuffer in?

There are many related questions on this topic, but none of the solutions I have found point to a canonical guide or clear example that puts it all together.

+3


source to share


1 answer


While I have been using multisampled FBO rendering with renderbuffers rather than textures, I understand the following.

Do I need to change calls to glFramebufferTexture2D

after use GL_TEXTURE_2D_MULTISAMPLE

instead GL_TEXTURE_2D

?

No, that's all you need. You create a texture with glTexImage2DMultisample()

and then add it with GL_TEXTURE_2D_MULTISAMPLE

as the third argument to glFramebufferTexture2D()

. The only limitation is that the level (5th argument) must be 0.

If I handle both color and depth in textures, do I need to make a call glRenderbufferStorageMultisample

?

Yes. If you attach a depth buffer to the same FBO, you need to use a multisampled render buffer with the same number of samples as the color buffer. This way you create your render depth with by glRenderbufferStorageMultisample()

passing in the same count you used for the color buffer.



Finally, is there something glBlit*

I need to do in addition to setting up textures to render the framebuffer in?

Not for rendering to a framebuffer. When you're done rendering, you have several options:

  • You can reduce (resolve) the texture of a multisample to a regular texture and then use a regular texture for subsequent rendering. For multi-spiral texture resolution, you can use glBlitFramebuffer()

    where multisample texture is anchored to GL_READ_FRAMEBUFFER

    and regular texture is anchored to GL_DRAW_FRAMEBUFFER

    .

  • You can use a multisample texture for subsequent rendering. You will need to use the sampler2DMS

    sampler type in your shader code with the appropriate sampling functions.

For option 1, I really don't see a good reason to use a multi-spiral texture. You can also use the renderbuffer multisampler, which is a little easier to use and should be at least efficient. To do this, you create a renderbuffer to nest the color and highlight it with glRenderbufferStorageMultisample()

, very similar to what you need for a depth buffer.

0


source







All Articles