Foundation
Loading...
Searching...
No Matches
Swapchain.hpp
Go to the documentation of this file.
1#pragma once
2#include "Common.hpp"
3namespace Foundation::RHI {
4 class RHIDevice;
5 class RHITexture;
6 class RHIDeviceSemaphore;
7 class RHIDeviceFence;
8 class RHISurface;
9 enum class RHISwapchainResult {
10 Success,
12 Timeout,
17 Error
18 };
19 // Presentable image was acquired/presented; Suboptimal still warrants recreate when convenient.
20 [[nodiscard]] inline bool RHISwapchainResultMayPresent(RHISwapchainResult result)
21 {
23 }
25 // V-Sync
26 Fifo,
27 // N buffering
28 Mailbox,
29 // No V-Sync (tearing allowed)
31 };
32 class RHISwapchain : public RHIObject {
33 protected:
35 public:
37 // Name for the swap chain, used for debugging purposes.
40 // Swapchain buffer sizes.
42 // Min number of buffers in the swap chain. i.e. double buffering = 2, triple buffering = 3, etc.
43 // Driver may create more buffers than requested.
45 // Present mode for the swap chain.
47 // The surface to present to.
50 [[nodiscard]] virtual Span<RHITexture* const> GetImages() const = 0;
51 RHISwapchain(RHIDevice const& device, SwapchainDesc const& desc) : mDevice(device), mDesc(desc) {}
53 uint64_t timeout_ns,
56 uint32_t& imageIndex
57 ) = 0;
58 [[nodiscard]] virtual RHIExtent2D GetExtents() const = 0;
59 [[nodiscard]] float GetAspectRatio() const {
60 auto xy = GetExtents();
61 return static_cast<float>(xy.x) / static_cast<float>(xy.y);
62 }
63
64 virtual void DebugSetObjectName(const char* name) = 0;
65 };
71}
#define ENUM_NAME_CONV_BEGIN(T)
Defines convince to_string() method and format_as() [fmt] for the respective enum class Example usage...
Definition Enums.hpp:82
#define ENUM_NAME(E)
Definition Enums.hpp:93
Definition Device.hpp:246
Handle type for RHI Objects.
Definition Details.hpp:43
Base class for all RHI objects.
Definition Details.hpp:17
Definition Swapchain.hpp:32
const RHIDevice & mDevice
Definition Swapchain.hpp:34
RHISwapchain(RHIDevice const &device, SwapchainDesc const &desc)
Definition Swapchain.hpp:51
virtual RHISwapchainResult GetNextImage(uint64_t timeout_ns, RHIDeviceHandle< RHIDeviceSemaphore > semaphore, RHIDeviceHandle< RHIDeviceFence > fence, uint32_t &imageIndex)=0
virtual Span< RHITexture *const > GetImages() const =0
struct Foundation::RHI::RHISwapchain::SwapchainDesc mDesc
virtual void DebugSetObjectName(const char *name)=0
virtual RHIExtent2D GetExtents() const =0
float GetAspectRatio() const
Definition Swapchain.hpp:59
std::span< T > Span
Alias for std::span
Definition Container.hpp:62
Low-level Rendering Hardware Interface (RHI) abstractions.
Definition Application.hpp:3
RHISwapchainPresentMode
Definition Swapchain.hpp:24
RHIColorSpace
Definition Common.hpp:131
RHIResourceFormat
Definition Common.hpp:34
bool RHISwapchainResultMayPresent(RHISwapchainResult result)
Definition Swapchain.hpp:20
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
RHISwapchainResult
Definition Swapchain.hpp:9
RHIDeviceHandle< RHISurface > surface
Definition Swapchain.hpp:48
uint32_t minBufferCount
Definition Swapchain.hpp:44
RHIResourceFormat format
Definition Swapchain.hpp:38
RHIColorSpace colorSpace
Definition Swapchain.hpp:39
RHISwapchainPresentMode presentMode
Definition Swapchain.hpp:46
RHIExtent2D extents
Definition Swapchain.hpp:41