summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHilderin <81109165+Hilderin@users.noreply.github.com>2024-09-14 23:28:39 -0400
committerHilderin <81109165+Hilderin@users.noreply.github.com>2024-09-17 18:18:07 -0400
commitc11107b1fbcb67181f03ec1105953fe4808649fd (patch)
tree65b7de56cd3e803b5b468d136ebd1afd7deed017
parent6681f2563b99e14929a8acb27f4908fece398ef1 (diff)
downloadredot-engine-c11107b1fbcb67181f03ec1105953fe4808649fd.tar.gz
Fix Viewport Texture must be set to use it
-rw-r--r--scene/main/viewport.cpp25
-rw-r--r--scene/main/viewport.h1
2 files changed, 14 insertions, 12 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index de2332125f..20c4889e0d 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -111,6 +111,9 @@ void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
if (get_local_scene() && !path.is_empty()) {
setup_local_to_scene();
} else {
+ if (path.is_empty()) {
+ vp_changed = false;
+ }
emit_changed();
}
}
@@ -121,9 +124,7 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const {
int ViewportTexture::get_width() const {
if (!vp) {
- if (!vp_pending) {
- ERR_PRINT("Viewport Texture must be set to use it.");
- }
+ _err_print_viewport_not_set();
return 0;
}
return vp->size.width;
@@ -131,9 +132,7 @@ int ViewportTexture::get_width() const {
int ViewportTexture::get_height() const {
if (!vp) {
- if (!vp_pending) {
- ERR_PRINT("Viewport Texture must be set to use it.");
- }
+ _err_print_viewport_not_set();
return 0;
}
return vp->size.height;
@@ -141,9 +140,7 @@ int ViewportTexture::get_height() const {
Size2 ViewportTexture::get_size() const {
if (!vp) {
- if (!vp_pending) {
- ERR_PRINT("Viewport Texture must be set to use it.");
- }
+ _err_print_viewport_not_set();
return Size2();
}
return vp->size;
@@ -163,14 +160,18 @@ bool ViewportTexture::has_alpha() const {
Ref<Image> ViewportTexture::get_image() const {
if (!vp) {
- if (!vp_pending) {
- ERR_PRINT("Viewport Texture must be set to use it.");
- }
+ _err_print_viewport_not_set();
return Ref<Image>();
}
return RS::get_singleton()->texture_2d_get(vp->texture_rid);
}
+void ViewportTexture::_err_print_viewport_not_set() const {
+ if (!vp_pending && !vp_changed) {
+ ERR_PRINT("Viewport Texture must be set to use it.");
+ }
+}
+
void ViewportTexture::_setup_local_to_scene(const Node *p_loc_scene) {
// Always reset this, even if this call fails with an error.
vp_pending = false;
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index faa36851e9..16e963698b 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -63,6 +63,7 @@ class ViewportTexture : public Texture2D {
bool vp_changed = false;
void _setup_local_to_scene(const Node *p_loc_scene);
+ void _err_print_viewport_not_set() const;
mutable RID proxy_ph;
mutable RID proxy;