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 <vector>
30 #include <Eigen/Core>
32 
33 namespace open3d {
34 namespace visualization {
35 
36 namespace glsl {
37 
38 class SimpleShader : public ShaderWrapper {
39 public:
40  ~SimpleShader() override { Release(); }
41 
42 protected:
43  SimpleShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
44 
45 protected:
46  bool Compile() final;
47  void Release() final;
48  bool BindGeometry(const geometry::Geometry &geometry,
49  const RenderOption &option,
50  const ViewControl &view) final;
51  bool RenderGeometry(const geometry::Geometry &geometry,
52  const RenderOption &option,
53  const ViewControl &view) final;
54  void UnbindGeometry() final;
55 
56 protected:
57  virtual bool PrepareRendering(const geometry::Geometry &geometry,
58  const RenderOption &option,
59  const ViewControl &view) = 0;
60  virtual bool PrepareBinding(const geometry::Geometry &geometry,
61  const RenderOption &option,
62  const ViewControl &view,
63  std::vector<Eigen::Vector3f> &points,
64  std::vector<Eigen::Vector3f> &colors) = 0;
65 
66 protected:
69  GLuint vertex_color_;
71  GLuint MVP_;
72 };
73 
75 public:
76  SimpleShaderForPointCloud() : SimpleShader("SimpleShaderForPointCloud") {}
77 
78 protected:
79  bool PrepareRendering(const geometry::Geometry &geometry,
80  const RenderOption &option,
81  const ViewControl &view) final;
82  bool PrepareBinding(const geometry::Geometry &geometry,
83  const RenderOption &option,
84  const ViewControl &view,
85  std::vector<Eigen::Vector3f> &points,
86  std::vector<Eigen::Vector3f> &colors) final;
87 };
88 
90 public:
91  SimpleShaderForLineSet() : SimpleShader("SimpleShaderForLineSet") {}
92 
93 protected:
94  bool PrepareRendering(const geometry::Geometry &geometry,
95  const RenderOption &option,
96  const ViewControl &view) final;
97  bool PrepareBinding(const geometry::Geometry &geometry,
98  const RenderOption &option,
99  const ViewControl &view,
100  std::vector<Eigen::Vector3f> &points,
101  std::vector<Eigen::Vector3f> &colors) final;
102 };
103 
105 public:
107  : SimpleShader("SimpleShaderForTriangleMesh") {}
108 
109 protected:
110  bool PrepareRendering(const geometry::Geometry &geometry,
111  const RenderOption &option,
112  const ViewControl &view) final;
113  bool PrepareBinding(const geometry::Geometry &geometry,
114  const RenderOption &option,
115  const ViewControl &view,
116  std::vector<Eigen::Vector3f> &points,
117  std::vector<Eigen::Vector3f> &colors) final;
118 };
119 
121 public:
122  SimpleShaderForVoxelGrid() : SimpleShader("SimpleShaderForVoxelGrid") {}
123 
124 protected:
125  bool PrepareRendering(const geometry::Geometry &geometry,
126  const RenderOption &option,
127  const ViewControl &view) final;
128  bool PrepareBinding(const geometry::Geometry &geometry,
129  const RenderOption &option,
130  const ViewControl &view,
131  std::vector<Eigen::Vector3f> &points,
132  std::vector<Eigen::Vector3f> &colors) final;
133 };
134 
135 } // namespace glsl
136 
137 } // namespace visualization
138 } // namespace open3d
GLuint vertex_position_buffer_
Definition: SimpleShader.h:68
Definition: Geometry.h:32
bool Compile() final
Definition: SimpleShader.cpp:41
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: SimpleShader.cpp:90
GLuint vertex_color_buffer_
Definition: SimpleShader.h:70
SimpleShaderForLineSet()
Definition: SimpleShader.h:91
Definition: ViewControl.h:38
GLuint vertex_color_
Definition: SimpleShader.h:69
void UnbindGeometry() final
Definition: SimpleShader.cpp:111
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: SimpleShader.cpp:58
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
SimpleShaderForTriangleMesh()
Definition: SimpleShader.h:106
GLuint vertex_position_
Definition: SimpleShader.h:67
Definition: SimpleShader.h:38
void Release() final
Definition: SimpleShader.cpp:53
Definition: RenderOption.h:36
~SimpleShader() override
Definition: SimpleShader.h:40
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:43
int points
Definition: FilePCD.cpp:69
SimpleShaderForVoxelGrid()
Definition: SimpleShader.h:122
Definition: PinholeCameraIntrinsic.cpp:33
std::string name
Definition: FilePCD.cpp:54
Definition: ShaderWrapper.h:40
SimpleShaderForPointCloud()
Definition: SimpleShader.h:76
GLuint MVP_
Definition: SimpleShader.h:71