Open3D (C++ API)  0.18.0+252c867
ImguiFilamentBridge.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 // Altered from Filament's ImGuiHelper.cpp
8 // Filament code is from somewhere close to v1.4.3 and is:
9 /*
10  * Copyright (C) 2018 The Android Open Source Project
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24 
25 #pragma once
26 
27 // 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags
28 // 4146: PixelBufferDescriptor assert unsigned is positive before subtracting
29 // but MSVC can't figure that out.
30 // 4293: Filament's utils/algorithm.h utils::details::clz() does strange
31 // things with MSVC. Somehow sizeof(unsigned int) > 4, but its size is
32 // 32 so that x >> 32 gives a warning. (Or maybe the compiler can't
33 // determine the if statement does not run.)
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable : 4068 4146 4293)
37 #endif // _MSC_VER
38 
39 #include <filament/Engine.h>
40 #include <filament/IndexBuffer.h>
41 #include <filament/Material.h>
42 #include <filament/MaterialInstance.h>
43 #include <filament/Texture.h>
44 #include <filament/VertexBuffer.h>
45 #include <filament/View.h>
46 
47 #ifdef _MSC_VER
48 #pragma warning(pop)
49 #endif // _MSC_VER
50 
51 #include <cstddef> // <filament/Engine> recursive includes needs this, std::size_t especially
52 #include <memory>
53 
54 struct ImDrawData;
55 
56 namespace open3d {
57 
58 namespace visualization {
59 namespace rendering {
60 class FilamentRenderer;
61 }
62 } // namespace visualization
63 
64 namespace visualization {
65 namespace gui {
66 
67 struct Size;
68 class Window;
69 
70 // Translates ImGui's draw commands into Filament primitives, textures, vertex
71 // buffers, etc. Creates a UI-specific Scene object and populates it with a
72 // Renderable. Does not handle event processing; clients can simply call
73 // ImGui::GetIO() directly and set the mouse state.
75 public:
77  const Size& window_size);
79 
80  // Helper method called after resolving fontPath; public so fonts can be
81  // added by caller. Requires the appropriate ImGuiContext to be current
82  void CreateAtlasTextureAlpha8(unsigned char* pixels,
83  int width,
84  int height,
85  int bytes_per_px);
86 
87  // This populates the Filament View. Clients are responsible for
88  // rendering the View. This should be called on every frame, regardless of
89  // whether the Renderer wants to skip or not.
90  void Update(ImDrawData* imguiData);
91 
92  void OnWindowResized(const Window& window);
93 
94 private:
95  void CreateBuffers(size_t num_required_buffers);
96  void PopulateVertexData(size_t buffer_index,
97  size_t vb_size_in_bytes,
98  void* vb_data,
99  size_t ib_size_in_bytes,
100  void* ib_data);
101  void CreateVertexBuffer(size_t buffer_index, size_t capacity);
102  void CreateIndexBuffer(size_t buffer_index, size_t capacity);
103  void SyncThreads();
104 
105 private:
106  struct Impl;
107  std::unique_ptr<Impl> impl_;
108 };
109 
110 } // namespace gui
111 } // namespace visualization
112 } // namespace open3d
Definition: ImguiFilamentBridge.h:74
void Update(ImDrawData *imguiData)
Definition: ImguiFilamentBridge.cpp:271
~ImguiFilamentBridge()
Definition: ImguiFilamentBridge.cpp:211
ImguiFilamentBridge(visualization::rendering::FilamentRenderer *renderer, const Size &window_size)
Definition: ImguiFilamentBridge.cpp:150
void OnWindowResized(const Window &window)
Definition: ImguiFilamentBridge.cpp:370
void CreateAtlasTextureAlpha8(unsigned char *pixels, int width, int height, int bytes_per_px)
Definition: ImguiFilamentBridge.cpp:185
Definition: Window.h:30
int width
Definition: FilePCD.cpp:52
int height
Definition: FilePCD.cpp:53
Definition: PinholeCameraIntrinsic.cpp:16
Definition: ImguiFilamentBridge.cpp:129