MRPT  2.0.4
CRenderizableShaderPoints.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
15 
16 namespace mrpt::opengl
17 {
18 /** Renderizable generic renderer for objects using the points shader.
19  *
20  * All points may have the same point size (see setPointSize()) or a dynamic,
21  * depth-dependent size to emulate the effect of larger points when looked
22  * closely (see enableVariablePointSize()).
23  *
24  * In the latter case, point size is computed in the shader as:
25  *
26  * gl_PointSize = vertexPointSize +
27  * variablePointSize_k/(variablePointSize_DepthScale*gl_Position.z + 0.01);
28  *
29  * where the paramters vertexPointSize, variablePointSize_k, and
30  * variablePointSize_DepthScale can be set in this class via setPointSize(),
31  * setVariablePointSize_k(), and setVariablePointSize_DepthScale(),
32  * respectively.
33  *
34  * \sa opengl::COpenGLScene
35  *
36  * \ingroup mrpt_opengl_grp
37  */
39 {
41 
42  public:
43  CRenderizableShaderPoints() = default;
44  virtual ~CRenderizableShaderPoints() override;
45 
46  virtual shader_list_t requiredShaders() const override
47  {
48  return {DefaultShaderID::POINTS};
49  }
50  void render(const RenderContext& rc) const override;
51  void renderUpdateBuffers() const override;
52 
53  /** Must be implemented in derived classes to update the geometric entities
54  * to be drawn in "m_*_buffer" fields. */
55  virtual void onUpdateBuffers_Points() = 0;
56 
57  /** By default is 1.0. \sa enableVariablePointSize() */
58  inline void setPointSize(float p) { m_pointSize = p; }
59  inline float getPointSize() const { return m_pointSize; }
60 
61  /** Enable/disable variable eye distance-dependent point size (default=true)
62  */
63  inline void enableVariablePointSize(bool enable = true)
64  {
65  m_variablePointSize = enable;
66  }
67  inline bool isEnabledVariablePointSize() const
68  {
69  return m_variablePointSize;
70  }
71  /** see CRenderizableShaderPoints for a discussion of this parameter. */
74 
75  /** see CRenderizableShaderPoints for a discussion of this parameter. */
77  {
79  }
81  {
83  }
84 
85  // See base docs
86  void freeOpenGLResources() override
87  {
90  m_vao.destroy();
91  }
92 
93  /** @name Raw access to point shader buffer data
94  * @{ */
95  const auto& shaderPointsVertexPointBuffer() const
96  {
97  return m_vertex_buffer_data;
98  }
99  const auto& shaderPointsVertexColorBuffer() const
100  {
101  return m_color_buffer_data;
102  }
103  /** @} */
104 
105  protected:
106  mutable std::vector<mrpt::math::TPoint3Df> m_vertex_buffer_data;
107  mutable std::vector<mrpt::img::TColor> m_color_buffer_data;
108 
109  float m_pointSize = 1.0f;
110  bool m_variablePointSize = true;
111  float m_variablePointSize_K = 0.1f;
113 
116 
117  private:
120 };
121 
122 } // namespace mrpt::opengl
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
A wrapper for an OpenGL vertex array object (VAO).
A wrapper for an OpenGL buffer object.
Definition: COpenGLBuffer.h:21
void setPointSize(float p)
By default is 1.0.
void destroy()
Automatically called upon destructor, no need for the user to call it in normal situations.
Definition: COpenGLBuffer.h:68
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
void freeOpenGLResources() override
Free opengl buffers.
void destroy()
Automatically called upon destructor, no need for the user to call it in normal situations.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
std::vector< mrpt::img::TColor > m_color_buffer_data
void params_deserialize(mrpt::serialization::CArchive &in)
void setVariablePointSize_DepthScale(float v)
see CRenderizableShaderPoints for a discussion of this parameter.
void params_serialize(mrpt::serialization::CArchive &out) const
Renderizable generic renderer for objects using the points shader.
void enableVariablePointSize(bool enable=true)
Enable/disable variable eye distance-dependent point size (default=true)
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
void setVariablePointSize_k(float v)
see CRenderizableShaderPoints for a discussion of this parameter.
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
virtual ~CRenderizableShaderPoints() override
virtual void onUpdateBuffers_Points()=0
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
static constexpr shader_id_t POINTS



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020