Open3D (C++ API)  0.15.1
ShaderWrapper.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-2021 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 <GL/glew.h>
30
34
35namespace open3d {
36namespace visualization {
37
38namespace glsl {
39
41public:
42 virtual ~ShaderWrapper() {}
43 ShaderWrapper(const ShaderWrapper &) = delete;
45
46protected:
47 ShaderWrapper(const std::string &name) : shader_name_(name) {}
48
49public:
54 bool Render(const geometry::Geometry &geometry,
55 const RenderOption &option,
56 const ViewControl &view);
57
60 void InvalidateGeometry();
61
62 const std::string &GetShaderName() const { return shader_name_; }
63
64 void PrintShaderWarning(const std::string &message) const;
65
66protected:
70 virtual bool Compile() = 0;
71
75 virtual void Release() = 0;
76
77 virtual bool BindGeometry(const geometry::Geometry &geometry,
78 const RenderOption &option,
79 const ViewControl &view) = 0;
80 virtual bool RenderGeometry(const geometry::Geometry &geometry,
81 const RenderOption &option,
82 const ViewControl &view) = 0;
83 virtual void UnbindGeometry() = 0;
84
85protected:
86 bool ValidateShader(GLuint shader_index);
87 bool ValidateProgram(GLuint program_index);
88 bool CompileShaders(const char *const vertex_shader_code,
89 const char *const geometry_shader_code,
90 const char *const fragment_shader_code);
91 void ReleaseProgram();
92
93protected:
94 GLuint vertex_shader_ = 0;
95 GLuint geometry_shader_ = 0;
96 GLuint fragment_shader_ = 0;
97 GLuint program_ = 0;
98 GLenum draw_arrays_mode_ = GL_POINTS;
99 GLsizei draw_arrays_size_ = 0;
100 bool compiled_ = false;
101 bool bound_ = false;
102
103 void SetShaderName(const std::string &shader_name) {
104 shader_name_ = shader_name;
105 }
106
107private:
108 std::string shader_name_ = "ShaderWrapper";
109};
110
111} // namespace glsl
112
113} // namespace visualization
114} // namespace open3d
The base geometry class.
Definition: Geometry.h:37
Defines rendering options for visualizer.
Definition: RenderOption.h:39
View controller for visualizer.
Definition: ViewControl.h:41
Definition: ShaderWrapper.h:40
bool CompileShaders(const char *const vertex_shader_code, const char *const geometry_shader_code, const char *const fragment_shader_code)
Definition: ShaderWrapper.cpp:63
GLuint geometry_shader_
Definition: ShaderWrapper.h:95
const std::string & GetShaderName() const
Definition: ShaderWrapper.h:62
ShaderWrapper & operator=(const ShaderWrapper &)=delete
GLuint fragment_shader_
Definition: ShaderWrapper.h:96
bool compiled_
Definition: ShaderWrapper.h:100
GLuint program_
Definition: ShaderWrapper.h:97
virtual bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
void PrintShaderWarning(const std::string &message) const
Definition: ShaderWrapper.cpp:59
bool ValidateShader(GLuint shader_index)
Definition: ShaderWrapper.cpp:138
virtual ~ShaderWrapper()
Definition: ShaderWrapper.h:42
ShaderWrapper(const std::string &name)
Definition: ShaderWrapper.h:47
virtual bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
bool bound_
Definition: ShaderWrapper.h:101
void SetShaderName(const std::string &shader_name)
Definition: ShaderWrapper.h:103
GLsizei draw_arrays_size_
Definition: ShaderWrapper.h:99
GLuint vertex_shader_
Definition: ShaderWrapper.h:94
ShaderWrapper(const ShaderWrapper &)=delete
bool ValidateProgram(GLuint program_index)
Definition: ShaderWrapper.cpp:155
bool Render(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)
Definition: ShaderWrapper.cpp:37
GLenum draw_arrays_mode_
Definition: ShaderWrapper.h:98
void ReleaseProgram()
Definition: ShaderWrapper.cpp:131
void InvalidateGeometry()
Definition: ShaderWrapper.cpp:53
std::string name
Definition: FilePCD.cpp:58
Definition: PinholeCameraIntrinsic.cpp:35