MRPT  2.0.0
COpenGLBuffer.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 
12 #include <mrpt/core/exceptions.h>
14 #include <mrpt/opengl/opengl_api.h>
15 
16 using namespace mrpt::opengl;
17 
19 {
20  m_impl = std::make_shared<RAII_Impl>(type);
21 }
22 
25 {
26  // Free opengl resources:
27  destroy();
28 }
29 
31 {
32  destroy();
33 #if MRPT_HAS_OPENGL_GLUT
34  GLuint buffer;
35  glGenBuffers(1, &buffer);
36  this->buffer_id = buffer;
37  this->created_from = std::this_thread::get_id();
38  created = true;
39 #endif
40 }
41 
43 {
44  if (!created) return;
45 #if MRPT_HAS_OPENGL_GLUT
46  if (created_from == std::this_thread::get_id())
47  {
48  release();
49  glDeleteBuffers(1, &buffer_id);
50  }
51 #endif
52  buffer_id = 0;
53  created = false;
54 }
55 
57 {
58 #if MRPT_HAS_OPENGL_GLUT
59  ASSERT_(created);
60  glBindBuffer(static_cast<GLenum>(type), buffer_id);
61 #endif
62 }
63 
65 {
66 #if MRPT_HAS_OPENGL_GLUT
67  if (!created) return;
68  if (created_from != std::this_thread::get_id()) return;
69 
70  glBindBuffer(static_cast<GLenum>(type), 0);
71 #endif
72 }
73 
74 void COpenGLBuffer::RAII_Impl::allocate(const void* data, int byteCount)
75 {
76 #if MRPT_HAS_OPENGL_GLUT
77  ASSERT_(created);
78  glBufferData(
79  static_cast<GLenum>(type), byteCount, data, static_cast<GLenum>(usage));
80 #endif
81 }
void destroy()
Automatically called upon destructor, no need for the user to call it in normal situations.
Definition: COpenGLBuffer.h:68
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
std::shared_ptr< RAII_Impl > m_impl
void allocate(const void *data, int byteCount)
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
static struct FontData data
Definition: gltext.cpp:144



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020