Midnight Graphics
Create Fast and Simple Graphics in C++
Image.hpp
1 #pragma once
2 
3 #include <Math.hpp>
4 
5 #include "ObjectHandle.hpp"
6 
7 namespace mn::Graphics
8 {
9  // Reformat this as image w/ attachments
10  // Then we can add has_attachment<>() function to determine if there's depth/stencil
11  struct ImageFactory;
12 
13  struct Image
14  {
15  enum Type
16  {
17  Color, DepthStencil
18  };
19 
20  struct Attachment
21  {
22  mn::handle_t handle, allocation, view;
23  u32 format;
24  Math::Vec2u size;
25 
26  // IF IMGUI
27  mn::handle_t imgui_ds;
28 
29  void destroy();
30 
31  template<Type T>
32  void rebuild(u32 format, Math::Vec2u size);
33  };
34 
35  enum Format : u32
36  {
37  DF32_SU8 = 130,
38  R8G8B8A8_UNORM = 37,
39  B8G8R8A8_UNORM = 44,
40  R16G16B16A16_SFLOAT = 97
41  };
42 
43  Image(const Image&) = delete;
44  Image(Image&&) = default;
45 
46  ~Image();
47 
48  bool hasDepthAttachment() const
49  {
50  return depth_attachment.has_value();
51  }
52 
53  const Attachment&
54  getDepthAttachment() const
55  {
56  return *depth_attachment;
57  }
58 
59  Attachment&
60  getDepthAttachment()
61  {
62  return *depth_attachment;
63  }
64 
65  const auto&
66  getColorAttachments() const
67  {
68  return color_attachments;
69  }
70 
71  auto&
72  getColorAttachments()
73  {
74  return color_attachments;
75  }
76 
77  private:
78  friend struct ImageFactory;
79 
80  Image() = default;
81 
82  std::vector<Attachment> color_attachments;
83  std::optional<Attachment> depth_attachment;
84  };
85 
86  struct ImageFactory
87  {
88  ImageFactory();
89 
90  template<Image::Type T>
92  addAttachment(u32 format, const Math::Vec2u& size);
93 
94  template<Image::Type T>
96  addImage(handle_t handle, u32 format, const Math::Vec2u& size);
97 
98  [[nodiscard]] Image&&
99  build();
100 
101  private:
102  std::unique_ptr<Image> image;
103  };
104 }
Definition: Image.hpp:87
Definition: Image.hpp:21
Definition: Image.hpp:14
Definition: Vector.hpp:12