Open3D (C++ API)
SimpleShader.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 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 
29 #include <Eigen/Core>
30 #include <vector>
31 
33 
34 namespace open3d {
35 namespace visualization {
36 
37 namespace glsl {
38 
39 class SimpleShader : public ShaderWrapper {
40 public:
41  ~SimpleShader() override { Release(); }
42 
43 protected:
44  SimpleShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
45 
46 protected:
47  bool Compile() final;
48  void Release() final;
49  bool BindGeometry(const geometry::Geometry &geometry,
50  const RenderOption &option,
51  const ViewControl &view) final;
52  bool RenderGeometry(const geometry::Geometry &geometry,
53  const RenderOption &option,
54  const ViewControl &view) final;
55  void UnbindGeometry() final;
56 
57 protected:
58  virtual bool PrepareRendering(const geometry::Geometry &geometry,
59  const RenderOption &option,
60  const ViewControl &view) = 0;
61  virtual bool PrepareBinding(const geometry::Geometry &geometry,
62  const RenderOption &option,
63  const ViewControl &view,
64  std::vector<Eigen::Vector3f> &points,
65  std::vector<Eigen::Vector3f> &colors) = 0;
66 
67 protected:
70  GLuint vertex_color_;
72  GLuint MVP_;
73 };
74 
76 public:
77  SimpleShaderForPointCloud() : SimpleShader("SimpleShaderForPointCloud") {}
78 
79 protected:
80  bool PrepareRendering(const geometry::Geometry &geometry,
81  const RenderOption &option,
82  const ViewControl &view) final;
83  bool PrepareBinding(const geometry::Geometry &geometry,
84  const RenderOption &option,
85  const ViewControl &view,
86  std::vector<Eigen::Vector3f> &points,
87  std::vector<Eigen::Vector3f> &colors) final;
88 };
89 
91 public:
92  SimpleShaderForLineSet() : SimpleShader("SimpleShaderForLineSet") {}
93 
94 protected:
95  bool PrepareRendering(const geometry::Geometry &geometry,
96  const RenderOption &option,
97  const ViewControl &view) final;
98  bool PrepareBinding(const geometry::Geometry &geometry,
99  const RenderOption &option,
100  const ViewControl &view,
101  std::vector<Eigen::Vector3f> &points,
102  std::vector<Eigen::Vector3f> &colors) final;
103 };
104 
106 public:
108  : SimpleShader("SimpleShaderForTriangleMesh") {}
109 
110 protected:
111  bool PrepareRendering(const geometry::Geometry &geometry,
112  const RenderOption &option,
113  const ViewControl &view) final;
114  bool PrepareBinding(const geometry::Geometry &geometry,
115  const RenderOption &option,
116  const ViewControl &view,
117  std::vector<Eigen::Vector3f> &points,
118  std::vector<Eigen::Vector3f> &colors) final;
119 };
120 
122 public:
124  : SimpleShader("SimpleShaderForVoxelGridLine") {}
125 
126 protected:
127  bool PrepareRendering(const geometry::Geometry &geometry,
128  const RenderOption &option,
129  const ViewControl &view) final;
130  bool PrepareBinding(const geometry::Geometry &geometry,
131  const RenderOption &option,
132  const ViewControl &view,
133  std::vector<Eigen::Vector3f> &points,
134  std::vector<Eigen::Vector3f> &colors) final;
135 };
136 
138 public:
140  : SimpleShader("SimpleShaderForVoxelGridFace") {}
141 
142 protected:
143  bool PrepareRendering(const geometry::Geometry &geometry,
144  const RenderOption &option,
145  const ViewControl &view) final;
146  bool PrepareBinding(const geometry::Geometry &geometry,
147  const RenderOption &option,
148  const ViewControl &view,
149  std::vector<Eigen::Vector3f> &points,
150  std::vector<Eigen::Vector3f> &colors) final;
151 };
152 
154 public:
155  SimpleShaderForOctreeLine() : SimpleShader("SimpleShaderForOctreeLine") {}
156 
157 protected:
158  bool PrepareRendering(const geometry::Geometry &geometry,
159  const RenderOption &option,
160  const ViewControl &view) final;
161  bool PrepareBinding(const geometry::Geometry &geometry,
162  const RenderOption &option,
163  const ViewControl &view,
164  std::vector<Eigen::Vector3f> &points,
165  std::vector<Eigen::Vector3f> &colors) final;
166 };
167 
169 public:
170  SimpleShaderForOctreeFace() : SimpleShader("SimpleShaderForOctreeFace") {}
171 
172 protected:
173  bool PrepareRendering(const geometry::Geometry &geometry,
174  const RenderOption &option,
175  const ViewControl &view) final;
176  bool PrepareBinding(const geometry::Geometry &geometry,
177  const RenderOption &option,
178  const ViewControl &view,
179  std::vector<Eigen::Vector3f> &points,
180  std::vector<Eigen::Vector3f> &colors) final;
181 };
182 
183 } // namespace glsl
184 
185 } // namespace visualization
186 } // namespace open3d
GLuint vertex_position_buffer_
Definition: SimpleShader.h:69
Definition: Geometry.h:32
bool Compile() final
Definition: SimpleShader.cpp:67
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: SimpleShader.cpp:116
GLuint vertex_color_buffer_
Definition: SimpleShader.h:71
SimpleShaderForLineSet()
Definition: SimpleShader.h:92
SimpleShaderForVoxelGridLine()
Definition: SimpleShader.h:123
Definition: ViewControl.h:38
GLuint vertex_color_
Definition: SimpleShader.h:70
void UnbindGeometry() final
Definition: SimpleShader.cpp:137
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: SimpleShader.cpp:84
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
SimpleShaderForTriangleMesh()
Definition: SimpleShader.h:107
GLuint vertex_position_
Definition: SimpleShader.h:68
Definition: SimpleShader.h:39
void Release() final
Definition: SimpleShader.cpp:79
Definition: RenderOption.h:36
SimpleShaderForOctreeFace()
Definition: SimpleShader.h:170
~SimpleShader() override
Definition: SimpleShader.h:41
virtual bool PrepareBinding(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view, std::vector< Eigen::Vector3f > &points, std::vector< Eigen::Vector3f > &colors)=0
SimpleShader(const std::string &name)
Definition: SimpleShader.h:44
int points
Definition: FilePCD.cpp:69
Definition: PinholeCameraIntrinsic.cpp:34
std::string name
Definition: FilePCD.cpp:54
Definition: ShaderWrapper.h:40
SimpleShaderForPointCloud()
Definition: SimpleShader.h:77
SimpleShaderForOctreeLine()
Definition: SimpleShader.h:155
SimpleShaderForVoxelGridFace()
Definition: SimpleShader.h:139
GLuint MVP_
Definition: SimpleShader.h:72