Submit cached terrain patch draws by pointer

TerrainHeightmap::AppendCulledDrawRefs references the cached, shared-
geometry patch commands for the visible quadtree patches (writing the
background light into the cache) instead of copying them into a new
vector each frame. BuildCulledDraws keeps its copying behaviour on top
of it for existing callers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 17:21:41 +09:00
co-authored by Claude Opus 5.5
parent df87bc64eb
commit dcd301a080
4 changed files with 47 additions and 27 deletions
+19 -11
View File
@@ -640,6 +640,17 @@ void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float*
std::vector<Render3DDrawRef>* outRefs) {
if (!IsMapReady()) return;
// Background light written into the referenced (cached) terrain and map-object commands.
float lightDir[3], lightAmbient[3];
if (m_pCurrentEnvironment) {
std::copy_n(m_pCurrentEnvironment->dir_light.direction, 3, lightDir);
lightAmbient[0] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[0]);
lightAmbient[1] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[1]);
lightAmbient[2] = std::max(0.38f, m_pCurrentEnvironment->dir_light.bg_ambient[2]);
}
const float* refLightDir = m_pCurrentEnvironment ? lightDir : nullptr;
const float* refLightAmbient = m_pCurrentEnvironment ? lightAmbient : nullptr;
if (m_bVisiblePart[PART_SKY] && m_skybox && viewMatrix && projMatrix && camPos) {
auto sdraws = m_skybox->BuildDrawCommands(viewMatrix, projMatrix, camPos[0], camPos[1], camPos[2]);
for (auto& sd : sdraws) outDraws.push_back(std::move(sd));
@@ -647,10 +658,15 @@ void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float*
if (m_bVisiblePart[PART_TERRAIN] && m_terrain) {
std::vector<Render3DDraw> tdraws;
if (viewMatrix && projMatrix) {
bool referenced = false;
if (viewMatrix && projMatrix && outRefs) {
const size_t refCount = outRefs->size();
m_terrain->AppendCulledDrawRefs(viewMatrix, projMatrix, GetFarClip(), outDraws.size(), *outRefs, refLightDir, refLightAmbient);
referenced = outRefs->size() != refCount;
} else if (viewMatrix && projMatrix) {
tdraws = m_terrain->BuildCulledDraws(viewMatrix, projMatrix, GetFarClip());
}
if (tdraws.empty()) {
if (!referenced && tdraws.empty()) {
auto td = m_terrain->BuildDrawCommand(nullptr, 2);
if (!td.positions.empty()) tdraws.push_back(std::move(td));
}
@@ -681,15 +697,7 @@ void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float*
}
if (m_bVisiblePart[PART_OBJECT] && m_mapObjects && outRefs) {
float lightDir[3], lightAmbient[3];
if (m_pCurrentEnvironment) {
std::copy_n(m_pCurrentEnvironment->dir_light.direction, 3, lightDir);
lightAmbient[0] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[0]);
lightAmbient[1] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[1]);
lightAmbient[2] = std::max(0.38f, m_pCurrentEnvironment->dir_light.bg_ambient[2]);
}
m_mapObjects->AppendDrawRefs(viewMatrix, projMatrix, outDraws.size(), *outRefs,
m_pCurrentEnvironment ? lightDir : nullptr, m_pCurrentEnvironment ? lightAmbient : nullptr);
m_mapObjects->AppendDrawRefs(viewMatrix, projMatrix, outDraws.size(), *outRefs, refLightDir, refLightAmbient);
} else if (m_bVisiblePart[PART_OBJECT] && m_mapObjects) {
auto bdraws = m_mapObjects->BuildDrawCommands(viewMatrix, projMatrix);
for (auto& bd : bdraws) {