From 12d7acf095f885a97166ca16c6d274817ab342f7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 8 Mar 2025 00:59:23 +0000 Subject: Current tile in frustum as we loop Chunk by surface only, render if visible in frustum --- game/terrain.cpp | 14 +++++--------- game/terrain.h | 1 - test/Jamfile.jam | 3 ++- test/perf-terrain.cpp | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 11 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 { diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 8219398..bedc2ad 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -71,5 +71,6 @@ explicit perf-assetFactory ; explicit perf-persistence ; explicit perf-geoData ; explicit perf-instancing ; -alias perf : perf-assetFactory perf-persistence perf-geoData perf-instancing ; +explicit perf-terrain ; +alias perf : perf-assetFactory perf-persistence perf-geoData perf-instancing perf-terrain ; explicit perf ; diff --git a/test/perf-terrain.cpp b/test/perf-terrain.cpp index 81cb16c..e75f80b 100644 --- a/test/perf-terrain.cpp +++ b/test/perf-terrain.cpp @@ -1,4 +1,7 @@ #include "game/terrain.h" +#include "gfx/camera.h" +#include "gfx/frustum.h" +#include "gfx/gl/sceneShader.h" #include "testMainWindow.h" #include @@ -14,8 +17,22 @@ namespace { terrain.generateMeshes(); } } + + void + terrainRender(benchmark::State & state) + { + Terrain terrain {GeoData::loadFromAsciiGrid(FIXTURESDIR "height/SD19.asc")}; + SceneShader shader; + Camera cam {terrain.getExtents().min + GlobalPosition3D {0, 0, 10000}, 45.F, 1.F, 1, 10000}; + cam.setForward(::north + ::east); + + for (auto _ : state) { + terrain.render(shader, cam); + } + } } BENCHMARK(terrainMeshgen); +BENCHMARK(terrainRender); BENCHMARK_MAIN(); -- cgit v1.2.3