1 | #pragma once |
2 | |
3 | #include "taichi/ui/utils/utils.h" |
4 | |
5 | #ifndef IMGUI_IMPL_VULKAN_NO_PROTOTYPES |
6 | #define IMGUI_IMPL_VULKAN_NO_PROTOTYPES |
7 | #endif |
8 | |
9 | #include <imgui.h> |
10 | #ifdef ANDROID |
11 | #include <imgui_impl_android.h> |
12 | #else |
13 | #include <imgui_impl_glfw.h> |
14 | #endif |
15 | #include <imgui_impl_vulkan.h> |
16 | #include "taichi/ui/backends/vulkan/app_context.h" |
17 | #include "taichi/ui/common/gui_base.h" |
18 | #include "taichi/rhi/vulkan/vulkan_device.h" |
19 | |
20 | namespace taichi::ui { |
21 | |
22 | namespace vulkan { |
23 | |
24 | class TI_DLL_EXPORT Gui final : public GuiBase { |
25 | public: |
26 | Gui(AppContext *app_context, SwapChain *swap_chain, TaichiWindow *window); |
27 | ~Gui() override; |
28 | |
29 | void init_render_resources(VkRenderPass render_pass); |
30 | void cleanup_render_resources(); |
31 | |
32 | void begin(const std::string &name, |
33 | float x, |
34 | float y, |
35 | float width, |
36 | float height) override; |
37 | void end() override; |
38 | void text(const std::string &text) override; |
39 | void text(const std::string &text, glm::vec3 color) override; |
40 | bool checkbox(const std::string &name, bool old_value) override; |
41 | int slider_int(const std::string &name, |
42 | int old_value, |
43 | int minimum, |
44 | int maximum) override; |
45 | float slider_float(const std::string &name, |
46 | float old_value, |
47 | float minimum, |
48 | float maximum) override; |
49 | // TODO: consider renaming this? |
50 | glm::vec3 color_edit_3(const std::string &name, glm::vec3 old_value) override; |
51 | bool button(const std::string &text) override; |
52 | |
53 | void draw(taichi::lang::CommandList *cmd_list); |
54 | |
55 | void prepare_for_next_frame(); |
56 | |
57 | VkRenderPass render_pass() { |
58 | return render_pass_; |
59 | } |
60 | |
61 | bool is_empty(); |
62 | |
63 | private: |
64 | bool is_empty_; |
65 | AppContext *app_context_; |
66 | SwapChain *swap_chain_; |
67 | |
68 | VkRenderPass render_pass_{VK_NULL_HANDLE}; |
69 | |
70 | VkDescriptorPool descriptor_pool_; |
71 | |
72 | void create_descriptor_pool(); |
73 | |
74 | float abs_x(float x); |
75 | |
76 | float abs_y(float y); |
77 | |
78 | bool initialized(); |
79 | }; |
80 | |
81 | } // namespace vulkan |
82 | |
83 | } // namespace taichi::ui |
84 | |