Debian Codegraph @

libs/opengl/src/VertexArrayObject.cpp

raw
1 /* +------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | https://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2026, 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>
13 #include <mrpt/opengl/VertexArrayObject.h>
14 #include <mrpt/opengl/opengl_api.h>
15
16 #include <thread>
17
18 using namespace mrpt::opengl;
19
20 VertexArrayObject::VertexArrayObject() {}
21
22 VertexArrayObject::RAII_Impl::~RAII_Impl()
23 {
24 // Free resources:
25 destroy();
26 }
27
28 void VertexArrayObject::RAII_Impl::create()
29 {
30 destroy();
31 #if MRPT_HAS_OPENGL_GLUT || MRPT_HAS_EGL
32 GLuint buffer;
33 glGenVertexArrays(1, &buffer);
34 m_state.get().buffer_id = buffer;
35 m_state.get().created = true;
36 #endif
37 }
38
39 void VertexArrayObject::RAII_Impl::destroy()
40 {
41 if (!m_state.get().created) return;
42 #if MRPT_HAS_OPENGL_GLUT || MRPT_HAS_EGL
43
44 release();
45 glDeleteVertexArrays(1, &m_state.get().buffer_id);
46 #endif
47 m_state.get().buffer_id = 0;
48 m_state.get().created = false;
49 }
50
51 void VertexArrayObject::RAII_Impl::bind()
52 {
53 #if MRPT_HAS_OPENGL_GLUT || MRPT_HAS_EGL
54 ASSERT_(m_state.get().created);
55 glBindVertexArray(m_state.get().buffer_id);
56 #endif
57 }
58
59 void VertexArrayObject::RAII_Impl::release()
60 {
61 #if MRPT_HAS_OPENGL_GLUT || MRPT_HAS_EGL
62 if (!m_state.get().created) return;
63 glBindVertexArray(0);
64 #endif
65 }