Open3D (C++ API)  0.12.0
Renderer.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 
31 
32 namespace open3d {
33 
34 namespace geometry {
35 class Image;
36 }
37 
38 namespace visualization {
39 namespace rendering {
40 
41 class RenderToBuffer;
42 class Scene;
43 class View;
44 
46 public:
47  using ErrorCallback = std::function<void(
48  const ResourceLoadRequest&, const uint8_t, const std::string&)>;
49 
50  ResourceLoadRequest(const void* data, size_t data_size);
51  explicit ResourceLoadRequest(const char* path);
52 
53  ResourceLoadRequest(const void* data,
54  size_t data_size,
55  ErrorCallback error_callback);
56  ResourceLoadRequest(const char* path, ErrorCallback error_callback);
57 
58  const void* data_;
59  const size_t data_size_;
60  const std::string path_;
62 };
63 
64 class Renderer {
65 public:
66  virtual ~Renderer() = default;
67 
68  virtual SceneHandle CreateScene() = 0;
69  virtual Scene* GetScene(const SceneHandle& id) const = 0;
70  virtual void DestroyScene(const SceneHandle& id) = 0;
71 
72  virtual void SetClearColor(const Eigen::Vector4f& color) = 0;
73  virtual void SetPreserveBuffer(bool preserve) = 0;
74  virtual void UpdateSwapChain() = 0;
75 
76  virtual void EnableCaching(bool enable) = 0;
77  virtual void BeginFrame() = 0;
78  virtual void Draw() = 0;
79  virtual void EndFrame() = 0;
80 
81  virtual MaterialHandle AddMaterial(const ResourceLoadRequest& request) = 0;
82  virtual MaterialInstanceHandle AddMaterialInstance(
83  const MaterialHandle& material) = 0;
84  virtual MaterialModifier& ModifyMaterial(const MaterialHandle& id) = 0;
85  virtual MaterialModifier& ModifyMaterial(
86  const MaterialInstanceHandle& id) = 0;
87  virtual void RemoveMaterialInstance(const MaterialInstanceHandle& id) = 0;
88 
89  virtual TextureHandle AddTexture(const ResourceLoadRequest& request,
90  bool srgb = false) = 0;
91  virtual TextureHandle AddTexture(
92  const std::shared_ptr<geometry::Image>& image,
93  bool srgb = false) = 0;
94  virtual void RemoveTexture(const TextureHandle& id) = 0;
95 
96  virtual IndirectLightHandle AddIndirectLight(
97  const ResourceLoadRequest& request) = 0;
98  virtual void RemoveIndirectLight(const IndirectLightHandle& id) = 0;
99 
100  virtual SkyboxHandle AddSkybox(const ResourceLoadRequest& request) = 0;
101  virtual void RemoveSkybox(const SkyboxHandle& id) = 0;
102 
103  virtual std::shared_ptr<RenderToBuffer> CreateBufferRenderer() = 0;
104 
105  void RenderToImage(
106  View* view,
107  Scene* scene,
108  std::function<void(std::shared_ptr<geometry::Image>)> cb);
109 };
110 
111 } // namespace rendering
112 } // namespace visualization
113 } // namespace open3d
void Draw(const std::vector< std::shared_ptr< geometry::Geometry3D >> &geometries, const std::string &window_name, int width, int height, const std::vector< DrawAction > &actions)
Definition: Draw.cpp:54
ErrorCallback error_callback_
Definition: Renderer.h:61
Definition: MaterialModifier.h:126
const size_t data_size_
Definition: Renderer.h:59
const void * data_
Definition: Renderer.h:58
std::function< void(const ResourceLoadRequest &, const uint8_t, const std::string &)> ErrorCallback
Definition: Renderer.h:48
math::float4 color
Definition: LineSetBuffers.cpp:64
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:259
const std::string path_
Definition: Renderer.h:60
Definition: PinholeCameraIntrinsic.cpp:35
const char const char value recording_handle imu_sample recording_handle uint8_t data
Definition: K4aPlugin.cpp:274