Pioneer
VertexArray.h
Go to the documentation of this file.
1 // Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _VERTEXARRAY_H
5 #define _VERTEXARRAY_H
6 
7 #include "Types.h"
8 #include "libs.h"
9 
10 namespace Graphics {
11 
12  /*
13  * VertexArray is a multi-purpose vertex container. Users specify
14  * the attributes they intend to use and then add vertices. Renderers
15  * do whatever they need to do with regards to the attribute set.
16  * This is not optimized for high performance drawing, but okay for simple
17  * cases.
18  */
19  class VertexArray {
20  public:
21  //specify attributes to be used, additionally reserve space for vertices
22  VertexArray(AttributeSet attribs, int size = 0);
23  ~VertexArray();
24 
25  //check presence of an attribute
26  __inline bool HasAttrib(const VertexAttrib v) const { return (m_attribs & v) != 0; }
27  __inline Uint32 GetNumVerts() const { return static_cast<Uint32>(position.size()); }
28  __inline AttributeSet GetAttributeSet() const { return m_attribs; }
29 
30  __inline bool IsEmpty() const { return position.empty(); }
31 
32  //removes vertices, does not deallocate space
33  // if reserveSize != 0, ensures the array has enough space for at least that many elements
34  void Clear(uint32_t reserveSize = 0);
35 
36  // don't mix these
37  void Add(const vector3f &v);
38  void Add(const vector3f &v, const Color &c);
39  void Add(const vector3f &v, const Color &c, const vector3f &n);
40  void Add(const vector3f &v, const Color &c, const vector2f &uv);
41  void Add(const vector3f &v, const vector2f &uv);
42  void Add(const vector3f &v, const vector3f &n);
43  void Add(const vector3f &v, const vector3f &n, const vector2f &uv);
44  void Add(const vector3f &v, const vector3f &n, const vector2f &uv, const vector3f &tang);
45  //virtual void Reserve(unsigned int howmuch)
46 
47  // don't mix these
48  void Set(const Uint32 idx, const vector3f &v);
49  void Set(const Uint32 idx, const vector3f &v, const Color &c);
50  void Set(const Uint32 idx, const vector3f &v, const Color &c, const vector3f &normal);
51  void Set(const Uint32 idx, const vector3f &v, const Color &c, const vector2f &uv);
52  void Set(const Uint32 idx, const vector3f &v, const vector2f &uv);
53  void Set(const Uint32 idx, const vector3f &v, const vector3f &n);
54  void Set(const Uint32 idx, const vector3f &v, const vector3f &normal, const vector2f &uv);
55  void Set(const Uint32 idx, const vector3f &v, const vector3f &n, const vector2f &uv, const vector3f &tang);
56 
57  //could make these private, but it is nice to be able to
58  //add attributes separately...
59  std::vector<vector3f> position;
60  std::vector<vector3f> normal;
61  std::vector<Color> diffuse;
62  std::vector<vector2f> uv0;
63  std::vector<vector3f> tangent;
64 
65  private:
66  void Reserve(uint32_t size);
67  AttributeSet m_attribs;
68  };
69 
70 } // namespace Graphics
71 
72 #endif
Definition: VertexArray.h:19
std::vector< vector3f > tangent
Definition: VertexArray.h:63
void Clear(uint32_t reserveSize=0)
Definition: VertexArray.cpp:35
__inline Uint32 GetNumVerts() const
Definition: VertexArray.h:27
VertexArray(AttributeSet attribs, int size=0)
Definition: VertexArray.cpp:8
__inline bool IsEmpty() const
Definition: VertexArray.h:30
~VertexArray()
Definition: VertexArray.cpp:17
__inline AttributeSet GetAttributeSet() const
Definition: VertexArray.h:28
std::vector< vector3f > normal
Definition: VertexArray.h:60
std::vector< vector3f > position
Definition: VertexArray.h:59
void Set(const Uint32 idx, const vector3f &v)
Definition: VertexArray.cpp:99
__inline bool HasAttrib(const VertexAttrib v) const
Definition: VertexArray.h:26
std::vector< vector2f > uv0
Definition: VertexArray.h:62
std::vector< Color > diffuse
Definition: VertexArray.h:61
void Add(const vector3f &v)
Definition: VertexArray.cpp:47
Definition: Background.h:14
VertexAttrib
Definition: Types.h:12
Definition: Color.h:66
Definition: Types.h:27