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 ¶ms)
Parameter | Description |
---|---|
params | Texture2D::Parameters |
Constructs a Texture2D object.
Factories preferred
Texture2D::Create() auto
cpp
static auto vglx::Texture2D::Create(const Parameters ¶ms)
Parameter | Description |
---|---|
params | Texture2D::Parameters |
Creates a shared pointer to a Texture2D object.
Types
Texture2D::Parameters struct
Parameters for constructing a texture2D object.
Name | Type | Description |
---|---|---|
data | std::vector< uint8_t > | Underlying texture data. |
height | unsigned | Height in pixels. |
width | unsigned | Width 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)
Parameter | Description |
---|---|
value | Offset value in pixels. |
Sets texture offset on the X-axis.
OffsetY() auto
cpp
auto vglx::Texture2D::OffsetY(float value)
Parameter | Description |
---|---|
value | Offset value in pixels. |
Sets texture offset on the Y-axis.
Rotate() auto
cpp
auto vglx::Texture2D::Rotate(float angle)
Parameter | Description |
---|---|
angle | Rotation angle in radians. |
Sets rotation angle.
Scale() auto
cpp
auto vglx::Texture2D::Scale(float value)
Parameter | Description |
---|---|
value | Scale value. |
Sets uniform scale.