Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ if(GFX_BUILD_EXAMPLES)
set(GFX_EXAMPLES_TO_BUILD "triangle;multiBuffer;imgui_usage;mc_cube;scop" CACHE STRING "Semicolon separated list of example names to build")
endif()

if (GFX_USE_UTILSCPP OR GFX_USE_MATH)
message(FATAL_ERROR "Not yet implemented")
endif()

enable_language(CXX)

if(APPLE AND GFX_BUILD_METAL)
Expand Down
3 changes: 3 additions & 0 deletions include/Graphics/Swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Swapchain
Swapchain(const Swapchain&) = delete;
Swapchain(Swapchain&&) = delete;

virtual uint32_t width() const = 0;
virtual uint32_t height() const = 0;

virtual std::shared_ptr<Drawable> nextDrawable() = 0;

virtual ~Swapchain() = default;
Expand Down
5 changes: 5 additions & 0 deletions src/Metal/MetalSwapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ class MetalSwapchain : public Swapchain

MetalSwapchain(const MetalDevice&, const Swapchain::Descriptor&);

inline uint32_t width() const override { return m_width; }
inline uint32_t height() const override { return m_height; }

std::shared_ptr<Drawable> nextDrawable() override;

~MetalSwapchain() override = default;

private:
uint32_t m_width;
uint32_t m_height;
CAMetalLayer* m_mtlLayer;

public:
Expand Down
4 changes: 3 additions & 1 deletion src/Metal/MetalSwapchain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
namespace gfx
{

MetalSwapchain::MetalSwapchain(const MetalDevice& device, const Swapchain::Descriptor& desc) { @autoreleasepool
MetalSwapchain::MetalSwapchain(const MetalDevice& device, const Swapchain::Descriptor& desc)
: m_width(desc.width)
, m_height(desc.height) { @autoreleasepool
{
assert(desc.surface);
auto* mtlSurface = dynamic_cast<MetalSurface*>(desc.surface);
Expand Down
11 changes: 5 additions & 6 deletions src/Vulkan/VulkanSwapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ VulkanSwapchain::VulkanSwapchain(const VulkanDevice* device, const Descriptor& d
std::vector<vk::PresentModeKHR> surfacePresentModes = vkPhysicalDevice.getSurfacePresentModesKHR(vkSurface);
assert(std::ranges::any_of(surfacePresentModes, [&desc](auto& m){return m == toVkPresentModeKHR(desc.presentMode);}));

vk::Extent2D extent;
if (surfaceCapabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
extent = surfaceCapabilities.currentExtent;
m_extent = surfaceCapabilities.currentExtent;
else
{
extent.width = std::clamp(desc.width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width);
extent.height = std::clamp(desc.height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height);
m_extent.width = std::clamp(desc.width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width);
m_extent.height = std::clamp(desc.height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height);
}


Expand All @@ -54,7 +53,7 @@ VulkanSwapchain::VulkanSwapchain(const VulkanDevice* device, const Descriptor& d
.setMinImageCount(desc.imageCount)
.setImageFormat(toVkFormat(desc.pixelFormat))
.setImageColorSpace(toVkColorSpaceKHR(desc.pixelFormat))
.setImageExtent(extent)
.setImageExtent(m_extent)
.setImageArrayLayers(1)
.setImageUsage(vk::ImageUsageFlagBits::eColorAttachment)
.setPreTransform(surfaceCapabilities.currentTransform)
Expand All @@ -77,7 +76,7 @@ VulkanSwapchain::VulkanSwapchain(const VulkanDevice* device, const Descriptor& d
s_oldSwapchains[&vkSurface] = *m_vkSwapchain;

Texture::Descriptor swapchainImageTexDesc = {
.width = extent.width, .height = extent.height,
.width = m_extent.width, .height = m_extent.height,
.pixelFormat = desc.pixelFormat,
.usages = TextureUsage::colorAttachment,
.storageMode = ResourceStorageMode::deviceLocal
Expand Down
4 changes: 4 additions & 0 deletions src/Vulkan/VulkanSwapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ class VulkanSwapchain : public Swapchain

VulkanSwapchain(const VulkanDevice*, const Swapchain::Descriptor&);

inline uint32_t width() const override { return m_extent.width; }
inline uint32_t height() const override { return m_extent.height; }

std::shared_ptr<Drawable> nextDrawable() override;

~VulkanSwapchain() override = default;

private:
const VulkanDevice* m_device;
vk::Extent2D m_extent;

vk::SwapchainKHR* m_vkSwapchain;
std::vector<std::shared_ptr<SwapchainImage>> m_swapchainImages;
Expand Down