Debian Codegraph @

avogadro/rendering/packedvertex.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_PACKEDVERTEX_H
7 #define AVOGADRO_RENDERING_PACKEDVERTEX_H
8
9 #include <avogadro/core/vector.h>
10
11 namespace Avogadro {
12 namespace Rendering {
13
14 /**
15 * @struct PackedVertex packedvertex.h <avogadro/rendering/packedvertex.h>
16 * @brief Packed vertex structure for efficient GPU transfer.
17 *
18 * This structure packs color, normal, and vertex data into a 32-byte aligned
19 * format that is ideal for GPU memory access patterns.
20 */
21 struct PackedVertex
22 {
23 Vector4ub color; // 4 bytes
24 Vector3f normal; // 12 bytes
25 Vector3f vertex; // 12 bytes
26 unsigned char padding[4]; // 4 bytes
27
28 PackedVertex() : color(0, 0, 0, 255), normal(0, 0, 1), vertex(0, 0, 0) {}
29
30 PackedVertex(const Vector4ub& c, const Vector3f& n, const Vector3f& v)
31 : color(c), normal(n), vertex(v)
32 {
33 }
34
35 static int colorOffset() { return 0; }
36 static int normalOffset() { return static_cast<int>(sizeof(Vector4ub)); }
37 static int vertexOffset()
38 {
39 return normalOffset() + static_cast<int>(sizeof(Vector3f));
40 }
41 }; // 32 bytes total size - 16/32/64 are ideal for alignment.
42
43 } // namespace Rendering
44 } // namespace Avogadro
45
46 #endif // AVOGADRO_RENDERING_PACKEDVERTEX_H