Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 1474c6735d9aebbf017986a32fe3fa9412f37961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
   model/vertexarray.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_MODEL_VERTEXARRAY_H__
#define __INCLUDED_MODEL_VERTEXARRAY_H__

#include "math/vector3f.h"

namespace model
{

// number of segments in a sphere circle, must be uneven
const int SPHERESEGMENTS = 65;

/// global geometry vertex array
/** a VertexArray acts like a stack of model vertices, it has no knowledge of what it is holding
 */
class VertexArray
{
public:
	/// create a new VertexArray with size in Mb
	VertexArray(size_t size);
	~VertexArray();

	/// clear array, set memory to 0
	void clear();
	
	/// print vertex array usage to console
	void info();

	size_t add_vertex(math::Vector3f const &v, math::Vector3f const &n, float tex_x = 0.0f, float tex_y = 0.0f);

	/// true when the array is full
	inline bool overflow() const {
		return vertexarray_overflow;
	}
	
	/// return true if the vertex data has changed and needs to uploaded to video memory
	inline bool dirty() const {
		return vertexarray_dirty;
	}
	
	/// pointer to model vertices, sequential in GL_T2F_N3F_V3F format
	inline const float *ptr() const {
		return vertexarray_data;
	}

	/// size of the vertex array in number of floats (for a single array)
	inline size_t size() const {
		return vertexarray_size;
	}

	/// number of allocated floats
	inline size_t index() const {
		return vertexarray_index;
	}
	
	inline void set_dirty(const bool dirty = true) {
		vertexarray_dirty = dirty;
	}

	static inline VertexArray *instance() {
		return vertexarray_instance;
	}

private:
	void add_sphere();
	
	size_t vertexarray_index;
	size_t vertexarray_size;
	
	/// model vertices, sequential in GL_T2F_N3F_V3F format
	float *vertexarray_data;

	bool vertexarray_overflow;
	bool vertexarray_dirty;
	
	static VertexArray *vertexarray_instance;
};

}

#endif // __INCLUDED_MODEL_VERTEXARRAY_H__