From: Mikko Rasa Date: Sat, 25 Sep 2021 15:37:32 +0000 (+0300) Subject: Automatically detect which multisample buffers to resolve X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=1fba50491957cdd28cff4082a32764691d8ec473 Automatically detect which multisample buffers to resolve --- diff --git a/source/core/commands.cpp b/source/core/commands.cpp index f2c27372..19ff1011 100644 --- a/source/core/commands.cpp +++ b/source/core/commands.cpp @@ -82,7 +82,7 @@ void Commands::draw_instanced(const Batch &batch, unsigned count) glDrawElementsInstanced(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr, count); } -void Commands::resolve_multisample(Framebuffer &target, BufferBits buffers) +void Commands::resolve_multisample(Framebuffer &target) { static Require _req(EXT_framebuffer_blit); @@ -90,6 +90,7 @@ void Commands::resolve_multisample(Framebuffer &target, BufferBits buffers) unsigned width = min(source->get_width(), target.get_width()); unsigned height = min(source->get_height(), target.get_height()); + unsigned buffers = get_gl_buffer_bits(source->get_format())&get_gl_buffer_bits(target.get_format()); if(ARB_direct_state_access) glBlitNamedFramebuffer(source->id, target.id, 0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST); diff --git a/source/core/commands.h b/source/core/commands.h index 2dc66cfa..6969b820 100644 --- a/source/core/commands.h +++ b/source/core/commands.h @@ -21,7 +21,7 @@ public: void clear(const ClearValue *); void draw(const Batch &); void draw_instanced(const Batch &, unsigned); - void resolve_multisample(Framebuffer &, BufferBits); + void resolve_multisample(Framebuffer &); }; } // namespace GL diff --git a/source/core/frameformat.cpp b/source/core/frameformat.cpp index 3b114e7f..f56d13a6 100644 --- a/source/core/frameformat.cpp +++ b/source/core/frameformat.cpp @@ -133,5 +133,20 @@ GLenum get_gl_attachment(FrameAttachment fa) return GL_COLOR_ATTACHMENT0+get_attach_point(fa); } +GLenum get_gl_buffer_bits(const FrameFormat &format) +{ + GLenum bits = 0; + for(FrameAttachment a: format) + { + if(get_attach_point(a)==get_attach_point(DEPTH_ATTACHMENT)) + bits |= GL_DEPTH_BUFFER_BIT; + else if(get_attach_point(a)==get_attach_point(STENCIL_ATTACHMENT)) + bits |= GL_STENCIL_BUFFER_BIT; + else + bits |= GL_COLOR_BUFFER_BIT; + } + return bits; +} + } // namespace GL } // namespace Msp diff --git a/source/core/frameformat.h b/source/core/frameformat.h index c80f63e0..a78985f3 100644 --- a/source/core/frameformat.h +++ b/source/core/frameformat.h @@ -77,6 +77,7 @@ inline unsigned get_attach_point(FrameAttachment fa) PixelFormat get_attachment_pixelformat(FrameAttachment); GLenum get_gl_attachment(FrameAttachment); +GLenum get_gl_buffer_bits(const FrameFormat &); } // namespace GL } // namespace Msp diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 4320ef30..19148a4d 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -265,7 +265,7 @@ void Renderer::draw_instanced(const Batch &batch, unsigned count) commands.draw_instanced(batch, count); } -void Renderer::resolve_multisample(Framebuffer &target, BufferBits buffers) +void Renderer::resolve_multisample(Framebuffer &target) { if(!state->framebuffer) throw invalid_operation("Renderer::resolve_multisample"); @@ -277,7 +277,7 @@ void Renderer::resolve_multisample(Framebuffer &target, BufferBits buffers) pipeline_state.set_framebuffer(state->framebuffer); commands.use_pipeline(&pipeline_state); - commands.resolve_multisample(target, buffers); + commands.resolve_multisample(target); } void Renderer::apply_state() diff --git a/source/render/renderer.h b/source/render/renderer.h index 8026f5ab..5139c4ce 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -201,7 +201,7 @@ public: void draw(const Batch &); void draw_instanced(const Batch &, unsigned); - void resolve_multisample(Framebuffer &, BufferBits); + void resolve_multisample(Framebuffer &); private: void apply_state(); diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index 7a964c87..5a3afa45 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -174,7 +174,7 @@ void Sequence::render(Renderer &renderer, Tag tag) const if(target[0]) { if(target_ms) - renderer.resolve_multisample(target[0]->get_framebuffer(), COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); + renderer.resolve_multisample(target[0]->get_framebuffer()); renderer.set_depth_test(0); renderer.set_stencil_test(0);