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 "taichi/ui/utils/utils.h" |
16 | #include <memory> |
17 | |
18 | #include "taichi/ui/backends/vulkan/swap_chain.h" |
19 | #include "taichi/ui/backends/vulkan/app_context.h" |
20 | #include "taichi/ui/backends/vulkan/canvas.h" |
21 | #include "taichi/ui/backends/vulkan/renderer.h" |
22 | #include "taichi/ui/common/window_base.h" |
23 | #include "taichi/ui/backends/vulkan/gui.h" |
24 | #include "taichi/program/ndarray.h" |
25 | |
26 | namespace taichi::lang { |
27 | class Program; |
28 | } // namespace taichi::lang |
29 | |
30 | namespace taichi::ui { |
31 | |
32 | namespace vulkan { |
33 | |
34 | class Window final : public WindowBase { |
35 | public: |
36 | Window(lang::Program *prog, const AppConfig &config); |
37 | |
38 | void show() override; |
39 | CanvasBase *get_canvas() override; |
40 | GuiBase *gui() override; |
41 | |
42 | std::pair<uint32_t, uint32_t> get_window_shape() override; |
43 | |
44 | void write_image(const std::string &filename) override; |
45 | |
46 | void copy_depth_buffer_to_ndarray( |
47 | const taichi::lang::Ndarray &depth_arr) override; |
48 | |
49 | std::vector<uint32_t> &get_image_buffer(uint32_t &w, uint32_t &h) override; |
50 | |
51 | ~Window() override; |
52 | |
53 | private: |
54 | std::unique_ptr<Canvas> canvas_; |
55 | std::unique_ptr<Gui> gui_; |
56 | std::unique_ptr<Renderer> renderer_; |
57 | bool drawn_frame_{false}; |
58 | |
59 | private: |
60 | void init(lang::Program *prog, const AppConfig &config); |
61 | |
62 | void prepare_for_next_frame(); |
63 | |
64 | void draw_frame(); |
65 | |
66 | void present_frame(); |
67 | |
68 | void resize(); |
69 | |
70 | static void framebuffer_resize_callback(GLFWwindow *glfw_window_, |
71 | int width, |
72 | int height); |
73 | }; |
74 | |
75 | } // namespace vulkan |
76 | |
77 | } // namespace taichi::ui |
78 |