2023-06-02 19:24:21 +00:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <chrono>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <map>
|
2023-06-05 04:01:29 +00:00
|
|
|
#include <mutex>
|
2023-06-02 19:24:21 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "VideoCommon/Assets/CustomAssetLibrary.h"
|
2023-08-13 21:09:45 +00:00
|
|
|
#include "VideoCommon/Assets/CustomTextureData.h"
|
2023-06-02 19:24:21 +00:00
|
|
|
|
|
|
|
namespace VideoCommon
|
|
|
|
{
|
|
|
|
// This class implements 'CustomAssetLibrary' and loads any assets
|
|
|
|
// directly from the filesystem
|
|
|
|
class DirectFilesystemAssetLibrary final : public CustomAssetLibrary
|
|
|
|
{
|
|
|
|
public:
|
2023-06-05 04:01:29 +00:00
|
|
|
using AssetMap = std::map<std::string, std::filesystem::path>;
|
|
|
|
|
2023-09-06 05:16:26 +00:00
|
|
|
LoadInfo LoadTexture(const AssetID& asset_id, TextureData* data) override;
|
2023-06-29 05:56:06 +00:00
|
|
|
LoadInfo LoadPixelShader(const AssetID& asset_id, PixelShaderData* data) override;
|
2023-07-03 02:27:24 +00:00
|
|
|
LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override;
|
2024-02-13 00:42:01 +00:00
|
|
|
LoadInfo LoadMesh(const AssetID& asset_id, MeshData* data) override;
|
2023-06-02 19:24:21 +00:00
|
|
|
|
|
|
|
// Gets the latest time from amongst all the files in the asset map
|
|
|
|
TimeType GetLastAssetWriteTime(const AssetID& asset_id) const override;
|
|
|
|
|
|
|
|
// Assigns the asset id to a map of files, how this map is read is dependent on the data
|
|
|
|
// For instance, a raw texture would expect the map to have a single entry and load that
|
|
|
|
// file as the asset. But a model file data might have its data spread across multiple files
|
2023-06-05 04:01:29 +00:00
|
|
|
void SetAssetIDMapData(const AssetID& asset_id, AssetMap asset_path_map);
|
2023-06-02 19:24:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Loads additional mip levels into the texture structure until _mip<N> texture is not found
|
2023-08-13 21:09:45 +00:00
|
|
|
bool LoadMips(const std::filesystem::path& asset_path, CustomTextureData::ArraySlice* data);
|
2023-06-05 04:01:29 +00:00
|
|
|
|
|
|
|
// Gets the asset map given an asset id
|
|
|
|
AssetMap GetAssetMapForID(const AssetID& asset_id) const;
|
|
|
|
|
|
|
|
mutable std::mutex m_lock;
|
2023-06-02 19:24:21 +00:00
|
|
|
std::map<AssetID, std::map<std::string, std::filesystem::path>> m_assetid_to_asset_map_path;
|
|
|
|
};
|
|
|
|
} // namespace VideoCommon
|