diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2024-07-22 14:44:14 +0200 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2024-07-22 14:44:14 +0200 |
commit | 78ba8b28041fa366e2263f8ad7d7070f640828be (patch) | |
tree | 9f6043934083ae382d5df0e967a4dd2c8eda0065 | |
parent | f135f729b91e61e6844159a535a7474335ec8d52 (diff) | |
download | redot-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.
-rw-r--r-- | editor/editor_resource_preview.cpp | 14 |
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); } } |