MRPT  2.0.4
CRenderizableShaderWireFrame.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>
15 
16 using namespace mrpt;
17 using namespace mrpt::opengl;
18 
21 
22 // Dtor:
24 
26 {
27 #if MRPT_HAS_OPENGL_GLUT
28 
29  // Generate vertices & colors:
30  const_cast<CRenderizableShaderWireFrame&>(*this)
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  // TODO: Port thick lines to opengl3?
56  // glLineWidth(m_lineWidth);
57 
58  glEnable(GL_LINE_SMOOTH);
59  CHECK_OPENGL_ERROR();
60 
61  // Set up the vertex array:
62  const GLuint attr_position = rc.shader->attributeId("position");
63  m_vao.bind();
64  glEnableVertexAttribArray(attr_position);
66  glVertexAttribPointer(
67  attr_position, /* attribute */
68  3, /* size */
69  GL_FLOAT, /* type */
70  GL_FALSE, /* normalized? */
71  0, /* stride */
72  BUFFER_OFFSET(0) /* array buffer offset */
73  );
74  CHECK_OPENGL_ERROR();
75 
76  // Set up the color array:
77  const GLuint attr_color = rc.shader->attributeId("vertexColor");
78  glEnableVertexAttribArray(attr_color);
80  glVertexAttribPointer(
81  attr_color, /* attribute */
82  4, /* size */
83  GL_UNSIGNED_BYTE, /* type */
84  GL_TRUE, /* normalized? */
85  0, /* stride */
86  BUFFER_OFFSET(0) /* array buffer offset */
87  );
88  CHECK_OPENGL_ERROR();
89 
90  glDrawArrays(GL_LINES, 0, m_vertex_buffer_data.size());
91  CHECK_OPENGL_ERROR();
92 
93  glDisableVertexAttribArray(attr_position);
94  glDisableVertexAttribArray(attr_color);
95  CHECK_OPENGL_ERROR();
96 #endif
97 }
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
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
int attributeId(const char *name) const
Definition: Shader.h:114
Context for calls to render()
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
std::vector< mrpt::img::TColor > m_color_buffer_data
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Renderizable generic renderer for objects using the wireframe shader.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
void createOnce()
Calls create() only if the buffer has not been created yet.
virtual void onUpdateBuffers_Wireframe()=0
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
#define BUFFER_OFFSET(offset)
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.



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