15
15
int Chunk_triangleCounter = 0 ;
16
16
int Chunk_triangleCounterTransparent = 0 ;
17
17
18
- void Chunk_AllocateMeshData (ChunkMesh * mesh , int triangleCount ) {
19
-
20
- mesh -> vertexCount = triangleCount * 2 ;
21
- mesh -> triangleCount = triangleCount ;
22
-
23
- mesh -> vertices = MemAlloc (mesh -> vertexCount * 3 );
24
- mesh -> texcoords = MemAlloc (mesh -> vertexCount * 2 * sizeof (unsigned short ));
25
- mesh -> colors = MemAlloc (mesh -> vertexCount );
26
- mesh -> indices = MemAlloc (mesh -> triangleCount * 3 * sizeof (unsigned short ));
27
- }
28
-
29
- void Chunk_ReAllocateMeshData (ChunkMesh * mesh , int triangleCount ) {
30
- mesh -> vertexCount = triangleCount * 2 ;
31
- mesh -> triangleCount = triangleCount ;
32
-
33
- mesh -> vertices = MemRealloc (mesh -> vertices , mesh -> vertexCount * 3 );
34
- mesh -> texcoords = MemRealloc (mesh -> texcoords , mesh -> vertexCount * 2 * sizeof (unsigned short ));
35
- mesh -> colors = MemRealloc (mesh -> colors , mesh -> vertexCount );
36
- mesh -> indices = MemRealloc (mesh -> indices ,mesh -> triangleCount * 3 * sizeof (unsigned short ));
18
+ unsigned char * vertices ;
19
+ unsigned short * indices ;
20
+ unsigned short * texcoords ;
21
+ unsigned char * colors ;
22
+
23
+ unsigned char * verticesT ;
24
+ unsigned short * indicesT ;
25
+ unsigned short * texcoordsT ;
26
+ unsigned char * colorsT ;
27
+
28
+ void Chunk_MeshGenerationInit (void ) {
29
+
30
+ int vertexCount = 2 * 6 * CHUNK_SIZE * 2 ;
31
+ int triangleCount = 2 * 6 * CHUNK_SIZE ;
32
+
33
+ vertices = MemAlloc (vertexCount * 3 );
34
+ texcoords = MemAlloc (vertexCount * 2 * sizeof (unsigned short ));
35
+ colors = MemAlloc (vertexCount );
36
+ indices = MemAlloc (triangleCount * 3 * sizeof (unsigned short ));
37
+
38
+ verticesT = MemAlloc (vertexCount * 3 );
39
+ texcoordsT = MemAlloc (vertexCount * 2 * sizeof (unsigned short ));
40
+ colorsT = MemAlloc (vertexCount );
41
+ indicesT = MemAlloc (triangleCount * 3 * sizeof (unsigned short ));
37
42
}
38
43
39
44
@@ -44,9 +49,6 @@ void Chunk_BuildMesh(Chunk *chunk) {
44
49
ChunkMesh_Unload (chunk -> meshTransparent );
45
50
}
46
51
47
- Chunk_AllocateMeshData (chunk -> mesh , 2 * 6 * CHUNK_SIZE );
48
- Chunk_AllocateMeshData (chunk -> meshTransparent , 2 * 6 * CHUNK_SIZE );
49
-
50
52
BlockMesh_ResetIndexes ();
51
53
Chunk_triangleCounter = 0 ;
52
54
Chunk_triangleCounterTransparent = 0 ;
@@ -66,11 +68,14 @@ void Chunk_BuildMesh(Chunk *chunk) {
66
68
}
67
69
}
68
70
69
- Chunk_ReAllocateMeshData (chunk -> mesh , Chunk_triangleCounter );
70
- Chunk_ReAllocateMeshData (chunk -> meshTransparent , Chunk_triangleCounterTransparent );
71
+ chunk -> mesh -> vertexCount = Chunk_triangleCounter * 2 ;
72
+ chunk -> mesh -> triangleCount = Chunk_triangleCounter ;
73
+
74
+ chunk -> meshTransparent -> vertexCount = Chunk_triangleCounterTransparent * 2 ;
75
+ chunk -> meshTransparent -> triangleCount = Chunk_triangleCounterTransparent ;
71
76
72
- ChunkMesh_Upload (chunk -> mesh );
73
- ChunkMesh_Upload (chunk -> meshTransparent );
77
+ ChunkMesh_Upload (chunk -> mesh , vertices , indices , texcoords , colors );
78
+ ChunkMesh_Upload (chunk -> meshTransparent , verticesT , indicesT , texcoordsT , colorsT );
74
79
75
80
chunk -> isBuilt = true;
76
81
}
@@ -131,10 +136,10 @@ void Chunk_AddFace(Chunk *chunk, ChunkMesh *mesh, Vector3 pos, BlockFace face, B
131
136
if (bTest || sprite ) {
132
137
if (renderType == BlockRenderType_Translucent ) {
133
138
Chunk_triangleCounterTransparent += 2 ;
134
- BlockMesh_AddFace (mesh , face , pos , blockDef , 1 , lightLevel );
139
+ BlockMesh_AddFace (verticesT , indicesT , texcoordsT , colorsT , face , pos , blockDef , 1 , lightLevel );
135
140
} else {
136
141
Chunk_triangleCounter += 2 ;
137
- BlockMesh_AddFace (mesh , face , pos , blockDef , 0 , lightLevel );
142
+ BlockMesh_AddFace (vertices , indices , texcoords , colors , face , pos , blockDef , 0 , lightLevel );
138
143
}
139
144
140
145
}
0 commit comments