From fcc065736e303088ef121c554318e0cc028a0666 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 1 Sep 2022 22:31:17 +0300 Subject: [PATCH] Make it possible to query if a framebuffer can be presented --- source/backends/opengl/framebuffer_backend.h | 2 ++ source/backends/vulkan/commands_backend.cpp | 8 +------- source/backends/vulkan/framebuffer_backend.cpp | 8 ++++++++ source/backends/vulkan/framebuffer_backend.h | 2 ++ source/core/framebuffer.h | 2 ++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/source/backends/opengl/framebuffer_backend.h b/source/backends/opengl/framebuffer_backend.h index b2e93614..258db95f 100644 --- a/source/backends/opengl/framebuffer_backend.h +++ b/source/backends/opengl/framebuffer_backend.h @@ -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; diff --git a/source/backends/vulkan/commands_backend.cpp b/source/backends/vulkan/commands_backend.cpp index 9f53f1ce..5de0f090 100644 --- a/source/backends/vulkan/commands_backend.cpp +++ b/source/backends/vulkan/commands_backend.cpp @@ -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(framebuffer->get_attachment(i))) - fb_is_swapchain = true; - + fb_is_swapchain = framebuffer->is_presentable(); framebuffer->refresh(); RenderPass render_pass; diff --git a/source/backends/vulkan/framebuffer_backend.cpp b/source/backends/vulkan/framebuffer_backend.cpp index 9af8a2f7..4c68546f 100644 --- a/source/backends/vulkan/framebuffer_backend.cpp +++ b/source/backends/vulkan/framebuffer_backend.cpp @@ -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(this); + return std::any_of(self.attachments.begin(), self.attachments.end(), + [](const Framebuffer::Attachment &a){ return dynamic_cast(a.tex); }); +} + void VulkanFramebuffer::update(unsigned mask) const { const Framebuffer &self = *static_cast(this); diff --git a/source/backends/vulkan/framebuffer_backend.h b/source/backends/vulkan/framebuffer_backend.h index 30ca1701..faca5658 100644 --- a/source/backends/vulkan/framebuffer_backend.h +++ b/source/backends/vulkan/framebuffer_backend.h @@ -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 { } diff --git a/source/core/framebuffer.h b/source/core/framebuffer.h index b3359a34..4932f29a 100644 --- a/source/core/framebuffer.h +++ b/source/core/framebuffer.h @@ -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; -- 2.43.0