Texture2D
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.
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.
Texture2D::Texture2D(Parameters params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the texture. |
Factories preferred
Creates a shared instance of Texture2D.
static std::shared_ptr<Texture2D> Texture2D::Create(const Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the texture. |
Types
Texture2D::Parameters struct
Parameters for constructing a Texture2D object.
| Parameter | Description |
|---|---|
| width unsigned | Width in pixels. |
| height unsigned | Height in pixels. |
| color_space ColorSpace | Color space for texture data. |
| data std::vector<uint8_t> | Raw texture pixel data. |
Properties
data std::vector<uint8_t>
Raw texture pixel data.
std::vector<uint8_t> data {};height unsigned
Texture height in pixels.
unsigned height {};width unsigned
Texture width in pixels.
unsigned width {};Functions
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.
Matrix3 Texture2D::GetTransform();GetType() Texture::Type virtual
Identifies this texture as Texture::Type::Texture2D.
Type vglx::Texture2D::GetType() const override;OffsetX() auto
Applies a translation offset along the X-axis.
auto Texture2D::OffsetX(float value);| Parameter | Description |
|---|---|
| value | Offset value in pixels. |
OffsetY() auto
Applies a translation offset along the Y-axis.
auto Texture2D::OffsetY(float value);| Parameter | Description |
|---|---|
| value | Offset value in pixels. |
Rotate() auto
Applies a rotation to the texture coordinates.
auto Texture2D::Rotate(float angle);| Parameter | Description |
|---|---|
| angle | Rotation angle in radians. |
Scale() auto
Applies a uniform scale to the texture coordinates.
auto Texture2D::Scale(float value);| Parameter | Description |
|---|---|
| value | Scale factor. |