Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shared stencil buffer between framebuffers?

Started by ZachBethel Mar 18, 2013 at 1:53 AM 0 replies 3.1k views
Original Post
ZachBethel
ZachBethel

I'm writing a game where I need to apply a gaussian blur to parts of the scene. I've created an FBO with a depth-stencil buffer attached, and I'm rendering my scene to that buffer. I would like to set the stencil buffer to 1 for any fragment that requires blur, so my rendering queue has logic to set/unset that based on the requirements of the renderable. There are only a few sprites that are being blurred.

I'm trying to wrap my head around how OpenGL handles frame buffers with attached render buffers and all that. Is there a way I can share the stencil buffer across a couple frame buffer objects as well as my back buffer? Ideally, I would like to render everything into one scratch FBO (while doing stencil writes), and then render a first gaussian pass into the second FBO ignoring fragments not flagged by the stencil buffer. Finally, I'd like to render the second pass into the main framebuffer (also with stencil testing enabled).

Is this possible? I'm not quite understanding how OpenGL interprets which stencil buffer to use. I assume anytime I'm calling glStencilFunc, it's acting on the currently bound framebuffer object. In that case, do I need to somehow grab the default stencil buffer and attach it to my scratch FBOs?

Thanks!

Ashaman73
Ashaman73

You typically use multiple buffers at once, most likely a depth_stencil and at least a color buffer. Therefor you can change the color buffer while keeping the depth_stencil buffer:


// render color buffer
color_0 = my_color_buffer;
depth_stencil = my_depth_stencil_buffer;

// bur pass
source_buffer in shader: my_color_buffer
color_0 = my_blurred_buffer;
depth_stencil = my_depth_stencil_buffer;

// apply blurred buffer to target buffer
source_buffer in shader: my_blurred_buffer;
color_0 = my_color_buffer;
depth_stencil = my_depth_stencil_buffer;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.