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?