### Godot version

v4.1.dev.custom_build [18112ba36]

### System information

Linux Mint 21.1, NVIDIA GeForce GTX 1050 Ti,  Vulkan API 1.3.205

### Issue description

This is a regression from #64388. 

Textures seem to be used differently in 2D and 3D. They are rendered using the `RID` in 3D, and changing the `viewport_path` will cause the `RID` to change.

https://github.com/godotengine/godot/assets/30386067/ad393fe8-50c1-4a89-870d-58d4e224bcc6


### Steps to reproduce

1. Download and import MRP.
2. Open 1.tscn, and try to switch the `viewport_path` of the `MeshInstance3D:mesh:material:albedo_texture` in the MeshInstance3D node.
3. After switching, the MeshInstance3D is rendered as white in the editor;
4. Close and then reopen 1.tscn.

### Minimal reproduction project

[ViewportTexture-change-viewport_path.zip](https://github.com/godotengine/godot/files/11509010/ViewportTexture-change-viewport_path.zip)

if (viewport_under) {
				if (viewport_under != this) {
					Transform2D ai = viewport_under->get_final_transform().affine_inverse();
					viewport_pos = ai.xform(viewport_pos);
				}
				
				gui.drag_mouse_over = viewport_under->gui_find_control(viewport_pos);
				if (gui.drag_mouse_over) {
					Transform2D localizer = gui.drag_mouse_over->get_global_transform_with_canvas().affine_inverse();
					gui.drag_mouse_over_pos = localizer.xform(viewport_pos);
					bool can_drop = _gui_drop(gui.drag_mouse_over, gui.drag_mouse_over_pos, true);
					if (!can_drop) {
						ds_cursor_shape = DisplayServer::CURSOR_FORBIDDEN;
					} else {
						ds_cursor_shape = DisplayServer::CURSOR_CAN_DROP;
					}
				}
			} else {
				gui.drag_mouse_over = nullptr;
			}
		}
		if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE)) {
			DisplayServer::get_singleton()->cursor_set_shape(ds_cursor_shape);
		}
	}
	Ref<InputEventScreenTouch> touch_event = p_event;
	if (touch_event.is_valid()) {
		Size2 pos = touch_event->get_position();
		const int touch_index = touch_event->get_index();
		if (touch_event->is_pressed()) {