Implement initial Unity-style asset library cache
This commit is contained in:
@@ -141,4 +141,47 @@ TEST(MaterialLoader, RejectsUnknownRenderStateEnum) {
|
||||
std::remove(materialPath.string().c_str());
|
||||
}
|
||||
|
||||
TEST(MaterialLoader, ResourceManagerLoadsRelativeMaterialFromResourceRoot) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
ResourceManager& manager = ResourceManager::Get();
|
||||
manager.Initialize();
|
||||
|
||||
const fs::path previousPath = fs::current_path();
|
||||
const fs::path projectRoot = fs::temp_directory_path() / "xc_material_loader_resource_root";
|
||||
const fs::path assetsDir = projectRoot / "Assets";
|
||||
const fs::path materialPath = assetsDir / "relative.material";
|
||||
|
||||
fs::remove_all(projectRoot);
|
||||
fs::create_directories(assetsDir);
|
||||
|
||||
{
|
||||
std::ofstream materialFile(materialPath);
|
||||
ASSERT_TRUE(materialFile.is_open());
|
||||
materialFile << "{\n";
|
||||
materialFile << " \"renderQueue\": \"geometry\",\n";
|
||||
materialFile << " \"renderState\": {\n";
|
||||
materialFile << " \"cull\": \"back\",\n";
|
||||
materialFile << " \"colorWriteMask\": 15\n";
|
||||
materialFile << " }\n";
|
||||
materialFile << "}";
|
||||
}
|
||||
|
||||
manager.SetResourceRoot(projectRoot.string().c_str());
|
||||
fs::current_path(projectRoot.parent_path());
|
||||
|
||||
{
|
||||
const auto materialHandle = manager.Load<Material>("Assets/relative.material");
|
||||
ASSERT_TRUE(materialHandle.IsValid());
|
||||
EXPECT_EQ(materialHandle->GetRenderQueue(), static_cast<XCEngine::Core::int32>(MaterialRenderQueue::Geometry));
|
||||
EXPECT_EQ(materialHandle->GetRenderState().cullMode, MaterialCullMode::Back);
|
||||
EXPECT_EQ(materialHandle->GetRenderState().colorWriteMask, 15);
|
||||
}
|
||||
|
||||
fs::current_path(previousPath);
|
||||
fs::remove_all(projectRoot);
|
||||
manager.SetResourceRoot("");
|
||||
manager.Shutdown();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user