Open3D (C++ API)  0.18.0
ShaderWrapper.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <GL/glew.h>
11 
15 
16 namespace open3d {
17 namespace visualization {
18 
19 namespace glsl {
20 
22 public:
23  virtual ~ShaderWrapper() {}
24  ShaderWrapper(const ShaderWrapper &) = delete;
26 
27 protected:
28  ShaderWrapper(const std::string &name) : shader_name_(name) {}
29 
30 public:
35  bool Render(const geometry::Geometry &geometry,
36  const RenderOption &option,
37  const ViewControl &view);
38 
41  void InvalidateGeometry();
42 
43  const std::string &GetShaderName() const { return shader_name_; }
44 
45  void PrintShaderWarning(const std::string &message) const;
46 
47 protected:
51  virtual bool Compile() = 0;
52 
56  virtual void Release() = 0;
57 
58  virtual bool BindGeometry(const geometry::Geometry &geometry,
59  const RenderOption &option,
60  const ViewControl &view) = 0;
61  virtual bool RenderGeometry(const geometry::Geometry &geometry,
62  const RenderOption &option,
63  const ViewControl &view) = 0;
64  virtual void UnbindGeometry() = 0;
65 
66 protected:
67  bool ValidateShader(GLuint shader_index);
68  bool ValidateProgram(GLuint program_index);
69  bool CompileShaders(const char *const vertex_shader_code,
70  const char *const geometry_shader_code,
71  const char *const fragment_shader_code);
72  void ReleaseProgram();
73 
74 protected:
75  GLuint vertex_shader_ = 0;
76  GLuint geometry_shader_ = 0;
77  GLuint fragment_shader_ = 0;
78  GLuint program_ = 0;
79  GLenum draw_arrays_mode_ = GL_POINTS;
80  GLsizei draw_arrays_size_ = 0;
81  bool compiled_ = false;
82  bool bound_ = false;
83 
84  void SetShaderName(const std::string &shader_name) {
85  shader_name_ = shader_name;
86  }
87 
88 private:
89  std::string shader_name_ = "ShaderWrapper";
90 };
91 
92 } // namespace glsl
93 
94 } // namespace visualization
95 } // namespace open3d
The base geometry class.
Definition: Geometry.h:18
Defines rendering options for visualizer.
Definition: RenderOption.h:20
View controller for visualizer.
Definition: ViewControl.h:23
Definition: ShaderWrapper.h:21
bool CompileShaders(const char *const vertex_shader_code, const char *const geometry_shader_code, const char *const fragment_shader_code)
Definition: ShaderWrapper.cpp:44
GLuint geometry_shader_
Definition: ShaderWrapper.h:76
GLuint fragment_shader_
Definition: ShaderWrapper.h:77
bool compiled_
Definition: ShaderWrapper.h:81
GLuint program_
Definition: ShaderWrapper.h:78
virtual bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
void PrintShaderWarning(const std::string &message) const
Definition: ShaderWrapper.cpp:40
bool ValidateShader(GLuint shader_index)
Definition: ShaderWrapper.cpp:119
virtual ~ShaderWrapper()
Definition: ShaderWrapper.h:23
ShaderWrapper(const std::string &name)
Definition: ShaderWrapper.h:28
virtual bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
const std::string & GetShaderName() const
Definition: ShaderWrapper.h:43
bool bound_
Definition: ShaderWrapper.h:82
void SetShaderName(const std::string &shader_name)
Definition: ShaderWrapper.h:84
GLsizei draw_arrays_size_
Definition: ShaderWrapper.h:80
ShaderWrapper & operator=(const ShaderWrapper &)=delete
GLuint vertex_shader_
Definition: ShaderWrapper.h:75
ShaderWrapper(const ShaderWrapper &)=delete
bool ValidateProgram(GLuint program_index)
Definition: ShaderWrapper.cpp:136
bool Render(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)
Definition: ShaderWrapper.cpp:18
GLenum draw_arrays_mode_
Definition: ShaderWrapper.h:79
void ReleaseProgram()
Definition: ShaderWrapper.cpp:112
void InvalidateGeometry()
Definition: ShaderWrapper.cpp:34
std::string name
Definition: FilePCD.cpp:39
Definition: PinholeCameraIntrinsic.cpp:16