MRPT  2.0.4
CRenderizableShaderPoints.cpp
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 #include "opengl-precomp.h" // Precompiled header
11 
13 #include <mrpt/opengl/Shader.h>
14 #include <mrpt/opengl/opengl_api.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 
22 
23 // Dtor:
25 
27 {
28 #if MRPT_HAS_OPENGL_GLUT
29 
30  // Generate vertices & colors:
32 
33  // Define OpenGL buffers:
37  m_vertex_buffer_data.data(),
38  sizeof(m_vertex_buffer_data[0]) * m_vertex_buffer_data.size());
39 
40  // color buffer:
44  m_color_buffer_data.data(),
45  sizeof(m_color_buffer_data[0]) * m_color_buffer_data.size());
46 
47  // VAO: required to use glEnableVertexAttribArray()
48  m_vao.createOnce();
49 #endif
50 }
51 
53 {
54 #if MRPT_HAS_OPENGL_GLUT
55 
56  // Point size as uniform:
57  glUniform1f(rc.shader->uniformId("vertexPointSize"), m_pointSize);
58 
59  // Variable point size code in the shader:
60  glUniform1i(
61  rc.shader->uniformId("enableVariablePointSize"),
62  m_variablePointSize ? 1 : 0);
63 
64  glUniform1f(
65  rc.shader->uniformId("variablePointSize_K"), m_variablePointSize_K);
66  glUniform1f(
67  rc.shader->uniformId("variablePointSize_DepthScale"),
69 
70  // Set up the vertex array:
71  const GLuint attr_position = rc.shader->attributeId("position");
72  m_vao.bind();
73  glEnableVertexAttribArray(attr_position);
75  glVertexAttribPointer(
76  attr_position, /* attribute */
77  3, /* size */
78  GL_FLOAT, /* type */
79  GL_FALSE, /* normalized? */
80  0, /* stride */
81  BUFFER_OFFSET(0) /* array buffer offset */
82  );
83  CHECK_OPENGL_ERROR();
84 
85  // Set up the color array:
86  const GLuint attr_color = rc.shader->attributeId("vertexColor");
87  glEnableVertexAttribArray(attr_color);
89  glVertexAttribPointer(
90  attr_color, /* attribute */
91  4, /* size */
92  GL_UNSIGNED_BYTE, /* type */
93  GL_TRUE, /* normalized? */
94  0, /* stride */
95  BUFFER_OFFSET(0) /* array buffer offset */
96  );
97  CHECK_OPENGL_ERROR();
98 
99  glDrawArrays(GL_POINTS, 0, m_vertex_buffer_data.size());
100  CHECK_OPENGL_ERROR();
101 
102  glDisableVertexAttribArray(attr_position);
103  glDisableVertexAttribArray(attr_color);
104  CHECK_OPENGL_ERROR();
105 #endif
106 }
107 
110 {
111  out.WriteAs<uint8_t>(0); // serialization version
114 }
117 {
118  const auto version = in.ReadAs<uint8_t>();
119 
120  switch (version)
121  {
122  case 0:
125  break;
126  default:
128  };
129 }
void createOnce()
Calls create() only if the buffer has not been created yet.
Definition: COpenGLBuffer.h:60
#define IMPLEMENTS_VIRTUAL_SERIALIZABLE(class_name, base_class, NS)
This must be inserted as implementation of some required members for virtual CSerializable classes: ...
const mrpt::opengl::Program * shader
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
void allocate(const void *data, int byteCount)
Reserves byteCount bytes in the buffer and copy to it the provided data.
Definition: COpenGLBuffer.h:78
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
int attributeId(const char *name) const
Definition: Shader.h:114
Context for calls to render()
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
std::vector< mrpt::img::TColor > m_color_buffer_data
void params_deserialize(mrpt::serialization::CArchive &in)
STORED_TYPE ReadAs()
De-serialize a variable and returns it by value.
Definition: CArchive.h:155
void params_serialize(mrpt::serialization::CArchive &out) const
Renderizable generic renderer for objects using the points shader.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
void createOnce()
Calls create() only if the buffer has not been created yet.
int uniformId(const char *name) const
Definition: Shader.h:113
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...
#define BUFFER_OFFSET(offset)



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