Texture2D
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.
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.
Texture2D::Texture2D(std::shared_ptr<Image> image);| Parameter | Description |
|---|---|
| image | Decoded image containing pixel data and dimensions. |
Factories preferred
Creates a shared instance of Texture2D.
static std::shared_ptr<Texture2D> Texture2D::Create(std::shared_ptr<Image> image);| Parameter | Description |
|---|---|
| image | Decoded image containing pixel data and dimensions. |
Properties
The source image backing this texture.
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.
Transform2 transform {};Functions
GetType() Texture::Type virtual
Identifies this texture as Texture::Type::Texture2D.
Type vglx::Texture2D::GetType() const override;