From 95f4124b5bce51156c1d100a8d7d6a7ea0822b59 Mon Sep 17 00:00:00 2001 From: Pablo Escobar Date: Mon, 21 Feb 2022 20:23:01 +0100 Subject: [PATCH] GL: add Framebuffer::InvalidationAttachment::DepthStencil Not available on GLES2, similar to BufferAttachment but with the added constraint that WebGL1 doesn't support invalidating attachments at all. Not adding this for DefaultFramebuffer since that takes different target values, and GL_DEPTH_STENCIL is not one of them. --- src/Magnum/GL/Framebuffer.cpp | 3 ++ src/Magnum/GL/Framebuffer.h | 15 +++++++++ src/Magnum/GL/Test/FramebufferGLTest.cpp | 40 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/Magnum/GL/Framebuffer.cpp b/src/Magnum/GL/Framebuffer.cpp index 340d13961..7f521e343 100644 --- a/src/Magnum/GL/Framebuffer.cpp +++ b/src/Magnum/GL/Framebuffer.cpp @@ -73,6 +73,9 @@ const Framebuffer::BufferAttachment Framebuffer::BufferAttachment::DepthStencil #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) const Framebuffer::InvalidationAttachment Framebuffer::InvalidationAttachment::Depth = Framebuffer::InvalidationAttachment(GL_DEPTH_ATTACHMENT); const Framebuffer::InvalidationAttachment Framebuffer::InvalidationAttachment::Stencil = Framebuffer::InvalidationAttachment(GL_STENCIL_ATTACHMENT); +#ifndef MAGNUM_TARGET_GLES2 +const Framebuffer::InvalidationAttachment Framebuffer::InvalidationAttachment::DepthStencil = Framebuffer::InvalidationAttachment(GL_DEPTH_STENCIL_ATTACHMENT); +#endif #endif Int Framebuffer::maxColorAttachments() { diff --git a/src/Magnum/GL/Framebuffer.h b/src/Magnum/GL/Framebuffer.h index 42fb0713a..fdee1a87e 100644 --- a/src/Magnum/GL/Framebuffer.h +++ b/src/Magnum/GL/Framebuffer.h @@ -256,6 +256,21 @@ class MAGNUM_GL_EXPORT Framebuffer: public AbstractFramebuffer, public AbstractO */ static const InvalidationAttachment Stencil; + #ifndef MAGNUM_TARGET_GLES2 + /** + * @brief Invalidate both depth and stencil buffer + * @m_since_latest + * + * @m_keywords{GL_DEPTH_STENCIL_ATTACHMENT} + * @requires_gles30 Combined depth and stencil attachment is + * not available in OpenGL ES 2.0. Invalidate both + * @ref InvalidationAttachment::Depth and + * @ref InvalidationAttachment::Stencil instead. + * @todo Support this in ES2 (invalidate both depth and stencil internally) + */ + static const InvalidationAttachment DepthStencil; + #endif + /** @brief Invalidate color buffer */ constexpr /*implicit*/ InvalidationAttachment(Framebuffer::ColorAttachment attachment): attachment(GLenum(attachment)) {} diff --git a/src/Magnum/GL/Test/FramebufferGLTest.cpp b/src/Magnum/GL/Test/FramebufferGLTest.cpp index e9d1724c3..000d57774 100644 --- a/src/Magnum/GL/Test/FramebufferGLTest.cpp +++ b/src/Magnum/GL/Test/FramebufferGLTest.cpp @@ -126,6 +126,9 @@ struct FramebufferGLTest: OpenGLTester { void invalidate(); #endif #ifndef MAGNUM_TARGET_GLES2 + void invalidateCombinedDepthStencil(); + #endif + #ifndef MAGNUM_TARGET_GLES2 void invalidateSub(); #endif void read(); @@ -269,6 +272,9 @@ FramebufferGLTest::FramebufferGLTest() { &FramebufferGLTest::invalidate, #endif #ifndef MAGNUM_TARGET_GLES2 + &FramebufferGLTest::invalidateCombinedDepthStencil, + #endif + #ifndef MAGNUM_TARGET_GLES2 &FramebufferGLTest::invalidateSub, #endif &FramebufferGLTest::read, @@ -1400,6 +1406,40 @@ void FramebufferGLTest::invalidate() { framebuffer.invalidate({Framebuffer::InvalidationAttachment::Depth, Framebuffer::ColorAttachment(0)}); MAGNUM_VERIFY_NO_GL_ERROR(); + + #ifndef MAGNUM_TARGET_GLES2 + /* Invalidating combined bits should work as well even if there's just stencil alone */ + framebuffer.invalidate({Framebuffer::InvalidationAttachment::DepthStencil}); + + MAGNUM_VERIFY_NO_GL_ERROR(); + #endif +} +#endif + +#ifndef MAGNUM_TARGET_GLES2 +void FramebufferGLTest::invalidateCombinedDepthStencil() { + #ifndef MAGNUM_TARGET_GLES + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::ARB::framebuffer_object::string() << "is not supported."); + #endif + + Renderbuffer depthStencil; + depthStencil.setStorage(RenderbufferFormat::Depth24Stencil8, Vector2i(128)); + + Framebuffer framebuffer({{}, Vector2i(128)}); + framebuffer.attachRenderbuffer(Framebuffer::BufferAttachment::DepthStencil, depthStencil); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + framebuffer.invalidate({Framebuffer::InvalidationAttachment::DepthStencil}); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + /* Invalidating separate bits should work as well */ + framebuffer.invalidate({Framebuffer::InvalidationAttachment::Depth, + Framebuffer::InvalidationAttachment::Stencil}); + + MAGNUM_VERIFY_NO_GL_ERROR(); } #endif