CanvasIO.load

Prepare an image for drawing. For hardware accelerated backends, this may involve uploading the texture to the GPU.

An image may be passed to this function even if it was already loaded. The field image.data.ptr can be used to uniquely identify an image, so the canvas can use it to reuse previously prepared images. Additionally, the image.revisionNumber field will increase if the image was updated, so the change should be reflected in the canvas.

There is no corresponding unload call. The canvas can instead unload images based on whether they were loaded during a resize. This may look similar to this:

int resizeNumber;
void load(Image image) {
    // ... load the resource ...
    resource.lastResize = resizeNumber;
}
void resizeImpl(Vector2 space) {
    auto frame = this.implementIO();
    resizeNumber++;
    super.resizeImpl();
    foreach_reverse (ref resource; resources) {
        if (resource.lastResize < resizeNumber) {
            unload(resource);
            resource.isInvalid = true;
        }
    }
    return size;
}

Important: To make partial resizing possible, load can also be called outside of resizeImpl.

Unloading resources may change resource indices, but load calls must then set the new indices.

interface CanvasIO
nothrow
int
load

Parameters

image Image

Image to prepare. The image may be uninitialized, in which case the image should still be valid, but simply empty. Attention should be paid to the revisionNumber field.

Return Value

Type: int

A number to be associated with the image. Interpretation of this number is up to the backend, but usually it will be an index in an array, since it is faster to look up than an associative array.

Meta