Debian Codegraph @

avogadro/rendering/vertexarrayobject.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_RENDERING_VERTEXARRAYOBJECT_H
7 #define AVOGADRO_RENDERING_VERTEXARRAYOBJECT_H
8
9 #include "avogadrorenderingexport.h"
10 #include <avogadro/core/avogadrocore.h>
11
12 namespace Avogadro {
13 namespace Rendering {
14
15 /**
16 * @class VertexArrayObject vertexarrayobject.h
17 * <avogadro/rendering/vertexarrayobject.h>
18 * @brief Vertex Array Object to capture vertex attribute state.
19 *
20 * This class wraps an OpenGL VAO, which captures the state of vertex
21 * attribute bindings. Required for OpenGL 3.2+ core profile.
22 *
23 * The VAO handle is lazily created on first bind(), allowing the object
24 * to be constructed before the OpenGL context is initialized.
25 *
26 * Usage pattern:
27 * // During setup (when buffers change):
28 * vao.bind();
29 * vbo.bind();
30 * ibo.bind();
31 * // set up vertex attribute pointers
32 * vao.release();
33 *
34 * // During render:
35 * vao.bind();
36 * glDrawElements(...);
37 * vao.release();
38 */
39 class AVOGADRORENDERING_EXPORT VertexArrayObject
40 {
41 public:
42 VertexArrayObject();
43 ~VertexArrayObject();
44
45 // Non-copyable (OpenGL resource)
46 VertexArrayObject(const VertexArrayObject&) = delete;
47 VertexArrayObject& operator=(const VertexArrayObject&) = delete;
48
49 /** Bind the VAO, making it active for attribute setup or rendering. */
50 bool bind();
51
52 /** Unbind the VAO. */
53 void release();
54
55 /** Get the OpenGL handle. Returns 0 if not yet created. */
56 Index handle() const { return static_cast<Index>(m_handle); }
57
58 private:
59 unsigned int m_handle = 0;
60 };
61
62 } // namespace Rendering
63 } // namespace Avogadro
64
65 #endif // AVOGADRO_RENDERING_VERTEXARRAYOBJECT_H