Fix Shader and ShaderInclude resource loading

(cherry picked from commit 26e3443eef)
This commit is contained in:
bitsawer 2023-08-17 11:17:54 +03:00 committed by Yuri Sizov
parent c57d6c9371
commit a606b03fd7
2 changed files with 16 additions and 10 deletions

View File

@ -234,13 +234,16 @@ Ref<Resource> ResourceFormatLoaderShader::load(const String &p_path, const Strin
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }
Ref<Shader> shader; Error error = OK;
shader.instantiate(); Vector<uint8_t> buffer = FileAccess::get_file_as_bytes(p_path, &error);
ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot load shader: " + p_path);
Vector<uint8_t> buffer = FileAccess::get_file_as_bytes(p_path);
String str; 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_include_path(p_path);
shader->set_code(str); shader->set_code(str);

View File

@ -88,13 +88,16 @@ Ref<Resource> ResourceFormatLoaderShaderInclude::load(const String &p_path, cons
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }
Ref<ShaderInclude> shader_inc; Error error = OK;
shader_inc.instantiate(); 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);
Vector<uint8_t> buffer = FileAccess::get_file_as_bytes(p_path);
String str; 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_include_path(p_path);
shader_inc->set_code(str); shader_inc->set_code(str);