Debian Codegraph @

avogadro/rendering/scene.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_SCENE_H
7 #define AVOGADRO_RENDERING_SCENE_H
8
9 #include "avogadrorenderingexport.h"
10
11 #include "groupnode.h"
12 #include "primitive.h"
13
14 #include <avogadro/core/avogadrocore.h>
15 #include <avogadro/core/vector.h>
16
17 #include <map> // For member variables.
18 #include <string> // For member variables.
19 #include <vector> // For member variables.
20
21 namespace Avogadro {
22
23 namespace Core {
24 class Molecule;
25 }
26
27 namespace Rendering {
28
29 /**
30 * @class Scene scene.h <avogadro/rendering/scene.h>
31 * @brief The Scene contains data ready to be rendered.
32 * @author Marcus D. Hanwell
33 *
34 * A collection of geometric primitives ready for rendering. This is highly
35 * targeted for fast rendering on modern OpenGL 2.1/ES 2.0 GPUs, but can also
36 * be adapted and rendered using other approaches.
37 */
38
39 /// Pack the vertex data into a contiguous array.
40 struct ColorTextureVertex
41 {
42 Vector3f vertex; // 12 bytes
43 Vector3ub color; // 3 bytes
44 unsigned char unusedAlign; // 1 byte
45 Vector2f textureCoord; // 8 bytes
46 Vector2f textureCoord2; // 8 bytes
47
48 ColorTextureVertex(const Vector3f& p, const Vector3ub& c, const Vector2f& t,
49 const Vector2f& t2 = Vector2f::Zero())
50 : vertex(p), color(c), textureCoord(t), textureCoord2(t2)
51 {
52 }
53
54 static int vertexOffset() { return 0; }
55 static int colorOffset() { return static_cast<int>(sizeof(Vector3f)); }
56 static int textureCoordOffset()
57 {
58 return colorOffset() +
59 static_cast<int>(sizeof(Vector3ub) + sizeof(unsigned char));
60 }
61 static int textureCoord2Offset()
62 {
63 return textureCoordOffset() + static_cast<int>(sizeof(Vector2f));
64 }
65 }; // 32 bytes total size - 16/32/64 are ideal for alignment.
66
67 /// Pack the vertex data into a contiguous array.
68 struct ColorNormalVertex
69 {
70 Vector3ub color; // 3 bytes
71 unsigned char unusedAlign; // 1 byte
72 Vector3f normal; // 12 bytes
73 Vector3f vertex; // 12 bytes
74 unsigned char padding[4]; // 4 bytes
75 ColorNormalVertex() {}
76 ColorNormalVertex(const Vector3ub& c, const Vector3f& n, const Vector3f& v)
77 : color(c), normal(n), vertex(v)
78 {
79 }
80
81 static int colorOffset() { return 0; }
82 static int normalOffset()
83 {
84 return static_cast<int>(sizeof(Vector3ub) + sizeof(unsigned char));
85 }
86 static int vertexOffset()
87 {
88 return normalOffset() + static_cast<int>(sizeof(Vector3f));
89 }
90 }; // 32 bytes total size - 16/32/64 are ideal for alignment.
91
92 class AVOGADRORENDERING_EXPORT Scene
93 {
94 public:
95 Scene();
96 ~Scene();
97
98 /** Get the center of the points contained in this Scene. */
99 Vector3f center();
100
101 /** Get the radius, which is currently just the largest of the axis-aligned
102 * components of the positions.
103 */
104 float radius();
105
106 /**
107 * Get the root node of the scene.
108 */
109 GroupNode& rootNode() { return m_rootNode; }
110 const GroupNode& rootNode() const { return m_rootNode; }
111
112 /**
113 * Set the background color of the scene (default is black).
114 */
115 void setBackgroundColor(const Vector4ub& color) { m_backgroundColor = color; }
116
117 /**
118 * Get the background color of the scene.
119 */
120 Vector4ub backgroundColor() const { return m_backgroundColor; }
121
122 /**
123 * Mark the scene as dirty, primarily to ensure radius/center will be
124 * recalculated.
125 */
126 void setDirty(bool dirty) { m_dirty = dirty; }
127
128 /**
129 * Has the scene been marked as dirty?
130 */
131 bool isDirty() const { return m_dirty; }
132
133 /** Clear the scene of all elements. */
134 void clear();
135
136 private:
137 GroupNode m_rootNode;
138 Vector4ub m_backgroundColor;
139
140 mutable bool m_dirty;
141 mutable Vector3f m_center;
142 mutable float m_radius;
143 };
144
145 } // namespace Rendering
146 } // namespace Avogadro
147
148 #endif // AVOGADRO_RENDERING_SCENE_H