ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ImguiFilamentBridge.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags
11 // 4146: PixelBufferDescriptor assert unsigned is positive before subtracting
12 // but MSVC can't figure that out.
13 // 4293: Filament's utils/algorithm.h utils::details::clz() does strange
14 // things with MSVC. Somehow sizeof(unsigned int) > 4, but its size is
15 // 32 so that x >> 32 gives a warning. (Or maybe the compiler can't
16 // determine the if statement does not run.)
17 #ifdef _MSC_VER
18 #pragma warning(push)
19 #pragma warning(disable : 4068 4146 4293)
20 #endif // _MSC_VER
21 
22 #include <filament/Engine.h>
23 #include <filament/IndexBuffer.h>
24 #include <filament/Material.h>
25 #include <filament/MaterialInstance.h>
26 #include <filament/Texture.h>
27 #include <filament/VertexBuffer.h>
28 #include <filament/View.h>
29 
30 #ifdef _MSC_VER
31 #pragma warning(pop)
32 #endif // _MSC_VER
33 
34 #include <cstddef> // <filament/Engine> recursive includes needs this, std::size_t especially
35 #include <memory>
36 
37 struct ImDrawData;
38 
39 namespace cloudViewer {
40 
41 namespace visualization {
42 namespace rendering {
43 class FilamentRenderer;
44 }
45 } // namespace visualization
46 
47 namespace visualization {
48 namespace gui {
49 
50 struct Size;
51 class Window;
52 
53 // Translates ImGui's draw commands into Filament primitives, textures, vertex
54 // buffers, etc. Creates a UI-specific Scene object and populates it with a
55 // Renderable. Does not handle event processing; clients can simply call
56 // ImGui::GetIO() directly and set the mouse state.
58 public:
60  const Size& window_size);
62 
63  // Helper method called after resolving fontPath; public so fonts can be
64  // added by caller. Requires the appropriate ImGuiContext to be current
65  void CreateAtlasTextureAlpha8(unsigned char* pixels,
66  int width,
67  int height,
68  int bytes_per_px);
69 
70  // This populates the Filament View. Clients are responsible for
71  // rendering the View. This should be called on every frame, regardless of
72  // whether the Renderer wants to skip or not.
73  void Update(ImDrawData* imguiData);
74 
75  void OnWindowResized(const Window& window);
76 
77 private:
78  void CreateBuffers(size_t num_required_buffers);
79  void PopulateVertexData(size_t buffer_index,
80  size_t vb_size_in_bytes,
81  void* vb_data,
82  size_t ib_size_in_bytes,
83  void* ib_data);
84  void CreateVertexBuffer(size_t buffer_index, size_t capacity);
85  void CreateIndexBuffer(size_t buffer_index, size_t capacity);
86  void SyncThreads();
87 
88 private:
89  struct Impl;
90  std::unique_ptr<Impl> impl_;
91 };
92 
93 } // namespace gui
94 } // namespace visualization
95 } // namespace cloudViewer
int width
int height
ImguiFilamentBridge(visualization::rendering::FilamentRenderer *renderer, const Size &window_size)
void CreateAtlasTextureAlpha8(unsigned char *pixels, int width, int height, int bytes_per_px)
Generic file read and write utility for python interface.