refactor: reorganize Resources module into Core/Asset, Core/IO and Resources subdirectories
- Split core resource architecture into Core/Asset/ (IResource, ResourceManager, ResourceCache, etc.)
- Moved IO layer into Core/IO/ (IResourceLoader, ResourceFileSystem, etc.)
- Reorganized concrete resource types into Resources/{Texture,Mesh,Material,Shader,AudioClip}/
- Updated all include paths from relative to <XCEngine/...> format
- Fixed circular dependency in Material.h (removed unnecessary ResourceManager.h include)
- Fixed malformed include syntax in ResourceManager.h and AsyncLoader.h
- Fixed glad.h path issues in CMakeLists.txt
This commit is contained in:
85
engine/src/Resources/Shader/ShaderLoader.cpp
Normal file
85
engine/src/Resources/Shader/ShaderLoader.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "Resources/ShaderLoader.h"
|
||||
#include "Resources/ResourceManager.h"
|
||||
#include "Resources/ResourceTypes.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Resources {
|
||||
|
||||
ShaderLoader::ShaderLoader() = default;
|
||||
|
||||
ShaderLoader::~ShaderLoader() = default;
|
||||
|
||||
Containers::Array<Containers::String> ShaderLoader::GetSupportedExtensions() const {
|
||||
Containers::Array<Containers::String> extensions;
|
||||
extensions.PushBack("vert");
|
||||
extensions.PushBack("frag");
|
||||
extensions.PushBack("geom");
|
||||
extensions.PushBack("comp");
|
||||
extensions.PushBack("glsl");
|
||||
extensions.PushBack("hlsl");
|
||||
extensions.PushBack("shader");
|
||||
return extensions;
|
||||
}
|
||||
|
||||
bool ShaderLoader::CanLoad(const Containers::String& path) const {
|
||||
Containers::String ext = GetExtension(path);
|
||||
return ext == "vert" || ext == "frag" || ext == "geom" ||
|
||||
ext == "comp" || ext == "glsl" || ext == "hlsl" || ext == "shader";
|
||||
}
|
||||
|
||||
LoadResult ShaderLoader::Load(const Containers::String& path, const ImportSettings* settings) {
|
||||
Containers::Array<Core::uint8> data = ReadFileData(path);
|
||||
if (data.Empty()) {
|
||||
return LoadResult("Failed to read shader file: " + path);
|
||||
}
|
||||
|
||||
Containers::String source;
|
||||
source.Reserve(data.Size());
|
||||
for (size_t i = 0; i < data.Size(); ++i) {
|
||||
source += static_cast<char>(data[i]);
|
||||
}
|
||||
|
||||
Shader* shader = new Shader();
|
||||
shader->m_path = path;
|
||||
shader->m_name = path;
|
||||
shader->m_guid = ResourceGUID::Generate(path);
|
||||
|
||||
Containers::String ext = GetExtension(path);
|
||||
if (ext == "hlsl") {
|
||||
shader->SetShaderLanguage(ShaderLanguage::HLSL);
|
||||
} else {
|
||||
shader->SetShaderLanguage(ShaderLanguage::GLSL);
|
||||
}
|
||||
|
||||
ShaderType shaderType = DetectShaderType(path, source);
|
||||
shader->SetShaderType(shaderType);
|
||||
shader->SetSourceCode(source);
|
||||
|
||||
shader->m_isValid = true;
|
||||
shader->m_memorySize = sizeof(Shader) + shader->m_name.Length() +
|
||||
shader->m_path.Length() + source.Length();
|
||||
|
||||
return LoadResult(shader);
|
||||
}
|
||||
|
||||
ImportSettings* ShaderLoader::GetDefaultSettings() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ShaderType ShaderLoader::DetectShaderType(const Containers::String& path, const Containers::String& source) {
|
||||
Containers::String ext = GetExtension(path);
|
||||
|
||||
if (ext == "vert") return ShaderType::Vertex;
|
||||
if (ext == "frag") return ShaderType::Fragment;
|
||||
if (ext == "geom") return ShaderType::Geometry;
|
||||
if (ext == "comp") return ShaderType::Compute;
|
||||
|
||||
return ShaderType::Fragment;
|
||||
}
|
||||
|
||||
bool ShaderLoader::ParseShaderSource(const Containers::String& source, Shader* shader) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Resources
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user