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 created using TextureLoader rather than instantiated directly.

cpp
auto MyScene::OnAttached(SharedContextPointer context) -> void {
  texture_handle_ = context->texture_loader->LoadAsync("assets/diffuse.png");
}

auto MyScene::OnUpdate(float _) -> void {
  if (auto texture = texture_handle_.TryTake()) {
    material_->texture_map = texture.value();
  }
}

To learn more about how textures are imported and loaded see the Importing Assets Guide.

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};

Functions

GetTransform() Matrix3

Returns the UV transformation matrix.

The transform can be modified through translation, scaling, or rotation using the provided helper methods. This affects how the texture is sampled during rendering.

cpp
Matrix3 Texture2D::GetTransform();

GetType() Texture::Type virtual

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

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

OffsetX() auto

Applies a translation offset along the X-axis.

cpp
auto Texture2D::OffsetX(float value);
ParameterDescription
valueOffset value in pixels.

OffsetY() auto

Applies a translation offset along the Y-axis.

cpp
auto Texture2D::OffsetY(float value);
ParameterDescription
valueOffset value in pixels.

Rotate() auto

Applies a rotation to the texture coordinates.

cpp
auto Texture2D::Rotate(float angle);
ParameterDescription
angleRotation angle in radians.

Scale() auto

Applies a uniform scale to the texture coordinates.

cpp
auto Texture2D::Scale(float value);
ParameterDescription
valueScale factor.

Released under the MIT License.