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.
This commit is contained in:
Pedro J. Estébanez 2024-07-22 14:44:14 +02:00
parent f135f729b9
commit 78ba8b2804

View file

@ -40,6 +40,7 @@
#include "editor/editor_settings.h" #include "editor/editor_settings.h"
#include "editor/editor_string_names.h" #include "editor/editor_string_names.h"
#include "editor/themes/editor_scale.h" #include "editor/themes/editor_scale.h"
#include "scene/main/window.h"
#include "scene/resources/image_texture.h" #include "scene/resources/image_texture.h"
#include "servers/rendering/rendering_server_default.h" #include "servers/rendering/rendering_server_default.h"
@ -96,14 +97,25 @@ EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() {
} }
void EditorResourcePreviewGenerator::DrawRequester::request_and_wait(RID p_viewport) const { 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()) { 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()->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)); RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<EditorResourcePreviewGenerator::DrawRequester *>(this), &EditorResourcePreviewGenerator::DrawRequester::_post_semaphore));
semaphore.wait(); semaphore.wait();
} else { } 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); RS::get_singleton()->draw(false);
// Let main viewport and children be drawn again.
RenderingServer::get_singleton()->viewport_set_active(root_vp, true);
} }
} }