1 | #pragma once |
---|---|
2 | |
3 | #include <iostream> |
4 | #include <fstream> |
5 | #include <stdexcept> |
6 | #include <algorithm> |
7 | #include <chrono> |
8 | #include <vector> |
9 | #include <cstring> |
10 | #include <cstdlib> |
11 | #include <cstdint> |
12 | #include <array> |
13 | #include <optional> |
14 | #include <set> |
15 | #include <memory> |
16 | |
17 | #include "taichi/ui/utils/utils.h" |
18 | #include "taichi/ui/backends/vulkan/vertex.h" |
19 | #include "taichi/ui/backends/vulkan/scene.h" |
20 | #include "taichi/ui/backends/vulkan/app_context.h" |
21 | #include "taichi/ui/backends/vulkan/swap_chain.h" |
22 | #include "taichi/ui/backends/vulkan/renderable.h" |
23 | #include "taichi/ui/common/canvas_base.h" |
24 | |
25 | #include "gui.h" |
26 | |
27 | #include "renderables/set_image.h" |
28 | #include "renderables/triangles.h" |
29 | #include "renderables/mesh.h" |
30 | #include "renderables/particles.h" |
31 | #include "renderables/circles.h" |
32 | #include "renderables/lines.h" |
33 | #include "renderables/scene_lines.h" |
34 | |
35 | namespace taichi::lang { |
36 | class Program; |
37 | } // namespace taichi::lang |
38 | |
39 | namespace taichi::ui { |
40 | |
41 | namespace vulkan { |
42 | |
43 | class TI_DLL_EXPORT Renderer { |
44 | public: |
45 | void init(lang::Program *prog, TaichiWindow *window, const AppConfig &config); |
46 | ~Renderer(); |
47 | |
48 | void prepare_for_next_frame(); |
49 | |
50 | void set_background_color(const glm::vec3 &color); |
51 | |
52 | void set_image(const SetImageInfo &info); |
53 | |
54 | void set_image(taichi::lang::Texture *tex); |
55 | |
56 | void triangles(const TrianglesInfo &info); |
57 | |
58 | void circles(const CirclesInfo &info); |
59 | |
60 | void lines(const LinesInfo &info); |
61 | |
62 | void mesh(const MeshInfo &info, Scene *scene); |
63 | |
64 | void particles(const ParticlesInfo &info, Scene *scene); |
65 | |
66 | void scene_lines(const SceneLinesInfo &info, Scene *scene); |
67 | |
68 | void scene(Scene *scene); |
69 | |
70 | void draw_frame(Gui *gui); |
71 | |
72 | const AppContext &app_context() const; |
73 | AppContext &app_context(); |
74 | const SwapChain &swap_chain() const; |
75 | SwapChain &swap_chain(); |
76 | |
77 | taichi::lang::StreamSemaphore get_render_complete_semaphore(); |
78 | |
79 | private: |
80 | glm::vec3 background_color_ = glm::vec3(0.f, 0.f, 0.f); |
81 | |
82 | AppContext app_context_; |
83 | SwapChain swap_chain_; |
84 | |
85 | std::vector<std::unique_ptr<Renderable>> renderables_; |
86 | std::vector<Renderable *> render_queue_; |
87 | |
88 | taichi::lang::StreamSemaphore render_complete_semaphore_{nullptr}; |
89 | |
90 | template <typename T> |
91 | T *get_renderable_of_type(VertexAttributes vbo_attrs); |
92 | }; |
93 | |
94 | } // namespace vulkan |
95 | |
96 | } // namespace taichi::ui |
97 |