MRPT  2.0.4
COpenGLVertexArrayObject.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 #pragma once
10 
11 #include <memory>
12 #include <thread>
13 
14 namespace mrpt::opengl
15 {
16 /** A wrapper for an OpenGL vertex array object (VAO).
17  * Refer to docs for glGenVertexArrays().
18  *
19  * \ingroup mrpt_opengl_grp
20  */
22 {
23  public:
25  ~COpenGLVertexArrayObject() = default;
26 
27  /** Actually create the buffer, destroying any previously existing buffer.
28  */
29  void create() { m_impl->create(); }
30 
31  /** Calls create() only if the buffer has not been created yet. */
32  void createOnce()
33  {
34  if (!isCreated()) create();
35  }
36  bool isCreated() const { return m_impl->created; }
37 
38  /** Automatically called upon destructor, no need for the user to call it in
39  * normal situations. */
40  void destroy() { m_impl->destroy(); }
41 
42  void bind() { m_impl->bind(); }
43  void release() { m_impl->bind(); }
44 
45  unsigned int bufferId() const { return m_impl->buffer_id; }
46 
47  private:
48  struct RAII_Impl
49  {
50  RAII_Impl() = default;
51  ~RAII_Impl();
52 
53  void create();
54  void destroy();
55  void bind();
56  void release();
57  void allocate(const void* data, int byteCount);
58 
59  bool created = false;
60  unsigned int buffer_id = 0;
61  std::thread::id created_from;
62  };
63  std::shared_ptr<RAII_Impl> m_impl;
64 };
65 
66 } // namespace mrpt::opengl
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::bind
void bind()
Definition: COpenGLVertexArrayObject.cpp:57
mrpt::opengl::internal::data
static struct FontData data
Definition: gltext.cpp:144
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::created_from
std::thread::id created_from
Definition: COpenGLVertexArrayObject.h:61
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::release
void release()
Definition: COpenGLVertexArrayObject.cpp:65
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::allocate
void allocate(const void *data, int byteCount)
mrpt::opengl::COpenGLVertexArrayObject::~COpenGLVertexArrayObject
~COpenGLVertexArrayObject()=default
mrpt::opengl::COpenGLVertexArrayObject
A wrapper for an OpenGL vertex array object (VAO).
Definition: COpenGLVertexArrayObject.h:21
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::buffer_id
unsigned int buffer_id
Definition: COpenGLVertexArrayObject.h:60
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::created
bool created
Definition: COpenGLVertexArrayObject.h:59
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl
Definition: COpenGLVertexArrayObject.h:48
mrpt::opengl::COpenGLVertexArrayObject::bufferId
unsigned int bufferId() const
Definition: COpenGLVertexArrayObject.h:45
mrpt::opengl::COpenGLVertexArrayObject::COpenGLVertexArrayObject
COpenGLVertexArrayObject()
Definition: COpenGLVertexArrayObject.cpp:19
mrpt::opengl::COpenGLVertexArrayObject::create
void create()
Actually create the buffer, destroying any previously existing buffer.
Definition: COpenGLVertexArrayObject.h:29
mrpt::opengl::COpenGLVertexArrayObject::bind
void bind()
Definition: COpenGLVertexArrayObject.h:42
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::RAII_Impl
RAII_Impl()=default
mrpt::opengl::COpenGLVertexArrayObject::createOnce
void createOnce()
Calls create() only if the buffer has not been created yet.
Definition: COpenGLVertexArrayObject.h:32
mrpt::opengl::COpenGLVertexArrayObject::release
void release()
Definition: COpenGLVertexArrayObject.h:43
mrpt::opengl::COpenGLVertexArrayObject::destroy
void destroy()
Automatically called upon destructor, no need for the user to call it in normal situations.
Definition: COpenGLVertexArrayObject.h:40
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::~RAII_Impl
~RAII_Impl()
Definition: COpenGLVertexArrayObject.cpp:24
mrpt::opengl::COpenGLVertexArrayObject::isCreated
bool isCreated() const
Definition: COpenGLVertexArrayObject.h:36
mrpt::opengl::COpenGLVertexArrayObject::m_impl
std::shared_ptr< RAII_Impl > m_impl
Definition: COpenGLVertexArrayObject.h:63
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::destroy
void destroy()
Definition: COpenGLVertexArrayObject.cpp:42
mrpt::opengl::COpenGLVertexArrayObject::RAII_Impl::create
void create()
Definition: COpenGLVertexArrayObject.cpp:30
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 15:15:43 UTC 2020