DVUI

update

Update a texture that was created with textureCreate.

If the backend does not support updating textures, it will be destroyed and recreated, changing the pointer inside tex.

Only valid between Window.begin and Window.end.

Parameters

#
tex:*Texture
*Texture
pma:[]const Color.PMA
[]const Color.PMA

Source

Implementation

#
pub fn update(tex: *Texture, pma: []const Color.PMA) !void {
    if (pma.len != tex.width * tex.height) @panic("Texture size and supplied Content did not match");
    dvui.currentWindow().backend.textureUpdate(tex.*, @ptrCast(pma.ptr)) catch |err| {
        // texture update not supported by backend, destroy and create texture
        if (err == TextureError.NotImplemented) {
            const new_tex = try create(pma, .{ .width = tex.width, .height = tex.height, .interpolation = tex.interpolation, .format = tex.format, .wrap_u = tex.wrap_u, .wrap_v = tex.wrap_v });
            destroyLater(tex.*);
            tex.* = new_tex;
        } else {
            return err;
        }
    };
}