Skip to content

Commit

Permalink
Merge pull request godotengine#94619 from RandomShaper/fix_gl_prev
Browse files Browse the repository at this point in the history
Fix certain resource previews empty with GL compat
  • Loading branch information
akien-mga committed Jul 22, 2024
2 parents 9d8c2c9 + 78ba8b2 commit 88c4545
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion editor/editor_resource_preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 88c4545

Please sign in to comment.