From b17b828955511e7c61b86ccac668334f28823893 Mon Sep 17 00:00:00 2001 From: Lukas Ruppert Date: Wed, 10 Aug 2022 13:47:02 +0200 Subject: [PATCH 1/2] Set GL_DEPTH_BUFFER_BIT when blitting the depth buffer to the screen. (Fixes a copy-paste bug, previously the GL_STENCIL_BUFFER_BIT was being set.) --- src/renderpass_gl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderpass_gl.cpp b/src/renderpass_gl.cpp index 09aa208a..a38fa92b 100644 --- a/src/renderpass_gl.cpp +++ b/src/renderpass_gl.cpp @@ -359,7 +359,7 @@ void RenderPass::blit_to(const Vector2i &src_offset, target_id = 0; what = GL_COLOR_BUFFER_BIT; if (screen->has_depth_buffer() && m_targets[0]) - what |= GL_STENCIL_BUFFER_BIT; + what |= GL_DEPTH_BUFFER_BIT; if (screen->has_stencil_buffer() && m_targets[1]) what |= GL_STENCIL_BUFFER_BIT; } else if (rp) { From de3221f5d150e24151cd08f20dee74921f210a51 Mon Sep 17 00:00:00 2001 From: Lukas Ruppert Date: Wed, 5 Oct 2022 10:02:59 +0200 Subject: [PATCH 2/2] Disable blitting depth or stencil buffers to the screen if multisampling is enabled in the texture. (Blitting a multisampled texture into a single-sample screen results in a GL_INVALID_OPERATION.) Should there be a warning if blitting is not possible? --- src/renderpass_gl.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/renderpass_gl.cpp b/src/renderpass_gl.cpp index a38fa92b..50bcbb80 100644 --- a/src/renderpass_gl.cpp +++ b/src/renderpass_gl.cpp @@ -358,9 +358,13 @@ void RenderPass::blit_to(const Vector2i &src_offset, if (screen) { target_id = 0; what = GL_COLOR_BUFFER_BIT; - if (screen->has_depth_buffer() && m_targets[0]) + // blit the depth buffer (only possible if number of samples is equal) + const Texture* depth_buffer = dynamic_cast(m_targets[0]); + if (screen->has_depth_buffer() && depth_buffer && depth_buffer->samples() == 1) what |= GL_DEPTH_BUFFER_BIT; - if (screen->has_stencil_buffer() && m_targets[1]) + // blit the stencil buffer (only possible if number of samples is equal) + const Texture* stencil_buffer = dynamic_cast(m_targets[1]); + if (screen->has_stencil_buffer() && stencil_buffer && stencil_buffer->samples() == 1) what |= GL_STENCIL_BUFFER_BIT; } else if (rp) { target_id = rp->framebuffer_handle();