Skip to content

DynamicTexture2D

Represents a two-dimensional texture with GPU-allocated storage.

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.

cpp
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.

cpp
DynamicTexture2D::DynamicTexture2D(const Parameters& params);
ParameterDescription
paramsInitialization parameters for constructing the texture.

Factories preferred


DynamicTexture2D::Create() std::shared_ptr<DynamicTexture2D>

Creates a shared instance of DynamicTexture2D.

cpp
static std::shared_ptr<DynamicTexture2D> DynamicTexture2D::Create(const Parameters& params);
ParameterDescription
paramsInitialization parameters for constructing the texture.

Types

DynamicTexture2D::Parameters struct

Parameters for constructing a DynamicTexture2D object.

ParameterDescription
width intWidth in pixels.
height intHeight in pixels.
mips unsigned intNumber of mip levels to allocate.
format FormatTexture storage format.
color_space ColorSpaceColor space for sampling.

Properties

height const int

Texture height in pixels.

cpp
const int height {};

mips const unsigned int

Number of allocated mip levels.

cpp
const unsigned int mips {};

width const int

Texture width in pixels.

cpp
const int width {};

Functions

GetType() Texture::Type virtual

Identifies this texture as Texture::Type::DynamicTexture2D.

cpp
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.

cpp
void DynamicTexture2D::UpdateSubregion(unsigned int mip_level, int x, int y, int w, int h, std::span<const std::uint8_t> data);
ParameterDescription
mip_levelMip level to update.
xX offset in pixels.
yY offset in pixels.
wWidth of the updated region in pixels.
hHeight of the updated region in pixels.
dataRaw pixel bytes for the updated region.

Released under the MIT License.