Skip to content

Commit 6c85fd3

Browse files
committed
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?
1 parent ddfa84a commit 6c85fd3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/renderpass_gl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,13 @@ void RenderPass::blit_to(const Vector2i &src_offset,
345345
if (screen) {
346346
target_id = 0;
347347
what = GL_COLOR_BUFFER_BIT;
348-
if (screen->has_depth_buffer() && m_targets[0])
348+
// blit the depth buffer (only possible if number of samples is equal)
349+
const Texture* depth_buffer = dynamic_cast<Texture*>(m_targets[0].get());
350+
if (screen->has_depth_buffer() && depth_buffer && depth_buffer->samples() == 1)
349351
what |= GL_DEPTH_BUFFER_BIT;
350-
if (screen->has_stencil_buffer() && m_targets[1])
352+
// blit the stencil buffer (only possible if number of samples is equal)
353+
const Texture* stencil_buffer = dynamic_cast<Texture*>(m_targets[1].get());
354+
if (screen->has_stencil_buffer() && stencil_buffer && stencil_buffer->samples() == 1)
351355
what |= GL_STENCIL_BUFFER_BIT;
352356
} else if (rp) {
353357
target_id = rp->framebuffer_handle();

0 commit comments

Comments
 (0)