Skip to content

Texture2D

Represents a two-dimensional texture.

A 2D texture stores image data that can be sampled by materials during rendering. Textures are typically loaded using a texture loader rather than instantiated directly. To learn more see the Importing Assets Guide.

cpp
auto texture = vglx::LoadTexture("assets/crate.png");
if (texture.has_value()) {
    // use texture.value()
} else {
    std::println(stderr, "{}", texture.error());
}

INFO

Derives from Texture and inherits all public properties and methods.

Construction

Constructors


Texture2D()

Constructs a 2D texture from an Image.

The texture holds a shared reference to the image, allowing multiple textures to share the same underlying pixel data.

cpp
Texture2D::Texture2D(std::shared_ptr<Image> image);
ParameterDescription
imageDecoded image containing pixel data and dimensions.

Factories preferred


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

Creates a shared instance of Texture2D.

cpp
static std::shared_ptr<Texture2D> Texture2D::Create(std::shared_ptr<Image> image);
ParameterDescription
imageDecoded image containing pixel data and dimensions.

Properties

image std::shared_ptr<Image>

The source image backing this texture.

cpp
std::shared_ptr<Image> image {nullptr};

transform Transform2

UV transform applied to texture coordinates when sampling. Modify it directly through the Transform2 interface (for example Transform2::SetScale, Transform2::SetPosition, or Transform2::SetRotation) to translate, scale, or rotate the texture. The renderer reads the resulting matrix each frame.

cpp
Transform2 transform {};

Functions

GetType() Texture::Type virtual

Identifies this texture as Texture::Type::Texture2D.

cpp
Type vglx::Texture2D::GetType() const override;

Released under the MIT License.