mirror of
https://github.com/godotengine/godot
synced 2024-09-06 03:03:33 +00:00
Merge pull request #87229 from RandomShaper/gl_preview_goodboy
Run resource previewer on the main thread if using GL compatibility
This commit is contained in:
commit
6bb89c71ff
|
@ -41,6 +41,7 @@
|
||||||
#include "editor/editor_settings.h"
|
#include "editor/editor_settings.h"
|
||||||
#include "editor/editor_string_names.h"
|
#include "editor/editor_string_names.h"
|
||||||
#include "scene/resources/image_texture.h"
|
#include "scene/resources/image_texture.h"
|
||||||
|
#include "servers/rendering/rendering_server_default.h"
|
||||||
|
|
||||||
bool EditorResourcePreviewGenerator::handles(const String &p_type) const {
|
bool EditorResourcePreviewGenerator::handles(const String &p_type) const {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
@ -338,6 +339,20 @@ void EditorResourcePreview::_thread() {
|
||||||
exited.set();
|
exited.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorResourcePreview::_idle_callback() {
|
||||||
|
if (!singleton) {
|
||||||
|
// Just in case the shutdown of the editor involves the deletion of the singleton
|
||||||
|
// happening while additional idle callbacks can happen.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process preview tasks, trying to leave a little bit of responsiveness worst case.
|
||||||
|
uint64_t start = OS::get_singleton()->get_ticks_msec();
|
||||||
|
while (!singleton->queue.is_empty() && OS::get_singleton()->get_ticks_msec() - start < 100) {
|
||||||
|
singleton->_iterate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EditorResourcePreview::_update_thumbnail_sizes() {
|
void EditorResourcePreview::_update_thumbnail_sizes() {
|
||||||
if (small_thumbnail_size == -1) {
|
if (small_thumbnail_size == -1) {
|
||||||
// Kind of a workaround to retrieve the default icon size.
|
// Kind of a workaround to retrieve the default icon size.
|
||||||
|
@ -441,13 +456,21 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorResourcePreview::start() {
|
void EditorResourcePreview::start() {
|
||||||
if (DisplayServer::get_singleton()->get_name() != "headless") {
|
if (DisplayServer::get_singleton()->get_name() == "headless") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RSG::texture_storage->can_create_resources_async()) {
|
||||||
ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started.");
|
ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started.");
|
||||||
thread.start(_thread_func, this);
|
thread.start(_thread_func, this);
|
||||||
|
} else {
|
||||||
|
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorResourcePreview::stop() {
|
void EditorResourcePreview::stop() {
|
||||||
|
if (RSG::texture_storage->can_create_resources_async()) {
|
||||||
if (thread.is_started()) {
|
if (thread.is_started()) {
|
||||||
exiting.set();
|
exiting.set();
|
||||||
preview_sem.post();
|
preview_sem.post();
|
||||||
|
@ -464,6 +487,7 @@ void EditorResourcePreview::stop() {
|
||||||
thread.wait_to_finish();
|
thread.wait_to_finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EditorResourcePreview::EditorResourcePreview() {
|
EditorResourcePreview::EditorResourcePreview() {
|
||||||
singleton = this;
|
singleton = this;
|
||||||
|
|
|
@ -103,7 +103,8 @@ class EditorResourcePreview : public Node {
|
||||||
int small_thumbnail_size = -1;
|
int small_thumbnail_size = -1;
|
||||||
|
|
||||||
static void _thread_func(void *ud);
|
static void _thread_func(void *ud);
|
||||||
void _thread();
|
void _thread(); // For rendering drivers supporting async texture creation.
|
||||||
|
static void _idle_callback(); // For other rendering drivers (i.e., OpenGL).
|
||||||
void _iterate();
|
void _iterate();
|
||||||
|
|
||||||
void _write_preview_cache(Ref<FileAccess> p_file, int p_thumbnail_size, bool p_has_small_texture, uint64_t p_modified_time, String p_hash, const Dictionary &p_metadata);
|
void _write_preview_cache(Ref<FileAccess> p_file, int p_thumbnail_size, bool p_has_small_texture, uint64_t p_modified_time, String p_hash, const Dictionary &p_metadata);
|
||||||
|
|
Loading…
Reference in a new issue