Asset
Base class for all assets in the Asset Pipeline. Inherits RefCounted for automatic lifetime management via Ref<T>. Two-phase loading: Load() for CPU data (any thread), CreateGPU() for GPU resources (main thread).
- Module
- AssetSystem
- Header
#include "AssetSystem/Asset.h"- Namespace
Mowo
Constructors
Public functions
| Returns | Name | Description |
|---|---|---|
AssetType | GetAssetType | Type identification |
bool | Load | Load CPU-side data. |
std::string | PrimaryLoadFile | The one file whose bytes Load(path) reads first and whole, for a loader that reads them through the IO queue and hands them to LoadFromMemory. |
bool | LoadFromMemory | Load(path) with file's bytes already read. |
void | Unload | Release CPU-side data. |
bool | CreateGPU | Create GPU resources on the main thread. |
bool | CreateGPUBudgeted | Time-sliced GPU creation for the async-import drain. |
uint64_t | EstimatedMemoryUsage | Estimated CPU+GPU footprint for the eviction policy. |
uint64_t | EstimatedUploadBytes | Bytes the remaining GPU creation will still upload, read BEFORE CreateGPU so the per-frame drain can meter in bytes. |
void | DestroyGPU | Destroy GPU resources. |
bool | DestroyGPUIsFrameSafe | True when DestroyGPU only drops RHI objects whose backends already hold their release until the frames in flight have retired (images do, on every backend). |
bool | CanAdoptLoadedState | Off-thread reimport. |
void | AdoptLoadedState | |
bool | SaveMetadata | Save import settings to a .mdfmeta MDF file |
bool | LoadMetadata | Load import settings from a .mdfmeta MDF file |
void | WriteImportSettings | Override in derived classes to write type-specific import settings |
void | ReadImportSettings | Override in derived classes to read type-specific import settings |
void | CollectDependencyIDs | Override to report the UUIDs of assets this asset references (e.g. |
void | CollectDependencyPaths | |
UUID | GetID | |
void | SetID | |
const std::string& | GetSourcePath | |
void | SetSourcePath | |
uint64_t | GetSourceHash | Source content hash (FNV-1a 64) + mtime, persisted in the .mdfmeta so a project re-open restores them without re-reading every source file — change detection works immediately and there's no reimport storm. |
void | SetSourceHash | |
int64_t | GetSourceMtime | |
void | SetSourceMtime | |
AssetFlag | GetFlags | |
void | SetFlag | |
void | ClearFlag | |
bool | HasFlag | |
bool | IsLoaded | |
bool | IsGPUReady | |
bool | IsValid |
Function details
Asset
Asset()Asset
explicit Asset(UUID id)~Asset
virtual ~Asset()GetAssetType
virtual AssetType GetAssetType() const = 0Type identification
Load
virtual bool Load(const std::string& path) = 0Load CPU-side data. Can be called from any thread. Returns true on success.
PrimaryLoadFile
virtual std::string PrimaryLoadFile(const std::string& path) constThe one file whose bytes Load(path) reads first and whole, for a loader that reads them through the IO queue and hands them to LoadFromMemory. Empty (the default): Load does its own IO, and the loader only gives it a slot on the completion pool.
LoadFromMemory
virtual bool LoadFromMemory(const std::string& path, const std::string& file, std::vector<uint8_t>&& bytes)Load(path) with file's bytes already read. Any thread, like Load.
Unload
virtual void Unload() = 0Release CPU-side data.
CreateGPU
virtual bool CreateGPU(const GPUContext& ctx)Create GPU resources on the main thread. Returns true on success.
CreateGPUBudgeted
virtual bool CreateGPUBudgeted(const GPUContext& ctx, int budget)Time-sliced GPU creation for the async-import drain. MAIN THREAD ONLY. Does up to budget GPU work units (<= 0 = unbounded / one-shot). Returns true once the asset reached a TERMINAL state — GPUReady on success or Invalid on failure — and false while more budgeted work remains for a following frame. The default is one-shot (a single CreateGPU); large assets (meshes) override it to yield across frames.
EstimatedMemoryUsage
virtual uint64_t EstimatedMemoryUsage() constEstimated CPU+GPU footprint for the eviction policy. 0 = negligible / unknown (never triggers eviction by itself).
EstimatedUploadBytes
virtual uint64_t EstimatedUploadBytes() constBytes the remaining GPU creation will still upload, read BEFORE CreateGPU so the per-frame drain can meter in bytes. The default is the footprint estimate, which a texture knows from its CPU data alone; a type whose estimate needs its GPU objects (a mesh) overrides it.
DestroyGPU
virtual void DestroyGPU()Destroy GPU resources. Must be called on main thread.
DestroyGPUIsFrameSafe
virtual bool DestroyGPUIsFrameSafe() constTrue when DestroyGPU only drops RHI objects whose backends already hold their release until the frames in flight have retired (images do, on every backend). A reimport of such an asset needs the render thread fenced, not the whole device drained — the drain was a multi-second freeze in a Debug editor each time an artist saved a texture.
CanAdoptLoadedState
virtual bool CanAdoptLoadedState() constOff-thread reimport. The object a scene holds has to survive a reimport, so the loader cannot simply hand back a new one: it parses into a fresh object of the same type and the main thread moves that CPU state into the live one, after Unload and before CreateGPU. A type that cannot say which of its members Load fills keeps the synchronous reimport.
AdoptLoadedState
virtual void AdoptLoadedState(Asset& loaded)SaveMetadata
bool SaveMetadata(const std::string& mdfmetaPath) constSave import settings to a .mdfmeta MDF file
LoadMetadata
bool LoadMetadata(const std::string& mdfmetaPath)Load import settings from a .mdfmeta MDF file
WriteImportSettings
virtual void WriteImportSettings(MdfNode& importNode) constOverride in derived classes to write type-specific import settings
ReadImportSettings
virtual void ReadImportSettings(const MdfNode& importNode)Override in derived classes to read type-specific import settings
CollectDependencyIDs
virtual void CollectDependencyIDs(std::vector<UUID>& out) constOverride to report the UUIDs of assets this asset references (e.g. a material → its textures + parent). The registry stores these so it can answer "what does X need" and the reverse "who needs X" for delete-safety and a reference viewer. Default: no dependencies.
CollectDependencyPaths
virtual void CollectDependencyPaths(std::vector<std::string>& out) constGetID
UUID GetID() constSetID
void SetID(UUID id)GetSourcePath
const std::string& GetSourcePath() constSetSourcePath
void SetSourcePath(const std::string& path)GetSourceHash
uint64_t GetSourceHash() constSource content hash (FNV-1a 64) + mtime, persisted in the .mdfmeta so a project re-open restores them without re-reading every source file — change detection works immediately and there's no reimport storm.
SetSourceHash
void SetSourceHash(uint64_t h)GetSourceMtime
int64_t GetSourceMtime() constSetSourceMtime
void SetSourceMtime(int64_t m)GetFlags
AssetFlag GetFlags() constSetFlag
void SetFlag(AssetFlag flag)ClearFlag
void ClearFlag(AssetFlag flag)HasFlag
bool HasFlag(AssetFlag flag) constIsLoaded
bool IsLoaded() constIsGPUReady
bool IsGPUReady() constIsValid
bool IsValid() const