Skip to content

TextureLoader

Loads 2D textures from engine-optimized files.

TextureLoader is a concrete Loader implementation that reads the engine's custom .tex format from disk and constructs Texture2D resources. It exposes both synchronous and asynchronous loading through the base class API.

You can convert standard image formats (for example PNG or JPG) into .tex files using the asset_builder tool located in the engine's tools directory. The .tex format stores texture data and metadata in a layout optimized for fast loading at runtime. See Importing Assets to learn more.

Explicit instantiation of this class is discouraged due to lifetime concerns in the current architecture, particularly when used with asynchronous loading. Instead, obtain a reference to the loader through Node::OnAttached, which provides access to the owning context and its loader instances.

cpp
auto MyNode::OnAttached(SharedContextPointer context) -> void override {
  context->texture_loader->LoadAsync(
    "assets/my_texture.tex",
    [this](auto result) {
      if (result) {
        texture_ = result.value();
      } else {
        std::println(stderr, "{}", result.error());
      }
    }
  );
}

INFO

Derives from Loader and inherits all public properties and methods.

Construction

Factories preferred


TextureLoader::Create() std::shared_ptr<TextureLoader>

Creates a shared instance of TextureLoader.

The constructor is private to ensure the loader is always owned by a std::shared_ptr. This is required because the base Loader class inherits from std::enable_shared_from_this, which relies on the loader being managed by a shared pointer for safe use during asynchronous loading.

cpp
static std::shared_ptr<TextureLoader> TextureLoader::Create();

Types

TextureCallback typedef

Callback type for receiving loaded textures.

cpp
using TextureCallback =  std::function<void(std::shared_ptr<Texture2D>)>

Released under the MIT License.