diff --git a/include/osg/Camera b/include/osg/Camera index 74344b2e4..23aa7591f 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -310,6 +310,7 @@ class OSG_EXPORT Camera : public Transform, public CullSettings { DEPTH_BUFFER, STENCIL_BUFFER, + PACKED_DEPTH_STENCIL_BUFFER, COLOR_BUFFER, COLOR_BUFFER0, COLOR_BUFFER1 = COLOR_BUFFER0+1, diff --git a/include/osg/FrameBufferObject b/include/osg/FrameBufferObject index 8edc1605d..d84f9b190 100644 --- a/include/osg/FrameBufferObject +++ b/include/osg/FrameBufferObject @@ -114,6 +114,14 @@ #define GL_DEPTH_COMPONENT32 0x81A7 #endif +#ifndef GL_EXT_packed_depth_stencil +#define GL_EXT_packed_depth_stencil 1 +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#define GL_UNSIGNED_INT_24_8_EXT 0x84FA +#define GL_DEPTH24_STENCIL8_EXT 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 +#endif + namespace osg { @@ -165,11 +173,13 @@ namespace osg bool isSupported() const { return _supported; } bool isMultisampleSupported() const { return glRenderbufferStorageMultisampleEXT != 0; } bool isMultisampleCoverageSupported() const { return glRenderbufferStorageMultisampleCoverageNV != 0; } + bool isPackedDepthStencilSupported() const { return _packed_depth_stencil_supported; } protected: FBOExtensions(unsigned int contextID); bool _supported; + bool _packed_depth_stencil_supported; }; /************************************************************************** diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index f7038ec71..4432cf0d0 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -58,7 +58,8 @@ FBOExtensions::FBOExtensions(unsigned int contextID) glFramebufferRenderbufferEXT(0), glGenerateMipmapEXT(0), glBlitFramebufferEXT(0), - _supported(false) + _supported(false), + _packed_depth_stencil_supported(false) { if (!isGLExtensionSupported(contextID, "GL_EXT_framebuffer_object")) return; @@ -107,6 +108,11 @@ FBOExtensions::FBOExtensions(unsigned int contextID) { LOAD_FBO_EXT(glRenderbufferStorageMultisampleCoverageNV); } + + if (isGLExtensionSupported(contextID, "GL_EXT_packed_depth_stencil")) + { + _packed_depth_stencil_supported = true; + } } @@ -811,7 +817,26 @@ void FrameBufferObject::apply(State &state, BindTarget target) const for (AttachmentMap::const_iterator i=_attachments.begin(); i!=_attachments.end(); ++i) { const FrameBufferAttachment &fa = i->second; - fa.attach(state, target, convertBufferComponentToGLenum(i->first), ext); + switch(i->first) + { + case(Camera::PACKED_DEPTH_STENCIL_BUFFER): + if (ext->isPackedDepthStencilSupported()) + { + fa.attach(state, target, GL_DEPTH_ATTACHMENT_EXT, ext); + fa.attach(state, target, GL_STENCIL_ATTACHMENT_EXT, ext); + } + else + { + notify(WARN) << + "Warning: FrameBufferObject: could not attach PACKED_DEPTH_STENCIL_BUFFER, " + "EXT_packed_depth_stencil is not supported !" << std::endl; + } + break; + + default: + fa.attach(state, target, convertBufferComponentToGLenum(i->first), ext); + break; + } } dirtyAttachmentList = 0; }