Skip to content

Texture2D

Represents a 2D texture that can be attached to materials.

While you can instantiate a Texture2D object directly, it is recommended to use the texture loader object to create texture 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 Texture and inherits all public properties and methods.

Construction

Constructors


Texture2D()

cpp
vglx::Texture2D::Texture2D(const Parameters &params)
ParameterDescription
paramsTexture2D::Parameters

Constructs a Texture2D object.

Factories preferred


Texture2D::Create() auto

cpp
static auto vglx::Texture2D::Create(const Parameters &params)
ParameterDescription
paramsTexture2D::Parameters

Creates a shared pointer to a Texture2D object.

Types

Texture2D::Parameters struct

Parameters for constructing a texture2D object.

NameTypeDescription
datastd::vector< uint8_t >Underlying texture data.
heightunsignedHeight in pixels.
widthunsignedWidth in pixels.

Properties

data std::vector< uint8_t >

cpp
std::vector< uint8_t > data

Underlying texture data.

height unsigned

cpp
unsigned height

Height in pixels.

width unsigned

cpp
unsigned width

Width in pixels.

Functions

GetTransform() auto

cpp
auto vglx::Texture2D::GetTransform()

Returns the transformation matrix for UV mapping.

GetType() TextureType virtual

cpp
TextureType vglx::Texture2D::GetType() const override

Returns texture type.

OffsetX() auto

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

Sets texture offset on the X-axis.

OffsetY() auto

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

Sets texture offset on the Y-axis.

Rotate() auto

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

Sets rotation angle.

Scale() auto

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

Sets uniform scale.

Released under the MIT License.