Went through the source with a crayon scrawling recklessly. I think I have my work around now! At least, it doesn't crash the program by some miracle while doing what I wanted. Thought I'd share it here if anyone was interested.
Made 2 small edits in sfml, and added a small namespace named 'clair' (so I can search it easily if something explodes) that contains a boolean that activates the code needed for stencils. I just flip the bool to true before creating a RenderTexture, then turn it back off after it's done. Yeah... it's pretty ugly
The destructor seems to clean up the FBO version regardless of which branch is taken (but I might be fatally mistaken).
RenderTextureImplFBO.cpp
bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
{
...
if (depthBuffer)
{
...
glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
if(clair::enableStencilOnRenderTextureCreation){
// edited to allow stencils --clair
glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, width, height));
glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
}else{
// original code moved to else branch
glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
}
...
}
...
}
RenderTextureImplDefault.cpp
bool RenderTextureImplDefault::create(unsigned int width, unsigned int height, unsigned int, bool depthBuffer)
{
...
// Create the in-memory OpenGL context
if(clair::enableStencilOnRenderTextureCreation){
// edited to allow stencils --clair
m_context = new Context(ContextSettings(24, 8, 0), width, height);
}else{
// original code moved to else branch
m_context = new Context(ContextSettings(depthBuffer ? 32 : 0), width, height);
}
return true;
}