Open3D (C++ API)
FilamentRenderer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2019 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
30 
31 #include <filament/utils/Entity.h>
32 #include <memory>
33 #include <unordered_map>
34 #include <unordered_set>
35 
36 namespace filament {
37 class Engine;
38 class Renderer;
39 class Scene;
40 class SwapChain;
41 class VertexBuffer;
42 } // namespace filament
43 
44 namespace open3d {
45 namespace visualization {
46 
47 class FilamentMaterialModifier;
48 class FilamentRenderToBuffer;
49 class FilamentResourceManager;
50 class FilamentScene;
51 class FilamentView;
52 
53 class FilamentRenderer : public Renderer {
54 public:
55  FilamentRenderer(filament::Engine& engine,
56  void* native_drawable,
57  FilamentResourceManager& resource_mgr);
58  ~FilamentRenderer() override;
59 
60  SceneHandle CreateScene() override;
61  Scene* GetScene(const SceneHandle& id) const override;
62  void DestroyScene(const SceneHandle& id) override;
63 
64  void UpdateSwapChain() override;
65 
66  void BeginFrame() override;
67  void Draw() override;
68  void EndFrame() override;
69 
70  MaterialHandle AddMaterial(const ResourceLoadRequest& request) override;
71  MaterialInstanceHandle AddMaterialInstance(
72  const MaterialHandle& material) override;
73  MaterialInstanceHandle AddMaterialInstance(
74  const geometry::TriangleMesh::Material& material) override;
75  MaterialModifier& ModifyMaterial(const MaterialHandle& id) override;
76  MaterialModifier& ModifyMaterial(const MaterialInstanceHandle& id) override;
77  void RemoveMaterialInstance(const MaterialInstanceHandle& id) override;
78 
79  TextureHandle AddTexture(const ResourceLoadRequest& request) override;
80  TextureHandle AddTexture(
81  const std::shared_ptr<geometry::Image>& image) override;
82  void RemoveTexture(const TextureHandle& id) override;
83 
84  IndirectLightHandle AddIndirectLight(
85  const ResourceLoadRequest& request) override;
86  void RemoveIndirectLight(const IndirectLightHandle& id) override;
87 
88  SkyboxHandle AddSkybox(const ResourceLoadRequest& request) override;
89  void RemoveSkybox(const SkyboxHandle& id) override;
90 
91  std::shared_ptr<visualization::RenderToBuffer> CreateBufferRenderer()
92  override;
93 
94  // Removes scene from scenes list and draws it last
95  // WARNING: will destroy previous gui scene if there was any
96  void ConvertToGuiScene(const SceneHandle& id);
97  FilamentScene* GetGuiScene() const { return gui_scene_.get(); }
98 
99 private:
101 
102  filament::Engine& engine_;
103  filament::Renderer* renderer_ = nullptr;
104  filament::SwapChain* swap_chain_ = nullptr;
105 
106  std::unordered_map<REHandle_abstract, std::unique_ptr<FilamentScene>>
107  scenes_;
108  std::unique_ptr<FilamentScene> gui_scene_;
109 
110  std::unique_ptr<FilamentMaterialModifier> materials_modifier_;
111  FilamentResourceManager& resource_mgr_;
112 
113  std::unordered_set<FilamentRenderToBuffer*> buffer_renderers_;
114 
115  bool frame_started_ = false;
116 
117  void OnBufferRenderDestroyed(FilamentRenderToBuffer* render);
118 };
119 
120 } // namespace visualization
121 } // namespace open3d
FilamentScene * GetGuiScene() const
Definition: FilamentRenderer.h:97
Definition: MaterialModifier.h:116
Definition: FilamentResourceManager.h:59
Definition: TriangleMesh.h:746
Definition: Renderer.h:64
Definition: FilamentRenderToBuffer.h:45
Definition: Open3DViewer.h:29
Definition: RendererHandle.h:110
Definition: FilamentRenderer.h:53
Definition: FilamentScene.h:53
Definition: FilamentCamera.h:31
Definition: Scene.h:47