diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_export.cpp | 14 | ||||
-rw-r--r-- | editor/editor_node.cpp | 99 | ||||
-rw-r--r-- | editor/editor_node.h | 12 | ||||
-rw-r--r-- | editor/editor_resource_preview.cpp | 217 | ||||
-rw-r--r-- | editor/editor_resource_preview.h | 9 | ||||
-rw-r--r-- | editor/plugins/node_3d_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/project_manager.cpp | 7 |
8 files changed, 213 insertions, 149 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 2010ee01db..372d01d89a 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -1491,12 +1491,15 @@ void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, in } String EditorExportPlatform::test_etc2() const { + // String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); + // bool etc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc"); + // bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); bool etc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc"); bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); - if (driver == "GLES2" && !etc_supported) { - return TTR("Target platform requires 'ETC' texture compression for GLES2. Enable 'Import Etc' in Project Settings."); + if (driver == "OpenGL3" && !etc_supported) { + return TTR("Target platform requires 'ETC' texture compression for OpenGL. Enable 'Import Etc' in Project Settings."); } else if (driver == "Vulkan" && !etc2_supported) { // FIXME: Review if this is true for Vulkan. return TTR("Target platform requires 'ETC2' texture compression for Vulkan. Enable 'Import Etc 2' in Project Settings."); @@ -1508,9 +1511,12 @@ String EditorExportPlatform::test_etc2_or_pvrtc() const { String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); bool pvrtc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_pvrtc"); + // String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); + // bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); + // bool pvrtc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_pvrtc"); - if (driver == "GLES2" && !pvrtc_supported) { - return TTR("Target platform requires 'PVRTC' texture compression for GLES2. Enable 'Import Pvrtc' in Project Settings."); + if (driver == "OpenGL3" && !pvrtc_supported) { + return TTR("Target platform requires 'PVRTC' texture compression for OpenGL. Enable 'Import Pvrtc' in Project Settings."); } else if (driver == "Vulkan" && !etc2_supported && !pvrtc_supported) { // FIXME: Review if this is true for Vulkan. return TTR("Target platform requires 'ETC2' or 'PVRTC' texture compression for Vulkan. Enable 'Import Etc 2' or 'Import Pvrtc' in Project Settings."); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 288b6752ee..9edf0a24fc 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -589,6 +589,11 @@ void EditorNode::_notification(int p_what) { settings_changed = false; emit_signal(SNAME("project_settings_changed")); } + + ResourceImporterTexture::get_singleton()->update_imports(); + + // if using a main thread only renderer, we need to update the resource previews + EditorResourcePreview::get_singleton()->update(); } break; case NOTIFICATION_ENTER_TREE: { @@ -2903,8 +2908,13 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { OS::get_singleton()->shell_open("https://godotengine.org/donate"); } break; - case SET_VIDEO_DRIVER_SAVE_AND_RESTART: { - ProjectSettings::get_singleton()->set("rendering/driver/driver_name", video_driver_request); + // case SET_VIDEO_DRIVER_SAVE_AND_RESTART: { + // ProjectSettings::get_singleton()->set("rendering/driver/driver_name", video_driver_request); + // save_all_scenes(); + // restart_editor(); + // } break; + case SET_RENDERING_DRIVER_SAVE_AND_RESTART: { + ProjectSettings::get_singleton()->set("rendering/driver/driver_name", rendering_driver_request); ProjectSettings::get_singleton()->save(); save_all_scenes(); @@ -5585,17 +5595,16 @@ void EditorNode::_bottom_panel_raise_toggled(bool p_pressed) { top_split->set_visible(!p_pressed); } -void EditorNode::_update_video_driver_color() { - // TODO: Probably should de-hardcode this and add to editor settings. - if (video_driver->get_text() == "GLES2") { - video_driver->add_theme_color_override("font_color", Color::hex(0x5586a4ff)); - } else if (video_driver->get_text() == "Vulkan") { - video_driver->add_theme_color_override("font_color", theme_base->get_theme_color(SNAME("vulkan_color"), SNAME("Editor"))); +void EditorNode::_update_rendering_driver_color() { + if (rendering_driver->get_text() == "opengl3") { + rendering_driver->add_theme_color_override("font_color", Color::hex(0x5586a4ff)); + } else if (rendering_driver->get_text() == "vulkan") { + rendering_driver->add_theme_color_override("font_color", theme_base->get_theme_color("vulkan_color", "Editor")); } } -void EditorNode::_video_driver_selected(int p_which) { - String driver = video_driver->get_item_metadata(p_which); +void EditorNode::_rendering_driver_selected(int p_which) { + String driver = rendering_driver->get_item_metadata(p_which); String current = ""; // OS::get_singleton()->get_video_driver_name(OS::get_singleton()->get_current_video_driver()); @@ -5603,10 +5612,10 @@ void EditorNode::_video_driver_selected(int p_which) { return; } - video_driver_request = driver; + rendering_driver_request = driver; video_restart_dialog->popup_centered(); - video_driver->select(video_driver_current); - _update_video_driver_color(); + rendering_driver->select(rendering_driver_current); + _update_rendering_driver_color(); } void EditorNode::_resource_saved(RES p_resource, const String &p_path) { @@ -6610,40 +6619,50 @@ EditorNode::EditorNode() { HBoxContainer *right_menu_hb = memnew(HBoxContainer); menu_hb->add_child(right_menu_hb); - // Toggle for video driver - video_driver = memnew(OptionButton); - video_driver->set_focus_mode(Control::FOCUS_NONE); - video_driver->connect("item_selected", callable_mp(this, &EditorNode::_video_driver_selected)); - video_driver->add_theme_font_override("font", gui_base->get_theme_font(SNAME("bold"), SNAME("EditorFonts"))); - video_driver->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"))); - // TODO: Show again when OpenGL is ported. - video_driver->set_visible(false); - right_menu_hb->add_child(video_driver); - -#ifndef _MSC_VER -#warning needs to be reimplemented -#endif -#if 0 - String video_drivers = ProjectSettings::get_singleton()->get_custom_property_info()["rendering/driver/driver_name"].hint_string; - String current_video_driver = OS::get_singleton()->get_video_driver_name(OS::get_singleton()->get_current_video_driver()); - video_driver_current = 0; - for (int i = 0; i < video_drivers.get_slice_count(","); i++) { - String driver = video_drivers.get_slice(",", i); - video_driver->add_item(driver); - video_driver->set_item_metadata(i, driver); + rendering_driver = memnew(OptionButton); + + // Hide the renderer selection dropdown until OpenGL support is more mature. + // The renderer can still be changed in the project settings or using `--rendering-driver opengl3`. + rendering_driver->set_visible(false); + + rendering_driver->set_flat(true); + rendering_driver->set_focus_mode(Control::FOCUS_NONE); + rendering_driver->connect("item_selected", callable_mp(this, &EditorNode::_rendering_driver_selected)); + rendering_driver->add_theme_font_override("font", gui_base->get_theme_font("bold", "EditorFonts")); + rendering_driver->add_theme_font_size_override("font_size", gui_base->get_theme_font_size("bold_size", "EditorFonts")); + + right_menu_hb->add_child(rendering_driver); - if (current_video_driver == driver) { - video_driver->select(i); - video_driver_current = i; + // Only display the render drivers that are available for this display driver. + int display_driver_idx = OS::get_singleton()->get_display_driver_id(); + Vector<String> render_drivers = DisplayServer::get_create_function_rendering_drivers(display_driver_idx); + String current_rendering_driver = OS::get_singleton()->get_current_rendering_driver_name(); + + // As we are doing string comparisons, keep in standard case to prevent problems with capitals + // "vulkan" in particular uses lowercase "v" in the code, and uppercase in the UI. + current_rendering_driver = current_rendering_driver.to_lower(); + + for (int i = 0; i < render_drivers.size(); i++) { + String driver = render_drivers[i]; + + // Add the driver to the UI. + rendering_driver->add_item(driver); + rendering_driver->set_item_metadata(i, driver); + + // Lowercase for standard comparison. + driver = driver.to_lower(); + + if (current_rendering_driver == driver) { + rendering_driver->select(i); + rendering_driver_current = i; } } + _update_rendering_driver_color(); - _update_video_driver_color(); -#endif video_restart_dialog = memnew(ConfirmationDialog); video_restart_dialog->set_text(TTR("Changing the video driver requires restarting the editor.")); video_restart_dialog->get_ok_button()->set_text(TTR("Save & Restart")); - video_restart_dialog->connect("confirmed", callable_mp(this, &EditorNode::_menu_option), varray(SET_VIDEO_DRIVER_SAVE_AND_RESTART)); + video_restart_dialog->connect("confirmed", callable_mp(this, &EditorNode::_menu_option), varray(SET_RENDERING_DRIVER_SAVE_AND_RESTART)); gui_base->add_child(video_restart_dialog); progress_hb = memnew(BackgroundProgress); diff --git a/editor/editor_node.h b/editor/editor_node.h index 03e5146d98..98aa4b697c 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -206,7 +206,7 @@ private: HELP_ABOUT, HELP_SUPPORT_GODOT_DEVELOPMENT, - SET_VIDEO_DRIVER_SAVE_AND_RESTART, + SET_RENDERING_DRIVER_SAVE_AND_RESTART, GLOBAL_NEW_WINDOW, GLOBAL_SCENE, @@ -222,14 +222,14 @@ private: Control *theme_base; Control *gui_base; VBoxContainer *main_vbox; - OptionButton *video_driver; + OptionButton *rendering_driver; ConfirmationDialog *video_restart_dialog; - int video_driver_current; - String video_driver_request; - void _video_driver_selected(int); - void _update_video_driver_color(); + int rendering_driver_current; + String rendering_driver_request; + void _rendering_driver_selected(int); + void _update_rendering_driver_color(); // Split containers diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 8783fe4fc0..e9c0b40268 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -210,126 +210,130 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref< } } -void EditorResourcePreview::_thread() { - exited.clear(); - while (!exit.is_set()) { - preview_sem.wait(); - preview_mutex.lock(); - - if (queue.size()) { - QueueItem item = queue.front()->get(); - queue.pop_front(); - - if (cache.has(item.path)) { - //already has it because someone loaded it, just let it know it's ready - String path = item.path; - if (item.resource.is_valid()) { - path += ":" + itos(cache[item.path].last_hash); //keep last hash (see description of what this is in condition below) - } - - _preview_ready(path, cache[item.path].preview, cache[item.path].small_preview, item.id, item.function, item.userdata); - - preview_mutex.unlock(); - } else { - preview_mutex.unlock(); +void EditorResourcePreview::_iterate() { + preview_mutex.lock(); + + if (queue.size()) { + QueueItem item = queue.front()->get(); + queue.pop_front(); + + if (cache.has(item.path)) { + //already has it because someone loaded it, just let it know it's ready + String path = item.path; + if (item.resource.is_valid()) { + path += ":" + itos(cache[item.path].last_hash); //keep last hash (see description of what this is in condition below) + } - Ref<ImageTexture> texture; - Ref<ImageTexture> small_texture; + _preview_ready(path, cache[item.path].preview, cache[item.path].small_preview, item.id, item.function, item.userdata); - int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size *= EDSCALE; + preview_mutex.unlock(); + } else { + preview_mutex.unlock(); - if (item.resource.is_valid()) { - _generate_preview(texture, small_texture, item, String()); + Ref<ImageTexture> texture; + Ref<ImageTexture> small_texture; - //adding hash to the end of path (should be ID:<objid>:<hash>) because of 5 argument limit to call_deferred - _preview_ready(item.path + ":" + itos(item.resource->hash_edited_version()), texture, small_texture, item.id, item.function, item.userdata); + int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + thumbnail_size *= EDSCALE; - } else { - String temp_path = EditorPaths::get_singleton()->get_cache_dir(); - String cache_base = ProjectSettings::get_singleton()->globalize_path(item.path).md5_text(); - cache_base = temp_path.plus_file("resthumb-" + cache_base); + if (item.resource.is_valid()) { + _generate_preview(texture, small_texture, item, String()); - //does not have it, try to load a cached thumbnail + //adding hash to the end of path (should be ID:<objid>:<hash>) because of 5 argument limit to call_deferred + _preview_ready(item.path + ":" + itos(item.resource->hash_edited_version()), texture, small_texture, item.id, item.function, item.userdata); - String file = cache_base + ".txt"; - FileAccess *f = FileAccess::open(file, FileAccess::READ); - if (!f) { - // No cache found, generate - _generate_preview(texture, small_texture, item, cache_base); - } else { - uint64_t modtime = FileAccess::get_modified_time(item.path); - int tsize = f->get_line().to_int(); - bool has_small_texture = f->get_line().to_int(); - uint64_t last_modtime = f->get_line().to_int(); + } else { + String temp_path = EditorPaths::get_singleton()->get_cache_dir(); + String cache_base = ProjectSettings::get_singleton()->globalize_path(item.path).md5_text(); + cache_base = temp_path.plus_file("resthumb-" + cache_base); - bool cache_valid = true; + //does not have it, try to load a cached thumbnail - if (tsize != thumbnail_size) { + String file = cache_base + ".txt"; + FileAccess *f = FileAccess::open(file, FileAccess::READ); + if (!f) { + // No cache found, generate + _generate_preview(texture, small_texture, item, cache_base); + } else { + uint64_t modtime = FileAccess::get_modified_time(item.path); + int tsize = f->get_line().to_int(); + bool has_small_texture = f->get_line().to_int(); + uint64_t last_modtime = f->get_line().to_int(); + + bool cache_valid = true; + + if (tsize != thumbnail_size) { + cache_valid = false; + memdelete(f); + } else if (last_modtime != modtime) { + String last_md5 = f->get_line(); + String md5 = FileAccess::get_md5(item.path); + memdelete(f); + + if (last_md5 != md5) { cache_valid = false; - memdelete(f); - } else if (last_modtime != modtime) { - String last_md5 = f->get_line(); - String md5 = FileAccess::get_md5(item.path); - memdelete(f); - if (last_md5 != md5) { - cache_valid = false; + } else { + //update modified time + f = FileAccess::open(file, FileAccess::WRITE); + if (!f) { + // Not returning as this would leave the thread hanging and would require + // some proper cleanup/disabling of resource preview generation. + ERR_PRINT("Cannot create file '" + file + "'. Check user write permissions."); } else { - //update modified time - - f = FileAccess::open(file, FileAccess::WRITE); - if (!f) { - // Not returning as this would leave the thread hanging and would require - // some proper cleanup/disabling of resource preview generation. - ERR_PRINT("Cannot create file '" + file + "'. Check user write permissions."); - } else { - f->store_line(itos(thumbnail_size)); - f->store_line(itos(has_small_texture)); - f->store_line(itos(modtime)); - f->store_line(md5); - memdelete(f); - } + f->store_line(itos(thumbnail_size)); + f->store_line(itos(has_small_texture)); + f->store_line(itos(modtime)); + f->store_line(md5); + memdelete(f); } - } else { - memdelete(f); } + } else { + memdelete(f); + } - if (cache_valid) { - Ref<Image> img; - img.instantiate(); - Ref<Image> small_img; - small_img.instantiate(); + if (cache_valid) { + Ref<Image> img; + img.instantiate(); + Ref<Image> small_img; + small_img.instantiate(); - if (img->load(cache_base + ".png") != OK) { - cache_valid = false; - } else { - texture.instantiate(); - texture->create_from_image(img); - - if (has_small_texture) { - if (small_img->load(cache_base + "_small.png") != OK) { - cache_valid = false; - } else { - small_texture.instantiate(); - small_texture->create_from_image(small_img); - } + if (img->load(cache_base + ".png") != OK) { + cache_valid = false; + } else { + texture.instantiate(); + texture->create_from_image(img); + + if (has_small_texture) { + if (small_img->load(cache_base + "_small.png") != OK) { + cache_valid = false; + } else { + small_texture.instantiate(); + small_texture->create_from_image(small_img); } } } + } - if (!cache_valid) { - _generate_preview(texture, small_texture, item, cache_base); - } + if (!cache_valid) { + _generate_preview(texture, small_texture, item, cache_base); } - _preview_ready(item.path, texture, small_texture, item.id, item.function, item.userdata); } + _preview_ready(item.path, texture, small_texture, item.id, item.function, item.userdata); } - - } else { - preview_mutex.unlock(); } + + } else { + preview_mutex.unlock(); + } +} + +void EditorResourcePreview::_thread() { + exited.clear(); + while (!exit.is_set()) { + preview_sem.wait(); + _iterate(); } exited.set(); } @@ -429,8 +433,12 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) { } void EditorResourcePreview::start() { - ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started."); - thread.start(_thread_func, this); + if (OS::get_singleton()->get_render_main_thread_mode() == OS::RENDER_ANY_THREAD) { + ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started."); + thread.start(_thread_func, this); + } else { + _mainthread_only = true; + } } void EditorResourcePreview::stop() { @@ -453,3 +461,18 @@ EditorResourcePreview::EditorResourcePreview() { EditorResourcePreview::~EditorResourcePreview() { stop(); } + +void EditorResourcePreview::update() { + if (!_mainthread_only) { + return; + } + + if (!exit.is_set()) { + // no need to even lock the mutex if the size is zero + // there is no problem if queue.size() is wrong, even if + // there was a race condition. + if (queue.size()) { + _iterate(); + } + } +} diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index ea16c8fde0..9d1f269661 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -81,6 +81,11 @@ class EditorResourcePreview : public Node { SafeFlag exit; SafeFlag exited; + // when running from GLES, we want to run the previews + // in the main thread using an update, rather than create + // a separate thread + bool _mainthread_only = false; + struct Item { Ref<Texture2D> preview; Ref<Texture2D> small_preview; @@ -98,6 +103,7 @@ class EditorResourcePreview : public Node { static void _thread_func(void *ud); void _thread(); + void _iterate(); Vector<Ref<EditorResourcePreviewGenerator>> preview_generators; @@ -119,6 +125,9 @@ public: void start(); void stop(); + // for single threaded mode + void update(); + EditorResourcePreview(); ~EditorResourcePreview(); }; diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 84992892a4..b99ccc1012 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -4376,7 +4376,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito const int wireframe_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME); const int overdraw_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW); const int shadeless_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS); - const String unsupported_tooltip = TTR("Not available when using the GLES2 renderer."); + const String unsupported_tooltip = TTR("Not available when using the OpenGL renderer."); view_menu->get_popup()->set_item_disabled(normal_idx, true); view_menu->get_popup()->set_item_tooltip(normal_idx, unsupported_tooltip); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 6d023b8a7d..9189c75162 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -1246,7 +1246,7 @@ void VisualShaderEditor::_update_options_menu() { Color unsupported_color = get_theme_color(SNAME("error_color"), SNAME("Editor")); Color supported_color = get_theme_color(SNAME("warning_color"), SNAME("Editor")); - static bool low_driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name") == "GLES2"; + static bool low_driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name") == "opengl3"; Map<String, TreeItem *> folders; diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index e8fd3070c2..dc35e01a56 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -475,6 +475,13 @@ private: } ProjectSettings::CustomMap initial_settings; initial_settings["rendering/vulkan/rendering/back_end"] = rasterizer_button_group->get_pressed_button()->get_meta(SNAME("driver_name")); + if (rasterizer_button_group->get_pressed_button()->get_meta("driver_name") == "Vulkan") { + initial_settings["rendering/driver/driver_name"] = "Vulkan"; + } else { + initial_settings["rendering/driver/driver_name"] = "OpenGL3"; + initial_settings["rendering/textures/vram_compression/import_etc2"] = false; + initial_settings["rendering/textures/vram_compression/import_etc"] = true; + } initial_settings["application/config/name"] = project_name->get_text().strip_edges(); initial_settings["application/config/icon"] = "res://icon.png"; initial_settings["rendering/environment/defaults/default_environment"] = "res://default_env.tres"; |