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

Fix Shader and ShaderInclude resource loading #80705

Merged
merged 1 commit into from
Aug 28, 2023
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
13 changes: 8 additions & 5 deletions scene/resources/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,16 @@ Ref<Resource> ResourceFormatLoaderShader::load(const String &p_path, const Strin
*r_error = ERR_FILE_CANT_OPEN;
}

Ref<Shader> shader;
shader.instantiate();

Vector<uint8_t> buffer = FileAccess::get_file_as_bytes(p_path);
Error error = OK;
Vector<uint8_t> buffer = FileAccess::get_file_as_bytes(p_path, &error);
ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot load shader: " + p_path);

String str;
str.parse_utf8((const char *)buffer.ptr(), buffer.size());
error = str.parse_utf8((const char *)buffer.ptr(), buffer.size());
ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot parse shader: " + p_path);

Ref<Shader> shader;
shader.instantiate();

shader->set_include_path(p_path);
shader->set_code(str);
Expand Down
13 changes: 8 additions & 5 deletions scene/resources/shader_include.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ Ref<Resource> ResourceFormatLoaderShaderInclude::load(const String &p_path, cons
*r_error = ERR_FILE_CANT_OPEN;
}

Ref<ShaderInclude> shader_inc;
shader_inc.instantiate();

Vector<uint8_t> buffer = FileAccess::get_file_as_bytes(p_path);
Error error = OK;
Vector<uint8_t> buffer = FileAccess::get_file_as_bytes(p_path, &error);
ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot load shader include: " + p_path);

String str;
str.parse_utf8((const char *)buffer.ptr(), buffer.size());
error = str.parse_utf8((const char *)buffer.ptr(), buffer.size());
ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot parse shader include: " + p_path);

Ref<ShaderInclude> shader_inc;
shader_inc.instantiate();

shader_inc->set_include_path(p_path);
shader_inc->set_code(str);
Expand Down