libdonut  2.3.2
Application framework for cross-platform game development in C++20
Framebuffer.hpp
Go to the documentation of this file.
1 #ifndef DONUT_GRAPHICS_FRAMEBUFFER_HPP
2 #define DONUT_GRAPHICS_FRAMEBUFFER_HPP
3 
4 #include <donut/UniqueHandle.hpp>
6 
7 namespace donut::graphics {
8 
9 class Texture; // Forward declaration, to avoid including Texture.hpp.
10 class Window; // Forward declaration, to avoid a circular include of Window.hpp.
11 
15 class Framebuffer {
16 public:
22  public:
24 
29 
30  private:
31  friend Framebuffer;
32 
33  [[nodiscard]] TextureAttachment(Framebuffer& framebuffer, Texture& texture);
34 
35  Framebuffer& framebuffer;
36  };
37 
44 
56  [[nodiscard]] TextureAttachment attachTexture2D(Texture& texture) {
57  return TextureAttachment{*this, texture};
58  }
59 
70  [[nodiscard]] Handle get() const noexcept {
71  return fbo.get();
72  }
73 
74 private:
75  friend Window;
76 
77  explicit Framebuffer(Handle handle) noexcept
78  : fbo(handle) {}
79 
80  struct FramebufferDeleter {
81  void operator()(Handle handle) const noexcept;
82  };
83 
84  UniqueHandle<Handle, FramebufferDeleter> fbo{};
85 };
86 
87 } // namespace donut::graphics
88 
89 #endif
constexpr Handle get() const noexcept
Get the value of the underlying resource handle.
Definition: UniqueHandle.hpp:152
Scope guard type representing an active texture attachment to a framebuffer that automatically detach...
Definition: Framebuffer.hpp:21
TextureAttachment(TextureAttachment &&)=delete
TextureAttachment(const TextureAttachment &)=delete
TextureAttachment & operator=(const TextureAttachment &)=delete
TextureAttachment & operator=(TextureAttachment &&)=delete
Unique resource handle with exclusive ownership of a GPU framebuffer.
Definition: Framebuffer.hpp:15
Framebuffer()
Create a new GPU framebuffer resource.
TextureAttachment attachTexture2D(Texture &texture)
Attach a 2D texture to the color attachment of the framebuffer for drawing to.
Definition: Framebuffer.hpp:56
Handle get() const noexcept
Get an opaque handle to the GPU representation of the framebuffer.
Definition: Framebuffer.hpp:70
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configurati...
Definition: Texture.hpp:75
Graphical window that can be rendered to.
Definition: Window.hpp:81
Definition: Buffer.hpp:7
std::uint32_t Handle
Generic GPU resource handle.
Definition: Handle.hpp:11