3
3
//
4
4
5
5
#include " include/chunk_mesh.h"
6
- #include " include/chunk.h"
7
- #include " ../../../lib/include/lib.h"
6
+ #include " ../../lib/include/lib.h"
8
7
9
8
10
- ChunkMesh::ChunkMesh () {
9
+ ChunkMesh::ChunkMesh () : m_chunkMeshState(UnBuilt) {
11
10
static bool indexBufferInitialized = false ;
12
11
static IndexBuffer indexBuffer;
13
12
if (!indexBufferInitialized) {
@@ -31,30 +30,25 @@ ChunkMesh::ChunkMesh() {
31
30
delete[] buffer;
32
31
}
33
32
34
- for (int i = 0 ; i < vao .size (); i++) {
35
- vao .at (i).bind ();
36
- vbo .at (i).bind ();
33
+ for (int i = 0 ; i < m_vao .size (); i++) {
34
+ m_vao .at (i).bind ();
35
+ m_vbo .at (i).bind ();
37
36
indexBuffer.bind ();
38
37
39
- vbo .at (i).vertexAttribPointer (0 , 3 , GL_FLOAT, GL_FALSE, sizeof (Vertex),
40
- (void *) (offsetof (Vertex, position)));
41
- vbo .at (i).vertexAttribPointer (1 , 2 , GL_FLOAT, GL_FALSE, sizeof (Vertex),
42
- (void *) (offsetof (Vertex, uvs)));
43
- vbo .at (i).vertexAttribIPointer (2 , 1 , GL_UNSIGNED_BYTE, sizeof (Vertex),
44
- (void *) offsetof (Vertex, lightningLevel));
38
+ m_vbo .at (i).vertexAttribPointer (0 , 3 , GL_FLOAT, GL_FALSE, sizeof (Vertex),
39
+ (void *) (offsetof (Vertex, position)));
40
+ m_vbo .at (i).vertexAttribPointer (1 , 2 , GL_FLOAT, GL_FALSE, sizeof (Vertex),
41
+ (void *) (offsetof (Vertex, uvs)));
42
+ m_vbo .at (i).vertexAttribIPointer (2 , 1 , GL_UNSIGNED_BYTE, sizeof (Vertex),
43
+ (void *) offsetof (Vertex, lightningLevel));
45
44
46
- vao .at (i).unbind ();
45
+ m_vao .at (i).unbind ();
47
46
}
48
47
49
48
}
50
49
51
- ChunkMesh::~ChunkMesh () {
52
-
53
- }
54
-
55
50
void ChunkMesh::setMesh (std::array<std::vector<Vertex>, 3 >& vertices) {
56
51
for (int i = 0 ; i < vertices.size (); i++) {
57
- indicesCount.at (i) = 0 ;
58
52
std::string type;
59
53
if (i == 0 ){
60
54
type = " normal" ;
@@ -69,37 +63,40 @@ void ChunkMesh::setMesh(std::array<std::vector<Vertex>, 3>& vertices) {
69
63
(std::to_string (vertices.at (i).size ()) + type +
70
64
" m_vertices" ).c_str ());
71
65
if (!vertices.at (i).empty ()) {
72
- vbo .at (i).bind ();
73
- vbo .at (i).bufferData (vertices.at (i).size () * sizeof (Vertex), &vertices.at (i)[0 ], GL_STATIC_DRAW);
74
- indicesCount .at (i) = std::floor (vertices.at (i).size () / 4 ) * 6 ;
66
+ m_vbo .at (i).bind ();
67
+ m_vbo .at (i).bufferData (vertices.at (i).size () * sizeof (Vertex), &vertices.at (i)[0 ], GL_STATIC_DRAW);
68
+ m_indicesCount .at (i) = std::floor (vertices.at (i).size () / 4 ) * 6 ;
75
69
vertices.at (i).clear ();
76
70
}
71
+ else {
72
+ m_indicesCount.at (i) = 0 ;
73
+ }
77
74
78
75
}
79
76
}
80
77
81
78
VertexArray* ChunkMesh::getVao () {
82
- return &vao .at (0 );
79
+ return &m_vao .at (0 );
83
80
}
84
81
85
82
VertexArray* ChunkMesh::getTransparentVao () {
86
- return &vao .at (1 );
83
+ return &m_vao .at (1 );
87
84
}
88
85
89
86
VertexArray* ChunkMesh::getModelVao () {
90
- return &vao .at (2 );
87
+ return &m_vao .at (2 );
91
88
}
92
89
93
90
unsigned int ChunkMesh::getIndicesCount () {
94
- return indicesCount .at (0 );
91
+ return m_indicesCount .at (0 );
95
92
}
96
93
97
94
unsigned int ChunkMesh::getTransparentIndicesCount () {
98
- return indicesCount .at (1 );
95
+ return m_indicesCount .at (1 );
99
96
}
100
97
101
98
unsigned int ChunkMesh::getModelIndicesCount () {
102
- return indicesCount .at (2 );
99
+ return m_indicesCount .at (2 );
103
100
}
104
101
105
102
0 commit comments