Midnight Graphics
Create Fast and Simple Graphics in C++
RenderFrame.hpp
1 #pragma once
2 
3 #include <Def.hpp>
4 
5 #include "Mesh.hpp"
6 #include "Buffer.hpp"
7 #include "Image.hpp"
8 
9 namespace mn::Graphics
10 {
11  struct Window;
12  struct FrameData;
13  struct Pipeline;
14  struct Descriptor;
15 
16  // [x] Remove any `const T&` arguments, replace with std::shared_ptr<T>
17  // [x] Store the passed in pointers in an std::vector<std::shared_ptr<void>> in the frame_data
18  // [x] Add `.release()` function to frame_data that clears this vector (call it from the Window::startFrame method)
19  // [x] Add multiple color attachments to image
20  // [ ] Pass optional image into startRender() (no passed in image defaults to given)
21  // [x] Add explicit binding methods
22  // [x] Require descriptor set std::shared_ptr in pipeline
23 
24  struct RenderFrame
25  {
26  friend struct Window;
27 
28  const uint32_t image_index;
29  std::shared_ptr<Image> image;
30 
31  MN_SYMBOL void startRender(std::optional<std::shared_ptr<Image>> image = std::nullopt);
32  MN_SYMBOL void endRender();
33 
34  MN_SYMBOL void clear(std::tuple<float, float, float> color, float alpha = 1.f, std::optional<std::shared_ptr<Image>> image = std::nullopt, int attachment_index = -1) const;
35 
36  MN_SYMBOL void setPushConstant(const Pipeline& pipeline, const void* data) const;
37  template<typename T>
38  void setPushConstant(const Pipeline& pipeline, const T& value) const
39  {
40  setPushConstant(pipeline, reinterpret_cast<const void*>(&value));
41  }
42 
43  MN_SYMBOL void blit(const Image::Attachment& source, const Image::Attachment& destination) const;
44 
45  MN_SYMBOL void bind(const std::shared_ptr<Pipeline>& pipeline) const;
46 
47  // Does not bind pipeline
48  MN_SYMBOL void bind(uint32_t set_index, const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Descriptor>& descriptor) const;
49 
50  MN_SYMBOL void draw(uint32_t vertices, uint32_t instances = 1) const;
51  MN_SYMBOL void draw(const std::shared_ptr<Buffer>& buffer, uint32_t instances = 1) const;
52  MN_SYMBOL void draw(const std::shared_ptr<Mesh>& mesh, uint32_t instances = 1) const;
53  MN_SYMBOL void drawIndexed(
54  const std::shared_ptr<Buffer>& buffer,
55  const std::shared_ptr<TypeBuffer<uint32_t>>& indices,
56  uint32_t instances = 1,
57  uint32_t index_offset = 0,
58  std::optional<std::size_t> index_count = std::nullopt) const;
59 
60  MN_SYMBOL void draw(const std::shared_ptr<Pipeline>& pipeline, uint32_t vertices, uint32_t instances = 1) const;
61  MN_SYMBOL void draw(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Buffer>& buffer, uint32_t instances = 1) const;
62  MN_SYMBOL void draw(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Mesh>& mesh, uint32_t instances = 1) const;
63 
64  MN_SYMBOL void drawIndexed(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Buffer>& buffer, const std::shared_ptr<TypeBuffer<uint32_t>>& indices, uint32_t instances = 1) const;
65 
66  private:
67  RenderFrame(uint32_t i, std::shared_ptr<Image> im) : image_index(i), image(im) { }
68 
69  std::shared_ptr<FrameData> frame_data;
70  };
71 }
Definition: Image.hpp:21
Definition: Pipeline.hpp:64
Definition: RenderFrame.hpp:25
Definition: Buffer.hpp:40
Definition: Window.hpp:37