DynamicTexture2D
A dynamic 2D texture is intended for textures that are created at runtime and updated incrementally (for example, render targets, streaming tiles, lookup tables, or per-frame CPU uploads). Unlike Texture2D, it does not own persistent CPU-side image data. Instead, it exposes methods to update regions of the texture after creation.
auto MyNode::OnAttached(SharedContextPointer context) -> void {
dynamic_texture_ = vglx::DynamicTexture2D::Create({
.width = 1024,
.height = 1024,
.mips = 1,
.format = vglx::DynamicTexture2D::Format::RGBA8,
.color_space = vglx::ColorSpace::Linear
});
auto patch_bytes = get_image_subregion();
dynamic_texture_->UpdateSubregion(
0, // mip-level
0, // x
0, // y
64, // w
64, // h
patch_byes
);
}INFO
Derives from Texture and inherits all public properties and methods.
Construction
Constructors
DynamicTexture2D()
Constructs a dynamic 2D texture.
Allocates GPU storage for the requested dimensions, mip count, and format. Data can be uploaded later through UpdateSubregion.
DynamicTexture2D::DynamicTexture2D(const Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the texture. |
Factories preferred
DynamicTexture2D::Create() std::shared_ptr<DynamicTexture2D>
Creates a shared instance of DynamicTexture2D.
static std::shared_ptr<DynamicTexture2D> DynamicTexture2D::Create(const Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the texture. |
Types
DynamicTexture2D::Parameters struct
Parameters for constructing a DynamicTexture2D object.
| Parameter | Description |
|---|---|
| width int | Width in pixels. |
| height int | Height in pixels. |
| mips unsigned int | Number of mip levels to allocate. |
| format Format | Texture storage format. |
| color_space ColorSpace | Color space for sampling. |
Properties
height const int
Texture height in pixels.
const int height {};mips const unsigned int
Number of allocated mip levels.
const unsigned int mips {};width const int
Texture width in pixels.
const int width {};Functions
GetType() Texture::Type virtual
Identifies this texture as Texture::Type::DynamicTexture2D.
Type vglx::DynamicTexture2D::GetType() const override;UpdateSubregion() void
Updates a rectangular subregion of the texture.
Queues an upload for a region of the given mip level. This is typically used for incremental CPU updates such as streaming tiles or procedural generation. The byte layout of data must match the texture format and the size of the updated region.
void DynamicTexture2D::UpdateSubregion(unsigned int mip_level, int x, int y, int w, int h, std::span<const std::uint8_t> data);| Parameter | Description |
|---|---|
| mip_level | Mip level to update. |
| x | X offset in pixels. |
| y | Y offset in pixels. |
| w | Width of the updated region in pixels. |
| h | Height of the updated region in pixels. |
| data | Raw pixel bytes for the updated region. |