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 through the engine’s texture loader rather than instantiated directly.

cpp
auto MyNode::OnAttached(SharedContextPointer context) -> void {
  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 Texture and inherits all public properties and methods.

Construction

Constructors


Texture2D()

Constructs a 2D texture.

cpp
Texture2D::Texture2D(const Parameters& params);
ParameterDescription
paramsInitialization parameters for constructing the texture.

Factories preferred


Texture2D::Create() auto

Creates a shared instance of Texture2D.

cpp
static auto Texture2D::Create(const Parameters& params);
ParameterDescription
paramsInitialization parameters for constructing the texture.

Types

Texture2D::Parameters struct

Parameters for constructing a Texture2D object.

ParameterDescription
width unsignedWidth in pixels.
height unsignedHeight in pixels.
data std::vector<uint8_t>Raw texture pixel data.

Properties

data std::vector<uint8_t>

Raw texture pixel data.

cpp
std::vector<uint8_t> data {};

height unsigned

Texture height in pixels.

cpp
unsigned height {};

width unsigned

Texture width in pixels.

cpp
unsigned width {};

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

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.