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