Class ResourceLoader

Inheritance Relationships

Derived Types

Class Documentation

class ResourceLoader

Abstract base class for all resource loaders.

ResourceLoader defines the interface for loading typed resources from source data. Each loader is specialized for a specific ResourceType (Texture, Mesh, Material, etc.) and knows how to decode the relevant file formats.

Loader Responsibilities:

  • Read bytes from the provided ResourceSource (file, memory, etc.)

  • Decode the source format (PNG, GLTF, OBJ, etc.) into engine data structures

  • Create GPU resources (textures, buffers) via the RendererContext

  • Handle dependencies by loading required sub-resources through the registry

  • Return a Reference<Resource> that can be cast to the concrete type

Threading Model: Loaders run on job system worker threads. The load() method blocks the worker thread during loading, but since it’s on the job system, other workers continue processing. Loaders should avoid long-running operations that can’t be parallelized.

Dependency Handling: If a resource depends on other resources (e.g., materials depend on textures), loaders can request them from the registry:

// Inside MaterialLoader::load()
auto albedo_ref = registry.load<TextureResource>(meta.albedo_texture_id);
if (albedo_ref.is_valid()) {
    material->set_albedo_texture(albedo_ref.get());
}

See also

LoaderFactory::get() for how loaders are selected by ResourceType

See also

ResourceRegistry::load_direct() for how loaders are invoked

See also

ResourceSource for the data reading abstraction

Subclassed by portal::resources::FontLoader, portal::resources::GltfLoader, portal::resources::MaterialLoader, portal::resources::MeshLoader, portal::resources::SceneLoader, portal::resources::ShaderLoader, portal::resources::StubLoader, portal::resources::TextureLoader

Public Functions

inline explicit ResourceLoader(ResourceRegistry &registry)

Constructor.

Parameters:

registry – Reference to the ResourceRegistry for loading dependencies

virtual ~ResourceLoader() = default
virtual Reference<Resource> load(const SourceMetadata &meta, const ResourceSource &source) = 0

Load a resource from source data.

This method blocks the calling thread (job system worker) until the resource is fully loaded and ready for use. It reads bytes from the source, decodes the format, creates GPU resources if needed, and returns a Reference to the loaded resource.

If the resource depends on other resources, the loader can request them from the registry. The registry will handle scheduling those loads appropriately.

Error Handling: If loading fails (corrupt data, unsupported format, out of memory, etc.), the loader should log the error and return nullptr. The registry will move the resource to ResourceState::Error.

Note

The returned resource is managed by Reference (std::shared_ptr)

Note

Implementations should be thread-safe for reading from the source

Parameters:
  • meta – Metadata about the resource (type, format, dependencies, etc.)

  • source – Abstraction for reading the source bytes (file, memory, etc.)

Returns:

Reference<Resource> if successful, nullptr on error

Protected Attributes

ResourceRegistry &registry

Reference to the registry for loading dependent resources.