mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 09:29:44 +00:00
optimize ChunksRenderer by reducing meshes map reads
This commit is contained in:
parent
3895ef020c
commit
156ba02750
2 changed files with 29 additions and 17 deletions
|
|
@ -315,6 +315,19 @@ void ChunksRenderer::drawChunks(
|
|||
if (chunk == nullptr) {
|
||||
continue;
|
||||
}
|
||||
int cx = chunk->x;
|
||||
int cz = chunk->z;
|
||||
if (culling) {
|
||||
glm::vec3 min(cx * CHUNK_W, chunk->bottom, cz * CHUNK_D);
|
||||
glm::vec3 max(
|
||||
cx * CHUNK_W + CHUNK_W, chunk->top, cz * CHUNK_D + CHUNK_D
|
||||
);
|
||||
|
||||
if (!frustum.isBoxVisible(min, max)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
auto found = meshes.find(glm::ivec2(chunk->x, chunk->z));
|
||||
if (found == meshes.end()) {
|
||||
continue;
|
||||
|
|
@ -323,19 +336,19 @@ void ChunksRenderer::drawChunks(
|
|||
if (mesh.mesh == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (culling) {
|
||||
const auto& meshAABB = mesh.meshAABB;
|
||||
auto aabbMin = meshAABB.min();
|
||||
auto aabbMax = meshAABB.max();
|
||||
|
||||
glm::vec3 min(
|
||||
chunk->x * CHUNK_W + std::min(0.0f, aabbMin.x),
|
||||
cx * CHUNK_W + std::min(0.0f, aabbMin.x),
|
||||
chunk->bottom,
|
||||
chunk->z * CHUNK_D + std::min(0.0f, aabbMin.z)
|
||||
cz * CHUNK_D + std::min(0.0f, aabbMin.z)
|
||||
);
|
||||
glm::vec3 max(
|
||||
chunk->x * CHUNK_W + aabbMax.x,
|
||||
chunk->top,
|
||||
chunk->z * CHUNK_D + aabbMax.z
|
||||
cx * CHUNK_W + aabbMax.x, chunk->top, cz * CHUNK_D + aabbMax.z
|
||||
);
|
||||
|
||||
if (!frustum.isBoxVisible(min, max)) {
|
||||
|
|
@ -388,22 +401,23 @@ void ChunksRenderer::drawSortedMeshes(const Camera& camera, Shader& shader) {
|
|||
if (chunk == nullptr || !chunk->flags.lighted) {
|
||||
continue;
|
||||
}
|
||||
const auto& found = meshes.find(glm::ivec2(chunk->x, chunk->z));
|
||||
if (found == meshes.end() || found->second.sortingMeshData.entries.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int cx = chunk->x;
|
||||
int cz = chunk->z;
|
||||
if (culling) {
|
||||
glm::vec3 min(chunk->x * CHUNK_W, chunk->bottom, chunk->z * CHUNK_D);
|
||||
glm::vec3 min(cx * CHUNK_W, chunk->bottom, cz * CHUNK_D);
|
||||
glm::vec3 max(
|
||||
chunk->x * CHUNK_W + CHUNK_W,
|
||||
chunk->top,
|
||||
chunk->z * CHUNK_D + CHUNK_D
|
||||
cx * CHUNK_W + CHUNK_W, chunk->top, cz * CHUNK_D + CHUNK_D
|
||||
);
|
||||
|
||||
if (!frustum.isBoxVisible(min, max)) continue;
|
||||
}
|
||||
|
||||
const auto& found = meshes.find(glm::ivec2(cx, cz));
|
||||
if (found == meshes.end() || found->second.sortingMeshData.entries.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto& chunkEntries = found->second.sortingMeshData.entries;
|
||||
|
||||
if (chunkEntries.size() == 1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue