Moved occlusion test expiry code from KRScene::render to a dedicated function, KRViewport::expireOcclusionResults

This commit is contained in:
2024-09-21 21:21:48 -07:00
parent 8bee10c768
commit 3b9a5d6f81
6 changed files with 34 additions and 33 deletions

View File

@@ -34,6 +34,8 @@
#include "KRViewport.h"
const long KRENGINE_OCCLUSION_TEST_EXPIRY = 10;
using namespace hydra;
KRViewport::KRViewport()
@@ -283,7 +285,19 @@ bool KRViewport::visible(const AABB& b) const
return is_visible;
}
void KRViewport::expireOcclusionResults(long frame)
{
// Expire cached occlusion test results.
// Cached "failed" results are expired on the next frame (marked with .second of -1)
// Cached "success" results are expired after KRENGINE_OCCLUSION_TEST_EXPIRY frames (marked with .second of the last frame
std::set<AABB> expired_visible_bounds;
for (unordered_map<AABB, int>::iterator visible_bounds_itr = m_visibleBounds.begin(); visible_bounds_itr != m_visibleBounds.end(); visible_bounds_itr++) {
if ((*visible_bounds_itr).second == -1 || (*visible_bounds_itr).second + KRENGINE_OCCLUSION_TEST_EXPIRY < frame) {
expired_visible_bounds.insert((*visible_bounds_itr).first);
}
}
for (std::set<AABB>::iterator expired_visible_bounds_itr = expired_visible_bounds.begin(); expired_visible_bounds_itr != expired_visible_bounds.end(); expired_visible_bounds_itr++) {
m_visibleBounds.erase(*expired_visible_bounds_itr);
}
}