]> git.tdb.fi Git - libs/gl.git/commitdiff
Make it possible to query if a framebuffer can be presented
authorMikko Rasa <tdb@tdb.fi>
Thu, 1 Sep 2022 19:31:17 +0000 (22:31 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 1 Sep 2022 19:32:30 +0000 (22:32 +0300)
source/backends/opengl/framebuffer_backend.h
source/backends/vulkan/commands_backend.cpp
source/backends/vulkan/framebuffer_backend.cpp
source/backends/vulkan/framebuffer_backend.h
source/core/framebuffer.h

index b2e936147d73ce3c707ef15cabf5cc2af2d054cf..258db95fe9bbc0438ca01f77b95f6614a5ea444e 100644 (file)
@@ -27,6 +27,8 @@ protected:
        void format_changed(const FrameFormat &);
        static void require_layered();
 
+       bool is_presentable() const { return id==0; }
+
        void resize_system(unsigned, unsigned);
        void update(unsigned) const;
        void update(unsigned, bool) const;
index 9f53f1ce56f172a060e91bd3cfb102e5c4613c1e..5de0f090a9d774aa7e6c8d76d6dc4ebcf7bc5dd8 100644 (file)
@@ -10,7 +10,6 @@
 #include "rect.h"
 #include "renderpass.h"
 #include "semaphore.h"
-#include "swapchaintexture.h"
 #include "vulkan.h"
 
 using namespace std;
@@ -92,12 +91,7 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value
        if(!primary_buffer)
                begin_buffer(0);
 
-       fb_is_swapchain = false;
-       unsigned n_attachments = framebuffer->get_format().size();
-       for(unsigned i=0; (!fb_is_swapchain && i<n_attachments); ++i)
-               if(dynamic_cast<const SwapChainTexture *>(framebuffer->get_attachment(i)))
-                       fb_is_swapchain = true;
-
+       fb_is_swapchain = framebuffer->is_presentable();
        framebuffer->refresh();
 
        RenderPass render_pass;
index 9af8a2f7b1a7a9e52464d6d0027da801bee96700..4c68546f15ed322181aad3ef9c136f92c9892ff3 100644 (file)
@@ -3,6 +3,7 @@
 #include "framebuffer.h"
 #include "framebuffer_backend.h"
 #include "renderpass.h"
+#include "swapchaintexture.h"
 #include "vulkan.h"
 
 using namespace std;
@@ -53,6 +54,13 @@ bool VulkanFramebuffer::is_format_supported(const FrameFormat &fmt)
        return true;
 }
 
+bool VulkanFramebuffer::is_presentable() const
+{
+       const Framebuffer &self = *static_cast<const Framebuffer *>(this);
+       return std::any_of(self.attachments.begin(), self.attachments.end(),
+               [](const Framebuffer::Attachment &a){ return dynamic_cast<const SwapChainTexture *>(a.tex); });
+}
+
 void VulkanFramebuffer::update(unsigned mask) const
 {
        const Framebuffer &self = *static_cast<const Framebuffer *>(this);
index 30ca17011a0fdc65e585a62c4211533cc6ca05b5..faca5658feb7a0e2b1b5febf1c01d56e174dd787 100644 (file)
@@ -31,6 +31,8 @@ protected:
        void format_changed(const FrameFormat &) { }
        static void require_layered() { }
 
+       bool is_presentable() const;
+
        void update(unsigned) const;
        void require_complete() const { }
 
index b3359a34aeb5998052a728b1aff98f733f2fd74f..4932f29a31b687dff3fe8cd9abe52818eeef7b00 100644 (file)
@@ -120,6 +120,8 @@ public:
        const Texture *get_resolve_attachment(unsigned) const;
        bool has_resolve_attachments() const;
 
+       using FramebufferBackend::is_presentable;
+
        /** Ensures that the framebuffer is complete, throwing an exception if it
        isn't. */
        void require_complete() const;