Skip to content

ImageLoader

Loader for image assets.

Provides both synchronous and asynchronous interfaces for loading common image formats (PNG, JPEG, TGA, BMP, HDR) from disk. It is intended to be accessed through the shared runtime context and used directly by application or node code.

The synchronous Load method performs the entire load on the calling thread and returns either a shared pointer to a fully constructed Image or an error message.

The asynchronous LoadAsync method schedules file I/O off the main thread and returns a ImageLoadHandle immediately. The handle can later be queried from the main thread to retrieve the loaded image once the operation completes.

Internally, asynchronous loading is coordinated through a LoadScheduler instance, which ensures that background work and main-thread commits are clearly separated.

cpp
auto handle = context->image_loader->LoadAsync("assets/texture.png");

auto OnUpdate(float) -> void override {
  if (auto image = handle.TryTake()) {
    // use image.value()
  }
}

Functions

Load() std::expected<std::shared_ptr<Image>, std::string >

Loads an image synchronously from a file.

Performs file I/O and image decoding on the calling thread. If loading succeeds a shared pointer to a fully constructed Image is returned. On failure an error message describing the problem is returned instead.

This method is intended for tooling, offline processing, or scenarios where blocking behavior is acceptable.

cpp
std::expected<std::shared_ptr< Image>, std::string > ImageLoader::Load(const fs::path& path) const;
ParameterDescription
pathFilesystem path to the image file.

LoadAsync() ImageLoadHandle

Loads an image asynchronously from a file.

Schedules file I/O work to run off the main thread and returns immediately with a ImageLoadHandle. The handle can later be polled to retrieve the loaded image once the operation completes. Errors can be retrieved explicitly from the handle or will be reported through the logger.

cpp
ImageLoadHandle ImageLoader::LoadAsync(const fs::path& path) const;
ParameterDescription
pathFilesystem path to the image file.

Released under the MIT License.