Skip to content

Commit

Permalink
Merge pull request #91846 from rburing/multimesh_cache_me_if_you_can
Browse files Browse the repository at this point in the history
Fix MultiMesh buffer cache in transforms-only case
  • Loading branch information
akien-mga committed May 14, 2024
2 parents 5ae85fc + a24cb7b commit d532bc5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions drivers/gles3/storage/mesh_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,11 @@ void MeshStorage::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_b
glBindBuffer(GL_ARRAY_BUFFER, 0);

} else {
// If we have a data cache, just update it.
if (multimesh->data_cache.size()) {
multimesh->data_cache = p_buffer;
}

// Only Transform is being used, so we can upload directly.
ERR_FAIL_COND(p_buffer.size() != (multimesh->instances * (int)multimesh->stride_cache));
const float *r = p_buffer.ptr();
Expand All @@ -1947,16 +1952,12 @@ void MeshStorage::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_b
multimesh->buffer_set = true;

if (multimesh->data_cache.size() || multimesh->uses_colors || multimesh->uses_custom_data) {
//if we have a data cache, just update it
multimesh->data_cache = multimesh->data_cache;
{
//clear dirty since nothing will be dirty anymore
uint32_t data_cache_dirty_region_count = Math::division_round_up(multimesh->instances, MULTIMESH_DIRTY_REGION_SIZE);
for (uint32_t i = 0; i < data_cache_dirty_region_count; i++) {
multimesh->data_cache_dirty_regions[i] = false;
}
multimesh->data_cache_used_dirty_regions = 0;
// Clear dirty since nothing will be dirty anymore.
uint32_t data_cache_dirty_region_count = Math::division_round_up(multimesh->instances, MULTIMESH_DIRTY_REGION_SIZE);
for (uint32_t i = 0; i < data_cache_dirty_region_count; i++) {
multimesh->data_cache_dirty_regions[i] = false;
}
multimesh->data_cache_used_dirty_regions = 0;

_multimesh_mark_all_dirty(multimesh, false, true); //update AABB
} else if (multimesh->mesh.is_valid()) {
Expand Down

0 comments on commit d532bc5

Please sign in to comment.