Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Allow reading shaders from .gdshader files #49983

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ ProjectSettings::ProjectSettings() {
if (Engine::get_singleton()->has_singleton("GodotSharp")) {
extensions.push_back("cs");
}
extensions.push_back("gdshader");
extensions.push_back("shader");

GLOBAL_DEF("editor/main_run_args", "");
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@
<member name="editor/script_templates_search_path" type="String" setter="" getter="" default="&quot;res://script_templates&quot;">
Search path for project-specific script templates. Godot will search for script templates both in the editor-specific path and in this project-specific path.
</member>
<member name="editor/search_in_file_extensions" type="PoolStringArray" setter="" getter="" default="PoolStringArray( &quot;gd&quot;, &quot;shader&quot; )">
<member name="editor/search_in_file_extensions" type="PoolStringArray" setter="" getter="" default="PoolStringArray( &quot;gd&quot;, &quot;gdshader&quot;, &quot;shader&quot; )">
Text-based file extensions to include in the script editor's "Find in Files" feature. You can add e.g. [code]tscn[/code] if you wish to also parse your scene files, especially if you use built-in scripts which are serialized in the scene files.
</member>
<member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0">
Expand Down
1 change: 1 addition & 0 deletions editor/editor_asset_installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) {
extension_guess["glb"] = tree->get_icon("PackedScene", "EditorIcons");

extension_guess["gdshader"] = tree->get_icon("Shader", "EditorIcons");
extension_guess["shader"] = tree->get_icon("Shader", "EditorIcons");
extension_guess["gd"] = tree->get_icon("GDScript", "EditorIcons");
if (Engine::get_singleton()->has_singleton("GodotSharp")) {
extension_guess["cs"] = tree->get_icon("CSharpScript", "EditorIcons");
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2975,7 +2975,7 @@ void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_numb
if (ResourceLoader::exists(fpath)) {
RES res = ResourceLoader::load(fpath);

if (fpath.get_extension() == "shader") {
if (fpath.get_extension() == "gdshader" || fpath.get_extension() == "shader") {
ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader"));
shader_editor->edit(res.ptr());
shader_editor->make_visible(true);
Expand Down
6 changes: 6 additions & 0 deletions misc/dist/linux/org.godotengine.Godot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<glob pattern="*.escn"/>
</mime-type>

<mime-type type="application/x-godot-shader">
<comment>Godot Engine shader</comment>
<icon name="x-godot-shader" />
<glob pattern="*.gdshader"/>
</mime-type>

<mime-type type="application/x-gdscript">
<comment>GDScript script</comment>
<icon name="x-gdscript" />
Expand Down
5 changes: 4 additions & 1 deletion scene/resources/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_origi
}

void ResourceFormatLoaderShader::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("gdshader");
p_extensions->push_back("shader");
}

Expand All @@ -213,7 +214,7 @@ bool ResourceFormatLoaderShader::handles_type(const String &p_type) const {

String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "shader") {
if (el == "gdshader" || el == "shader") {
return "Shader";
}
return "";
Expand Down Expand Up @@ -244,10 +245,12 @@ Error ResourceFormatSaverShader::save(const String &p_path, const RES &p_resourc
void ResourceFormatSaverShader::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (const Shader *shader = Object::cast_to<Shader>(*p_resource)) {
if (shader->is_text_shader()) {
p_extensions->push_back("gdshader");
p_extensions->push_back("shader");
}
}
}

bool ResourceFormatSaverShader::recognize(const RES &p_resource) const {
return p_resource->get_class_name() == "Shader"; //only shader, not inherited
}