diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-08 00:59:23 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-11 01:13:59 +0000 |
commit | 12d7acf095f885a97166ca16c6d274817ab342f7 (patch) | |
tree | adec614225b08ec1cceb55ea8a61ea0fb9370d47 /game | |
parent | Construct terrain tile AxisAlignedBoundingBox during mesh generation (diff) | |
download | ilt-12d7acf095f885a97166ca16c6d274817ab342f7.tar.bz2 ilt-12d7acf095f885a97166ca16c6d274817ab342f7.tar.xz ilt-12d7acf095f885a97166ca16c6d274817ab342f7.zip |
Current tile in frustum as we loop
Chunk by surface only, render if visible in frustum
Diffstat (limited to 'game')
-rw-r--r-- | game/terrain.cpp | 14 | ||||
-rw-r--r-- | game/terrain.h | 1 |
2 files changed, 5 insertions, 10 deletions
diff --git a/game/terrain.cpp b/game/terrain.cpp index dae295a..530b373 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -111,21 +111,17 @@ Terrain::render(const SceneShader & shader, const Frustum & frustum) const { grass->bind(); - std::ranges::for_each(meshes, [ext = getExtents(), &frustum](const auto & surfaceDef) { - surfaceDef.second.visible = frustum.contains(surfaceDef.second.aabb); - }); - const auto chunkBySurface = std::views::chunk_by([](const auto & itr1, const auto & itr2) { return itr1.first.surface == itr2.first.surface; }); - for (const auto & surfaceRange : meshes | std::views::filter([](const auto & itr) { - return itr.second.visible; - }) | chunkBySurface) { + for (const auto & surfaceRange : meshes | chunkBySurface) { const auto surface = surfaceRange.front().first.surface; shader.landmass.use(surface ? surface->colorBias : OPEN_SURFACE); for (const auto & sab : surfaceRange) { - glBindVertexArray(sab.second.vertexArray); - glDrawElements(GL_TRIANGLES, sab.second.count, GL_UNSIGNED_INT, nullptr); + if (frustum.contains(sab.second.aabb)) { + glBindVertexArray(sab.second.vertexArray); + glDrawElements(GL_TRIANGLES, sab.second.count, GL_UNSIGNED_INT, nullptr); + } } } glBindVertexArray(0); diff --git a/game/terrain.h b/game/terrain.h index 1d00f97..f38fe84 100644 --- a/game/terrain.h +++ b/game/terrain.h @@ -36,7 +36,6 @@ private: glBuffer indicesBuffer; GLsizei count; AxisAlignedBoundingBox aabb; - mutable bool visible; }; struct SurfaceKey { |