diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2024-02-21 10:44:21 +0100 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2024-02-21 10:44:21 +0100 |
commit | 91f0a65fc90ef9550ad1c0d3fc857017a4f844d4 (patch) | |
tree | ea4f199176012398984af5c6a70809935ecbc62f /editor/editor_resource_preview.cpp | |
parent | fb10e67fefb85af3b8f5abd30db561588d8456c6 (diff) | |
download | redot-engine-91f0a65fc90ef9550ad1c0d3fc857017a4f844d4.tar.gz |
Rework viewport capture in preview generation
Diffstat (limited to 'editor/editor_resource_preview.cpp')
-rw-r--r-- | editor/editor_resource_preview.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index bae7887c02..fc1dda9669 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -95,8 +95,35 @@ void EditorResourcePreviewGenerator::_bind_methods() { EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() { } +void EditorResourcePreviewGenerator::DrawRequester::request_and_wait(RID p_viewport) const { + 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 { + RS::get_singleton()->draw(false); + } +} + +void EditorResourcePreviewGenerator::DrawRequester::abort() const { + if (EditorResourcePreview::get_singleton()->is_threaded()) { + semaphore.post(); + } +} + +Variant EditorResourcePreviewGenerator::DrawRequester::_post_semaphore() const { + semaphore.post(); + return Variant(); // Needed because of how the callback is used. +} + EditorResourcePreview *EditorResourcePreview::singleton = nullptr; +bool EditorResourcePreview::is_threaded() const { + return RSG::texture_storage->can_create_resources_async(); +} + void EditorResourcePreview::_thread_func(void *ud) { EditorResourcePreview *erp = (EditorResourcePreview *)ud; erp->_thread(); @@ -470,7 +497,7 @@ void EditorResourcePreview::start() { return; } - if (RSG::texture_storage->can_create_resources_async()) { + if (is_threaded()) { ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started."); thread.start(_thread_func, this); } else { @@ -481,7 +508,7 @@ void EditorResourcePreview::start() { } void EditorResourcePreview::stop() { - if (RSG::texture_storage->can_create_resources_async()) { + if (is_threaded()) { if (thread.is_started()) { exiting.set(); preview_sem.post(); |