Skip to content

Commit 0072a0b

Browse files
committed
Merge pull request #88684 from clayjohn/GLES3-visibility-notifier
Implement VisibilityNotifier3D in the compatibility backend
2 parents 45dd2bd + 3c2f30e commit 0072a0b

File tree

4 files changed

+63
-14
lines changed

4 files changed

+63
-14
lines changed

drivers/gles3/storage/utilities.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ RS::InstanceType Utilities::get_base_type(RID p_rid) const {
160160
return RS::INSTANCE_PARTICLES;
161161
} else if (GLES3::ParticlesStorage::get_singleton()->owns_particles_collision(p_rid)) {
162162
return RS::INSTANCE_PARTICLES_COLLISION;
163+
} else if (owns_visibility_notifier(p_rid)) {
164+
return RS::INSTANCE_VISIBLITY_NOTIFIER;
163165
}
164166
return RS::INSTANCE_NONE;
165167
}
@@ -207,6 +209,9 @@ bool Utilities::free(RID p_rid) {
207209
} else if (GLES3::MeshStorage::get_singleton()->owns_skeleton(p_rid)) {
208210
GLES3::MeshStorage::get_singleton()->skeleton_free(p_rid);
209211
return true;
212+
} else if (owns_visibility_notifier(p_rid)) {
213+
visibility_notifier_free(p_rid);
214+
return true;
210215
} else {
211216
return false;
212217
}
@@ -233,32 +238,69 @@ void Utilities::base_update_dependency(RID p_base, DependencyTracker *p_instance
233238
} else if (ParticlesStorage::get_singleton()->owns_particles_collision(p_base)) {
234239
Dependency *dependency = ParticlesStorage::get_singleton()->particles_collision_get_dependency(p_base);
235240
p_instance->update_dependency(dependency);
241+
} else if (owns_visibility_notifier(p_base)) {
242+
VisibilityNotifier *vn = get_visibility_notifier(p_base);
243+
p_instance->update_dependency(&vn->dependency);
236244
}
237245
}
238246

239247
/* VISIBILITY NOTIFIER */
240248

241249
RID Utilities::visibility_notifier_allocate() {
242-
return RID();
250+
return visibility_notifier_owner.allocate_rid();
243251
}
244252

245253
void Utilities::visibility_notifier_initialize(RID p_notifier) {
254+
visibility_notifier_owner.initialize_rid(p_notifier, VisibilityNotifier());
246255
}
247256

248257
void Utilities::visibility_notifier_free(RID p_notifier) {
258+
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
259+
vn->dependency.deleted_notify(p_notifier);
260+
visibility_notifier_owner.free(p_notifier);
249261
}
250262

251263
void Utilities::visibility_notifier_set_aabb(RID p_notifier, const AABB &p_aabb) {
264+
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
265+
ERR_FAIL_NULL(vn);
266+
vn->aabb = p_aabb;
267+
vn->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_AABB);
252268
}
253269

254270
void Utilities::visibility_notifier_set_callbacks(RID p_notifier, const Callable &p_enter_callbable, const Callable &p_exit_callable) {
271+
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
272+
ERR_FAIL_NULL(vn);
273+
vn->enter_callback = p_enter_callbable;
274+
vn->exit_callback = p_exit_callable;
255275
}
256276

257277
AABB Utilities::visibility_notifier_get_aabb(RID p_notifier) const {
258-
return AABB();
278+
const VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
279+
ERR_FAIL_NULL_V(vn, AABB());
280+
return vn->aabb;
259281
}
260282

261283
void Utilities::visibility_notifier_call(RID p_notifier, bool p_enter, bool p_deferred) {
284+
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
285+
ERR_FAIL_NULL(vn);
286+
287+
if (p_enter) {
288+
if (!vn->enter_callback.is_null()) {
289+
if (p_deferred) {
290+
vn->enter_callback.call_deferred();
291+
} else {
292+
vn->enter_callback.call();
293+
}
294+
}
295+
} else {
296+
if (!vn->exit_callback.is_null()) {
297+
if (p_deferred) {
298+
vn->exit_callback.call_deferred();
299+
} else {
300+
vn->exit_callback.call();
301+
}
302+
}
303+
}
262304
}
263305

264306
/* TIMING */

drivers/gles3/storage/utilities.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,25 @@
3939

4040
namespace GLES3 {
4141

42+
/* VISIBILITY NOTIFIER */
43+
44+
struct VisibilityNotifier {
45+
AABB aabb;
46+
Callable enter_callback;
47+
Callable exit_callback;
48+
Dependency dependency;
49+
};
50+
4251
class Utilities : public RendererUtilities {
4352
private:
4453
static Utilities *singleton;
4554

55+
/* VISIBILITY NOTIFIER */
56+
57+
mutable RID_Owner<VisibilityNotifier> visibility_notifier_owner;
58+
59+
/* MISC */
60+
4661
struct ResourceAllocation {
4762
#ifdef DEV_ENABLED
4863
String name;
@@ -149,6 +164,10 @@ class Utilities : public RendererUtilities {
149164
virtual void base_update_dependency(RID p_base, DependencyTracker *p_instance) override;
150165

151166
/* VISIBILITY NOTIFIER */
167+
168+
VisibilityNotifier *get_visibility_notifier(RID p_rid) { return visibility_notifier_owner.get_or_null(p_rid); };
169+
bool owns_visibility_notifier(RID p_rid) const { return visibility_notifier_owner.owns(p_rid); };
170+
152171
virtual RID visibility_notifier_allocate() override;
153172
virtual void visibility_notifier_initialize(RID p_notifier) override;
154173
virtual void visibility_notifier_free(RID p_notifier) override;

scene/3d/visible_on_screen_notifier_3d.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@ void VisibleOnScreenNotifier3D::_notification(int p_what) {
7979
}
8080
}
8181

82-
PackedStringArray VisibleOnScreenNotifier3D::get_configuration_warnings() const {
83-
PackedStringArray warnings = VisualInstance3D::get_configuration_warnings();
84-
85-
if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
86-
warnings.push_back(RTR("VisibleOnScreenNotifier3D nodes are not supported when using the GL Compatibility backend yet. Support will be added in a future release."));
87-
}
88-
89-
return warnings;
90-
}
91-
9282
void VisibleOnScreenNotifier3D::_bind_methods() {
9383
ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibleOnScreenNotifier3D::set_aabb);
9484
ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibleOnScreenNotifier3D::is_on_screen);

scene/3d/visible_on_screen_notifier_3d.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class VisibleOnScreenNotifier3D : public VisualInstance3D {
5757
virtual AABB get_aabb() const override;
5858
bool is_on_screen() const;
5959

60-
virtual PackedStringArray get_configuration_warnings() const override;
61-
6260
VisibleOnScreenNotifier3D();
6361
~VisibleOnScreenNotifier3D();
6462
};

0 commit comments

Comments
 (0)