summaryrefslogtreecommitdiffstats
path: root/editor/editor_resource_preview.cpp
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2024-07-22 14:44:14 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2024-07-22 14:44:14 +0200
commit78ba8b28041fa366e2263f8ad7d7070f640828be (patch)
tree9f6043934083ae382d5df0e967a4dd2c8eda0065 /editor/editor_resource_preview.cpp
parentf135f729b91e61e6844159a535a7474335ec8d52 (diff)
downloadredot-engine-78ba8b28041fa366e2263f8ad7d7070f640828be.tar.gz
Fix certain resource previews empty with GL compat
As an additional fix, the preview render request now ignores the main viewport hierarchy so previews don't pay the cost of re-rendering the whole editor and descendant viewports.
Diffstat (limited to 'editor/editor_resource_preview.cpp')
-rw-r--r--editor/editor_resource_preview.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp
index 742d29fef0..71865f7e8c 100644
--- a/editor/editor_resource_preview.cpp
+++ b/editor/editor_resource_preview.cpp
@@ -40,6 +40,7 @@
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/themes/editor_scale.h"
+#include "scene/main/window.h"
#include "scene/resources/image_texture.h"
#include "servers/rendering/rendering_server_default.h"
@@ -96,14 +97,25 @@ EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() {
}
void EditorResourcePreviewGenerator::DrawRequester::request_and_wait(RID p_viewport) const {
+ Callable request_vp_update_once = callable_mp(RS::get_singleton(), &RS::viewport_set_update_mode).bind(p_viewport, RS::VIEWPORT_UPDATE_ONCE);
+
if (EditorResourcePreview::get_singleton()->is_threaded()) {
- Callable request_vp_update_once = callable_mp(RS::get_singleton(), &RS::viewport_set_update_mode).bind(p_viewport, RS::VIEWPORT_UPDATE_ONCE);
RS::get_singleton()->connect(SNAME("frame_pre_draw"), request_vp_update_once, Object::CONNECT_ONE_SHOT);
RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<EditorResourcePreviewGenerator::DrawRequester *>(this), &EditorResourcePreviewGenerator::DrawRequester::_post_semaphore));
semaphore.wait();
} else {
+ // Avoid the main viewport and children being redrawn.
+ SceneTree *st = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
+ ERR_FAIL_NULL_MSG(st, "Editor's MainLoop is not a SceneTree. This is a bug.");
+ RID root_vp = st->get_root()->get_viewport_rid();
+ RenderingServer::get_singleton()->viewport_set_active(root_vp, false);
+
+ request_vp_update_once.call();
RS::get_singleton()->draw(false);
+
+ // Let main viewport and children be drawn again.
+ RenderingServer::get_singleton()->viewport_set_active(root_vp, true);
}
}