From 2a2917f41f02fa12e9354616d76bf45c9b5bf3e6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 9 Dec 2021 15:34:27 +0200 Subject: [PATCH] Track the number of layers in Framebuffer --- source/backends/vulkan/framebuffer_backend.cpp | 2 +- source/core/framebuffer.cpp | 4 ++++ source/core/framebuffer.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/backends/vulkan/framebuffer_backend.cpp b/source/backends/vulkan/framebuffer_backend.cpp index 8ef69ecd..61ab1cae 100644 --- a/source/backends/vulkan/framebuffer_backend.cpp +++ b/source/backends/vulkan/framebuffer_backend.cpp @@ -74,7 +74,7 @@ void VulkanFramebuffer::update(unsigned) const framebuffer_info.pAttachments = handle_cast<::VkImageView *>(vk_attachments); framebuffer_info.width = self.width; framebuffer_info.height = self.height; - framebuffer_info.layers = 1; + framebuffer_info.layers = self.layers; vk.CreateFramebuffer(framebuffer_info, handle); diff --git a/source/core/framebuffer.cpp b/source/core/framebuffer.cpp index 8a1a5231..97cc905d 100644 --- a/source/core/framebuffer.cpp +++ b/source/core/framebuffer.cpp @@ -60,6 +60,7 @@ void Framebuffer::check_size() { unsigned w = 0; unsigned h = 0; + unsigned l = 1; if(const Texture2D *tex2d = dynamic_cast(a.tex)) { w = max(tex2d->get_width()>>a.level, 1U); @@ -74,6 +75,7 @@ void Framebuffer::check_size() { w = max(tex3d->get_width()>>a.level, 1U); h = max(tex3d->get_height()>>a.level, 1U); + l = (a.layer<0 ? tex3d->get_depth() : 1); } else if(const TextureCube *tex_cube = dynamic_cast(a.tex)) { @@ -85,12 +87,14 @@ void Framebuffer::check_size() { width = w; height = h; + layers = l; first = false; } else { width = min(width, w); height = min(height, h); + layers = min(layers, l); } } } diff --git a/source/core/framebuffer.h b/source/core/framebuffer.h index b8057216..1a13ca5b 100644 --- a/source/core/framebuffer.h +++ b/source/core/framebuffer.h @@ -49,6 +49,7 @@ protected: std::vector attachments; unsigned width = 0; unsigned height = 0; + unsigned layers = 0; mutable unsigned dirty = 0; Framebuffer(bool); @@ -71,6 +72,7 @@ public: unsigned get_width() const { return width; } unsigned get_height() const { return height; } + unsigned get_layers() const { return layers; } protected: void update() const; -- 2.43.0