Open3D (C++ API)
ImguiFilamentBridge.h
Go to the documentation of this file.
1 // Altered from Filament's ImGuiHelper.cpp
2 // Filament code is from somewhere close to v1.4.3 and is:
3 /*
4  * Copyright (C) 2018 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 // Open3D alterations are:
19 // ----------------------------------------------------------------------------
20 // - Open3D: www.open3d.org -
21 // ----------------------------------------------------------------------------
22 // The MIT License (MIT)
23 //
24 // Copyright (c) 2018 www.open3d.org
25 //
26 // Permission is hereby granted, free of charge, to any person obtaining a copy
27 // of this software and associated documentation files (the "Software"), to deal
28 // in the Software without restriction, including without limitation the rights
29 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30 // copies of the Software, and to permit persons to whom the Software is
31 // furnished to do so, subject to the following conditions:
32 //
33 // The above copyright notice and this permission notice shall be included in
34 // all copies or substantial portions of the Software.
35 //
36 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
42 // IN THE SOFTWARE.
43 // ----------------------------------------------------------------------------
44 
45 #pragma once
46 
47 #include <filament/Engine.h>
48 #include <filament/IndexBuffer.h>
49 #include <filament/Material.h>
50 #include <filament/MaterialInstance.h>
51 #include <filament/Texture.h>
52 #include <filament/VertexBuffer.h>
53 #include <filament/View.h>
54 #include <cstddef> // <filament/Engine> recursive includes needs this, std::size_t especially
55 #include <memory>
56 
57 struct ImDrawData;
58 
59 namespace open3d {
60 
61 namespace visualization {
62 class FilamentRenderer;
63 }
64 
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);
78  // The constructor creates its own Scene and places it in the given View.
79  ImguiFilamentBridge(filament::Engine* engine,
80  filament::Scene* scene,
81  filament::Material* uiblit_material);
83 
84  // Helper method called after resolving fontPath; public so fonts can be
85  // added by caller. Requires the appropriate ImGuiContext to be current
86  void CreateAtlasTextureAlpha8(unsigned char* pixels,
87  int width,
88  int height,
89  int bytes_per_px);
90 
91  // This populates the Filament View. Clients are responsible for
92  // rendering the View. This should be called on every frame, regardless of
93  // whether the Renderer wants to skip or not.
94  void Update(ImDrawData* imguiData);
95 
96  void OnWindowResized(const Window& window);
97 
98 private:
99  void CreateBuffers(size_t num_required_buffers);
100  void PopulateVertexData(size_t buffer_index,
101  size_t vb_size_in_bytes,
102  void* vb_data,
103  size_t ib_size_in_bytes,
104  void* ib_data);
105  void CreateVertexBuffer(size_t buffer_index, size_t capacity);
106  void CreateIndexBuffer(size_t buffer_index, size_t capacity);
107  void SyncThreads();
108 
109 private:
110  struct Impl;
111  std::unique_ptr<Impl> impl_;
112 };
113 
114 } // namespace gui
115 } // namespace open3d
Definition: ImguiFilamentBridge.cpp:184
Definition: Gui.h:40
Definition: Window.h:49
Definition: ImguiFilamentBridge.h:74
Definition: Open3DViewer.h:29
int height
Definition: FilePCD.cpp:70
Definition: FilamentRenderer.h:53
int width
Definition: FilePCD.cpp:69