Merge pull request #97029 from Hilderin/fix-viewport-texture-must-be-set-to-use-it

Fix Viewport Texture must be set to use it
This commit is contained in:
Rémi Verschelde 2024-09-18 11:15:39 +02:00
commit 2a8d30aa9f
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 14 additions and 12 deletions

View file

@ -111,6 +111,9 @@ void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
if (get_local_scene() && !path.is_empty()) { if (get_local_scene() && !path.is_empty()) {
setup_local_to_scene(); setup_local_to_scene();
} else { } else {
if (path.is_empty()) {
vp_changed = false;
}
emit_changed(); emit_changed();
} }
} }
@ -121,9 +124,7 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const {
int ViewportTexture::get_width() const { int ViewportTexture::get_width() const {
if (!vp) { if (!vp) {
if (!vp_pending) { _err_print_viewport_not_set();
ERR_PRINT("Viewport Texture must be set to use it.");
}
return 0; return 0;
} }
return vp->size.width; return vp->size.width;
@ -131,9 +132,7 @@ int ViewportTexture::get_width() const {
int ViewportTexture::get_height() const { int ViewportTexture::get_height() const {
if (!vp) { if (!vp) {
if (!vp_pending) { _err_print_viewport_not_set();
ERR_PRINT("Viewport Texture must be set to use it.");
}
return 0; return 0;
} }
return vp->size.height; return vp->size.height;
@ -141,9 +140,7 @@ int ViewportTexture::get_height() const {
Size2 ViewportTexture::get_size() const { Size2 ViewportTexture::get_size() const {
if (!vp) { if (!vp) {
if (!vp_pending) { _err_print_viewport_not_set();
ERR_PRINT("Viewport Texture must be set to use it.");
}
return Size2(); return Size2();
} }
return vp->size; return vp->size;
@ -163,14 +160,18 @@ bool ViewportTexture::has_alpha() const {
Ref<Image> ViewportTexture::get_image() const { Ref<Image> ViewportTexture::get_image() const {
if (!vp) { if (!vp) {
if (!vp_pending) { _err_print_viewport_not_set();
ERR_PRINT("Viewport Texture must be set to use it.");
}
return Ref<Image>(); return Ref<Image>();
} }
return RS::get_singleton()->texture_2d_get(vp->texture_rid); 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) { void ViewportTexture::_setup_local_to_scene(const Node *p_loc_scene) {
// Always reset this, even if this call fails with an error. // Always reset this, even if this call fails with an error.
vp_pending = false; vp_pending = false;

View file

@ -63,6 +63,7 @@ class ViewportTexture : public Texture2D {
bool vp_changed = false; bool vp_changed = false;
void _setup_local_to_scene(const Node *p_loc_scene); void _setup_local_to_scene(const Node *p_loc_scene);
void _err_print_viewport_not_set() const;
mutable RID proxy_ph; mutable RID proxy_ph;
mutable RID proxy; mutable RID proxy;