summaryrefslogtreecommitdiffstats
path: root/drivers/gles3/storage/mesh_storage.cpp
diff options
context:
space:
mode:
authorArman Elgudzhyan <48544263+puchik@users.noreply.github.com>2023-07-22 20:53:39 -0700
committerArman Elgudzhyan <48544263+puchik@users.noreply.github.com>2024-02-15 22:37:07 -0800
commit7ac8365e1122299eaf783310bf61c3c8148579cc (patch)
treed9c3c4a716366c8b429c64b63eb0de2458370ff6 /drivers/gles3/storage/mesh_storage.cpp
parenta9bb8509f2faac81bdb995c6c89a5347372f3498 (diff)
downloadredot-engine-7ac8365e1122299eaf783310bf61c3c8148579cc.tar.gz
Support custom AABB within MultiMesh resources
- Supporting custom AABB on the MultiMesh resource itself allows us to prevent costly runtime AABB recalculations. - Should also help improve CPU Particle performance.
Diffstat (limited to 'drivers/gles3/storage/mesh_storage.cpp')
-rw-r--r--drivers/gles3/storage/mesh_storage.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/drivers/gles3/storage/mesh_storage.cpp b/drivers/gles3/storage/mesh_storage.cpp
index 928e4e23ce..6c4bef10d5 100644
--- a/drivers/gles3/storage/mesh_storage.cpp
+++ b/drivers/gles3/storage/mesh_storage.cpp
@@ -1607,6 +1607,9 @@ void MeshStorage::_multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, b
void MeshStorage::_multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances) {
ERR_FAIL_COND(multimesh->mesh.is_null());
+ if (multimesh->custom_aabb != AABB()) {
+ return;
+ }
AABB aabb;
AABB mesh_aabb = mesh_get_aabb(multimesh->mesh);
for (int i = 0; i < p_instances; i++) {
@@ -1749,9 +1752,25 @@ RID MeshStorage::multimesh_get_mesh(RID p_multimesh) const {
return multimesh->mesh;
}
+void MeshStorage::multimesh_set_custom_aabb(RID p_multimesh, const AABB &p_aabb) {
+ MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
+ ERR_FAIL_NULL(multimesh);
+ multimesh->custom_aabb = p_aabb;
+ multimesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_AABB);
+}
+
+AABB MeshStorage::multimesh_get_custom_aabb(RID p_multimesh) const {
+ MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
+ ERR_FAIL_NULL_V(multimesh, AABB());
+ return multimesh->custom_aabb;
+}
+
AABB MeshStorage::multimesh_get_aabb(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
ERR_FAIL_NULL_V(multimesh, AABB());
+ if (multimesh->custom_aabb != AABB()) {
+ return multimesh->custom_aabb;
+ }
if (multimesh->aabb_dirty) {
const_cast<MeshStorage *>(this)->_update_dirty_multimeshes();
}
@@ -1943,8 +1962,10 @@ void MeshStorage::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_b
//if we have a mesh set, we need to re-generate the AABB from the new data
const float *data = p_buffer.ptr();
- _multimesh_re_create_aabb(multimesh, data, multimesh->instances);
- multimesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_AABB);
+ if (multimesh->custom_aabb != AABB()) {
+ _multimesh_re_create_aabb(multimesh, data, multimesh->instances);
+ multimesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_AABB);
+ }
}
}
@@ -2091,9 +2112,11 @@ void MeshStorage::_update_dirty_multimeshes() {
}
if (multimesh->aabb_dirty && multimesh->mesh.is_valid()) {
- _multimesh_re_create_aabb(multimesh, data, visible_instances);
multimesh->aabb_dirty = false;
- multimesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_AABB);
+ if (multimesh->custom_aabb != AABB()) {
+ _multimesh_re_create_aabb(multimesh, data, visible_instances);
+ multimesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_AABB);
+ }
}
}