]> git.tdb.fi Git - libs/gl.git/commitdiff
Automatically detect which multisample buffers to resolve
authorMikko Rasa <tdb@tdb.fi>
Sat, 25 Sep 2021 15:37:32 +0000 (18:37 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 Sep 2021 15:37:32 +0000 (18:37 +0300)
source/core/commands.cpp
source/core/commands.h
source/core/frameformat.cpp
source/core/frameformat.h
source/render/renderer.cpp
source/render/renderer.h
source/render/sequence.cpp

index f2c273727c7d2b5fcd7037b77f8df51c1b1f7a1e..19ff10115e53e10faf612220c2daf3f4697f841e 100644 (file)
@@ -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);
index 2dc66cfa5232c8ea409162f0d09b829ccb9012a0..6969b820306d88506424655dc3ef0516a8ac0511 100644 (file)
@@ -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
index 3b114e7f2f0ebd01da02ea39ce5edd72f64e2be8..f56d13a68b27db15bd98c9fb97fa5e187bd23fe6 100644 (file)
@@ -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
index c80f63e0dd02518e00aa85f9f1eae75947beb564..a78985f38583fa5227c7683bfa9716ca300f3849 100644 (file)
@@ -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
index 4320ef30e4e2e87815e0e1ab24212cf8d0eb2c2b..19148a4dbf5a4f9bf1c9743481336ecf80297bb3 100644 (file)
@@ -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()
index 8026f5ab8770429981c399b5f2482656756717fe..5139c4ce925fd978d8136e6b5655f6ddfd4087d2 100644 (file)
@@ -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();
index 7a964c870d39e2bbe40a9cbf4a2571d1e1f40843..5a3afa452e2e9235ade6e0cfc6558073672fa23e 100644 (file)
@@ -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);