MRPT  2.0.3
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 }
COpenGLBuffer.h
mrpt::opengl::internal::data
static struct FontData data
Definition: gltext.cpp:144
opengl_api.h
exceptions.h
mrpt::opengl::COpenGLBuffer::RAII_Impl::RAII_Impl
RAII_Impl(COpenGLBuffer::Type t)
Definition: COpenGLBuffer.cpp:23
mrpt::opengl::COpenGLBuffer::release
void release()
Definition: COpenGLBuffer.h:71
mrpt::opengl::COpenGLBuffer::RAII_Impl::create
void create()
Definition: COpenGLBuffer.cpp:30
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
mrpt::opengl::COpenGLBuffer::RAII_Impl::bind
void bind()
Definition: COpenGLBuffer.cpp:56
mrpt::opengl::COpenGLBuffer::RAII_Impl::destroy
void destroy()
Definition: COpenGLBuffer.cpp:42
mrpt::opengl::COpenGLBuffer::m_impl
std::shared_ptr< RAII_Impl > m_impl
Definition: COpenGLBuffer.h:102
mrpt::opengl::COpenGLBuffer::RAII_Impl::release
void release()
Definition: COpenGLBuffer.cpp:64
opengl-precomp.h
mrpt::opengl::COpenGLBuffer::COpenGLBuffer
COpenGLBuffer()
Definition: COpenGLBuffer.h:46
mrpt::opengl::COpenGLBuffer::Type
Type
Definition: COpenGLBuffer.h:24
mrpt::opengl::COpenGLBuffer::type
Type type() const
Definition: COpenGLBuffer.h:49
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::opengl::COpenGLBuffer::destroy
void destroy()
Automatically called upon destructor, no need for the user to call it in normal situations.
Definition: COpenGLBuffer.h:68
mrpt::opengl::COpenGLBuffer::RAII_Impl::allocate
void allocate(const void *data, int byteCount)
Definition: COpenGLBuffer.cpp:74
mrpt::opengl::COpenGLBuffer::usage
Usage usage() const
Definition: COpenGLBuffer.h:51
mrpt::opengl::COpenGLBuffer::RAII_Impl::~RAII_Impl
~RAII_Impl()
Definition: COpenGLBuffer.cpp:24



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Thu May 21 21:53:32 UTC 2020