Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
geometry_resource.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_GEOMETRY_RESOURCE_HPP__
4 #define SCENEVIEW_GEOMETRY_RESOURCE_HPP__
5 
6 #include <cstdint>
7 #include <memory>
8 #include <vector>
9 
10 #include <QString>
11 #include <QVector2D>
12 #include <QVector3D>
13 #include <QVector4D>
14 #include <QOpenGLBuffer>
15 
16 #include <sceneview/axis_aligned_box.hpp>
17 
18 namespace sv {
19 
20 class Drawable;
21 
30 struct GeometryData {
34  std::vector<QVector3D> vertices;
35 
39  std::vector<QVector3D> normals;
40 
45  std::vector<QVector4D> diffuse;
46 
51  std::vector<QVector4D> specular;
52 
57  std::vector<float> shininess;
58 
62  std::vector<QVector2D> tex_coords_0;
63 
68  std::vector<uint32_t> indices;
69 
74  GLenum gl_mode;
75 };
76 
92  public:
93  typedef std::shared_ptr<GeometryResource> Ptr;
94 
96 
102  void Load(const GeometryData& data);
103 
104  QOpenGLBuffer* VBO() { return &vbo_; }
105 
106  QOpenGLBuffer* IndexBuffer();
107 
108  int VertexOffset() const { return vertex_offset_; }
109 
110  int NumVertices() const { return num_vertices_; }
111 
112  int NormalOffset() const { return normal_offset_; }
113 
114  int NumNormals() const { return num_normals_; }
115 
116  int DiffuseOffset() const { return diffuse_offset_; }
117 
118  int NumDiffuse() const { return num_diffuse_; }
119 
120  int NumSpecular() const { return num_specular_; }
121 
122  int SpecularOffset() const { return specular_offset_; }
123 
124  int NumShininess() const { return num_shininess_; }
125 
126  int ShininessOffset() const { return shininess_offset_; }
127 
128  int TexCoords0Offset() const { return tex_coords_0_offset_; }
129 
130  int NumTexCoords0() const { return num_tex_coords_0_; }
131 
132  int NumIndices() const { return num_indices_; }
133 
138  GLenum IndexType() const { return index_type_; }
139 
144  GLenum GLMode() const { return gl_mode_; }
145 
146  const AxisAlignedBox& BoundingBox() const { return bounding_box_; }
147 
148  private:
149  friend class ResourceManager;
150 
151  friend class Drawable;
152 
153  explicit GeometryResource(const QString& name);
154 
155  void AddListener(Drawable* drawable);
156 
157  void RemoveListener(Drawable* drawable);
158 
159  const QString name_;
160 
161  // Vertex buffer to hold the data in graphics memory
162  bool created_vbo_;
163  QOpenGLBuffer vbo_;
164  QOpenGLBuffer index_buffer_;
165 
166  int vertex_offset_;
167  int normal_offset_;
168  int diffuse_offset_;
169  int specular_offset_;
170  int shininess_offset_;
171  int tex_coords_0_offset_;
172 
173  int num_vertices_;
174  int num_normals_;
175  int num_diffuse_;
176  int num_specular_;
177  int num_shininess_;
178  int num_tex_coords_0_;
179 
180  int num_indices_;
181 
182  GLenum gl_mode_;
183  GLenum index_type_;
184 
185  AxisAlignedBox bounding_box_;
186 
187  std::vector<Drawable*> listeners_;
188 };
189 
190 } // namespace sv
191 
192 #endif // SCENEVIEW_GEOMETRY_RESOURCE_HPP__
GLenum GLMode() const
What kind of primitives are in this geometry (GL_POINTS, GL_LINE_STRIP, ...)
Definition: geometry_resource.hpp:144
std::vector< QVector3D > vertices
Vertices of the geometry.
Definition: geometry_resource.hpp:34
std::vector< float > shininess
Shininess component.
Definition: geometry_resource.hpp:57
Geometry that can be rendered with glDrawArrays() or glDrawElements().
Definition: geometry_resource.hpp:91
Geometry description to be used with GeometryResource.
Definition: geometry_resource.hpp:30
std::vector< QVector4D > diffuse
Diffuse color component.
Definition: geometry_resource.hpp:45
An axis-aligned box typically used for bounding box and intersection calculations.
Definition: axis_aligned_box.hpp:17
GLenum IndexType() const
Returns the type parameter to pass to glDrawElements() Either GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT.
Definition: geometry_resource.hpp:138
GLenum gl_mode
The OpenGL primitive type.
Definition: geometry_resource.hpp:74
std::vector< uint32_t > indices
Vertex indices.
Definition: geometry_resource.hpp:68
void Load(const GeometryData &data)
Loads the specified geometry into this resource.
std::vector< QVector4D > specular
Specular color component.
Definition: geometry_resource.hpp:51
std::vector< QVector2D > tex_coords_0
Texture coordinates.
Definition: geometry_resource.hpp:62
std::vector< QVector3D > normals
Normal vectors.
Definition: geometry_resource.hpp:39