Revert "add experimental optimization"
This reverts commit 6dfbd5f401456b2b25e0e26bbca0164c9da17a62.
This commit is contained in:
parent
6dfbd5f401
commit
fb41b932fa
@ -106,6 +106,16 @@ bool WorldRenderer::drawChunk(
|
|||||||
if (mesh == nullptr) {
|
if (mesh == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (culling) {
|
||||||
|
glm::vec3 min(chunk->x * CHUNK_W, chunk->bottom, chunk->z * CHUNK_D);
|
||||||
|
glm::vec3 max(
|
||||||
|
chunk->x * CHUNK_W + CHUNK_W,
|
||||||
|
chunk->top,
|
||||||
|
chunk->z * CHUNK_D + CHUNK_D
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!frustumCulling->isBoxVisible(min, max)) return false;
|
||||||
|
}
|
||||||
glm::vec3 coord(chunk->x * CHUNK_W + 0.5f, 0.5f, chunk->z * CHUNK_D + 0.5f);
|
glm::vec3 coord(chunk->x * CHUNK_W + 0.5f, 0.5f, chunk->z * CHUNK_D + 0.5f);
|
||||||
glm::mat4 model = glm::translate(glm::mat4(1.0f), coord);
|
glm::mat4 model = glm::translate(glm::mat4(1.0f), coord);
|
||||||
shader->uniformMatrix("u_model", model);
|
shader->uniformMatrix("u_model", model);
|
||||||
@ -124,25 +134,9 @@ void WorldRenderer::drawChunks(
|
|||||||
|
|
||||||
// [warning] this whole method is not thread-safe for chunks
|
// [warning] this whole method is not thread-safe for chunks
|
||||||
|
|
||||||
bool culling = engine->getSettings().graphics.frustumCulling.get();
|
|
||||||
if (culling) {
|
|
||||||
frustumCulling->update(camera.getProjView());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<size_t> indices;
|
std::vector<size_t> indices;
|
||||||
for (size_t i = 0; i < chunks->getVolume(); i++) {
|
for (size_t i = 0; i < chunks->getVolume(); i++) {
|
||||||
auto chunk = chunks->getChunks()[i];
|
if (chunks->getChunks()[i] == nullptr) continue;
|
||||||
if (chunk == nullptr) continue;
|
|
||||||
if (culling) {
|
|
||||||
glm::vec3 min(chunk->x * CHUNK_W, chunk->bottom, chunk->z * CHUNK_D);
|
|
||||||
glm::vec3 max(
|
|
||||||
chunk->x * CHUNK_W + CHUNK_W,
|
|
||||||
chunk->top,
|
|
||||||
chunk->z * CHUNK_D + CHUNK_D
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!frustumCulling->isBoxVisible(min, max)) continue;
|
|
||||||
}
|
|
||||||
indices.emplace_back(i);
|
indices.emplace_back(i);
|
||||||
}
|
}
|
||||||
float px = camera.position.x / static_cast<float>(CHUNK_W) - 0.5f;
|
float px = camera.position.x / static_cast<float>(CHUNK_W) - 0.5f;
|
||||||
@ -157,7 +151,10 @@ void WorldRenderer::drawChunks(
|
|||||||
auto bdz = (b->z - pz);
|
auto bdz = (b->z - pz);
|
||||||
return (adx * adx + adz * adz > bdx * bdx + bdz * bdz);
|
return (adx * adx + adz * adz > bdx * bdx + bdz * bdz);
|
||||||
});
|
});
|
||||||
|
bool culling = engine->getSettings().graphics.frustumCulling.get();
|
||||||
|
if (culling) {
|
||||||
|
frustumCulling->update(camera.getProjView());
|
||||||
|
}
|
||||||
chunks->visible = 0;
|
chunks->visible = 0;
|
||||||
for (size_t i = 0; i < indices.size(); i++) {
|
for (size_t i = 0; i < indices.size(); i++) {
|
||||||
chunks->visible += drawChunk(indices[i], camera, shader, culling);
|
chunks->visible += drawChunk(indices[i], camera, shader, culling);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user