vsgImGui  0.0.0
VulkanSceneGraph 3rd party data integration library
RenderImGui.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2021 Don Burns, Roland Hill and Robert Osfield.
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of
8 this software and associated documentation files (the "Software"), to deal in
9 the Software without restriction, including without limitation the rights to
10 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 the Software, and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24 </editor-fold> */
25 
26 #include <functional>
27 
28 #include <vsg/app/Window.h>
29 #include <vsg/commands/ClearAttachments.h>
30 #include <vsg/nodes/Group.h>
31 #include <vsg/vk/DescriptorPool.h>
32 
33 #include <vsgImGui/Export.h>
34 #include <vsgImGui/imgui.h>
35 
36 namespace vsgImGui
37 {
38 
39  class VSGIMGUI_DECLSPEC RenderImGui : public vsg::Inherit<vsg::Group, RenderImGui>
40  {
41  public:
42  RenderImGui(const vsg::ref_ptr<vsg::Window>& window, bool useClearAttachments = false);
43 
44  RenderImGui(vsg::ref_ptr<vsg::Device> device, uint32_t queueFamily,
45  vsg::ref_ptr<vsg::RenderPass> renderPass,
46  uint32_t minImageCount, uint32_t imageCount,
47  VkExtent2D imageSize, bool useClearAttachments = false);
48 
49  template<typename... Args>
50  RenderImGui(const vsg::ref_ptr<vsg::Window>& window, Args&... args) :
51  RenderImGui(window, false)
52  {
53  (add(args), ...);
54  }
55 
56  template<typename... Args>
57  RenderImGui(const vsg::ref_ptr<vsg::Window>& window, Args&... args, bool useClearAttachments) :
58  RenderImGui(window, useClearAttachments)
59  {
60  (add(args), ...);
61  }
62 
63  using Component = std::function<bool()>;
64  using Components = std::list<Component>;
65 
68  void add(const Component& component);
69 
70  Components& getComponents() { return _components; }
71  const Components& getComponents() const { return _components; }
72 
73  void accept(vsg::RecordTraversal& rt) const override;
74 
75  private:
76  virtual ~RenderImGui();
77 
78  vsg::ref_ptr<vsg::Device> _device;
79  uint32_t _queueFamily;
80  vsg::ref_ptr<vsg::Queue> _queue;
81  vsg::ref_ptr<vsg::DescriptorPool> _descriptorPool;
82  Components _components;
83 
84  vsg::ref_ptr<vsg::ClearAttachments> _clearAttachments;
85 
86  void _init(const vsg::ref_ptr<vsg::Window>& window, bool useClearAttachments);
87  void _init(vsg::ref_ptr<vsg::Device> device, uint32_t queueFamily,
88  vsg::ref_ptr<vsg::RenderPass> renderPass,
89  uint32_t minImageCount, uint32_t imageCount,
90  VkExtent2D imageSize, bool useClearAttachments);
91  void _uploadFonts();
92  };
93 
94 } // namespace vsgImGui
95 
96 EVSG_type_name(vsgImGui::RenderImGui);
Definition: RenderImGui.h:40
void add(const Component &component)