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:
2026-03-24 14:46:17 +08:00
parent b1829bcfc5
commit 50c0ffdb9e
47 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,174 @@
#include "Resources/Material.h"
#include "Resources/Shader.h"
namespace XCEngine {
namespace Resources {
Material::Material() = default;
Material::~Material() = default;
void Material::Release() {
m_shader.Reset();
m_properties.Clear();
m_textureBindings.Clear();
m_constantBufferData.Clear();
m_isValid = false;
}
void Material::SetShader(const ResourceHandle<Shader>& shader) {
m_shader = shader;
}
void Material::SetFloat(const Containers::String& name, float value) {
MaterialProperty prop;
prop.name = name;
prop.type = MaterialPropertyType::Float;
prop.value.floatValue[0] = value;
prop.refCount = 1;
m_properties.Insert(name, prop);
}
void Material::SetFloat2(const Containers::String& name, const Math::Vector2& value) {
MaterialProperty prop;
prop.name = name;
prop.type = MaterialPropertyType::Float2;
prop.value.floatValue[0] = value.x;
prop.value.floatValue[1] = value.y;
prop.refCount = 1;
m_properties.Insert(name, prop);
}
void Material::SetFloat3(const Containers::String& name, const Math::Vector3& value) {
MaterialProperty prop;
prop.name = name;
prop.type = MaterialPropertyType::Float3;
prop.value.floatValue[0] = value.x;
prop.value.floatValue[1] = value.y;
prop.value.floatValue[2] = value.z;
prop.refCount = 1;
m_properties.Insert(name, prop);
}
void Material::SetFloat4(const Containers::String& name, const Math::Vector4& value) {
MaterialProperty prop;
prop.name = name;
prop.type = MaterialPropertyType::Float4;
prop.value.floatValue[0] = value.x;
prop.value.floatValue[1] = value.y;
prop.value.floatValue[2] = value.z;
prop.value.floatValue[3] = value.w;
prop.refCount = 1;
m_properties.Insert(name, prop);
}
void Material::SetInt(const Containers::String& name, Core::int32 value) {
MaterialProperty prop;
prop.name = name;
prop.type = MaterialPropertyType::Int;
prop.value.intValue[0] = value;
prop.refCount = 1;
m_properties.Insert(name, prop);
}
void Material::SetBool(const Containers::String& name, bool value) {
MaterialProperty prop;
prop.name = name;
prop.type = MaterialPropertyType::Bool;
prop.value.boolValue = value;
prop.refCount = 1;
m_properties.Insert(name, prop);
}
void Material::SetTexture(const Containers::String& name, const ResourceHandle<Texture>& texture) {
MaterialProperty prop;
prop.name = name;
prop.type = MaterialPropertyType::Texture;
prop.refCount = 1;
m_properties.Insert(name, prop);
TextureBinding binding;
binding.name = name;
binding.slot = static_cast<Core::uint32>(m_textureBindings.Size());
binding.texture = texture;
m_textureBindings.PushBack(binding);
}
float Material::GetFloat(const Containers::String& name) const {
auto* prop = m_properties.Find(name);
if (prop && prop->type == MaterialPropertyType::Float) {
return prop->value.floatValue[0];
}
return 0.0f;
}
Math::Vector2 Material::GetFloat2(const Containers::String& name) const {
auto* prop = m_properties.Find(name);
if (prop && prop->type == MaterialPropertyType::Float2) {
return Math::Vector2(prop->value.floatValue[0], prop->value.floatValue[1]);
}
return Math::Vector2::Zero();
}
Math::Vector3 Material::GetFloat3(const Containers::String& name) const {
auto* prop = m_properties.Find(name);
if (prop && prop->type == MaterialPropertyType::Float3) {
return Math::Vector3(prop->value.floatValue[0], prop->value.floatValue[1], prop->value.floatValue[2]);
}
return Math::Vector3::Zero();
}
Math::Vector4 Material::GetFloat4(const Containers::String& name) const {
auto* prop = m_properties.Find(name);
if (prop && prop->type == MaterialPropertyType::Float4) {
return Math::Vector4(prop->value.floatValue[0], prop->value.floatValue[1],
prop->value.floatValue[2], prop->value.floatValue[3]);
}
return Math::Vector4::Zero();
}
Core::int32 Material::GetInt(const Containers::String& name) const {
auto* prop = m_properties.Find(name);
if (prop && prop->type == MaterialPropertyType::Int) {
return prop->value.intValue[0];
}
return 0;
}
bool Material::GetBool(const Containers::String& name) const {
auto* prop = m_properties.Find(name);
if (prop && prop->type == MaterialPropertyType::Bool) {
return prop->value.boolValue;
}
return false;
}
ResourceHandle<Texture> Material::GetTexture(const Containers::String& name) const {
for (const auto& binding : m_textureBindings) {
if (binding.name == name) {
return binding.texture;
}
}
return ResourceHandle<Texture>();
}
void Material::UpdateConstantBuffer() {
m_constantBufferData.Clear();
}
bool Material::HasProperty(const Containers::String& name) const {
return m_properties.Contains(name);
}
void Material::RemoveProperty(const Containers::String& name) {
m_properties.Erase(name);
}
void Material::ClearAllProperties() {
m_properties.Clear();
m_textureBindings.Clear();
m_constantBufferData.Clear();
}
} // namespace Resources
} // namespace XCEngine