Skip to content

Image ​

Represents decoded image data loaded from an asset.

An image holds raw pixel data along with its dimensions. Images are typically loaded using an image loader and shared between texture instances. Pixel data is stored as either 8-bit bytes for standard LDR images, or 32-bit floats for HDR images. To learn more see the Importing Assets Guide.

cpp
auto image = vglx::LoadImage("assets/heightmap.png");
if (image.has_value()) {
    // use image.value()
} else {
    std::println(stderr, "{}", image.error());
}

Loading images directly is useful when you need to share the same pixel data across textures or update texture contents at runtime (see DynamicTexture2D). For one-off texture creation, prefer LoadTexture, which loads an image and creates a texture in one step.

Construction ​

Constructors ​


Image() ​

Constructs an image from initialization parameters.

Prefer Image::Create over direct construction to obtain a stdshared_ptr<Image> that can be shared between textures.

cpp
Image::Image(Parameters params);
ParameterDescription
paramsInitialization parameters for constructing the image.

Factories preferred ​


Image::Create() std::shared_ptr<Image> ​

Creates a shared instance of Image.

cpp
static std::shared_ptr<Image> Image::Create(Parameters params);
ParameterDescription
paramsInitialization parameters for constructing the image.

Types ​

Image::Parameters struct ​

Parameters for constructing an Image object.

ParameterDescription
data PixelDataRaw pixel data.
width unsignedImage width in pixels.
height unsignedImage height in pixels.

PixelData typedef ​

Pixel data storage; LDR (8-bit) or HDR (32-bit float).

cpp
using vglx::Image::PixelData = std::variant<std::vector<uint8_t>, std::vector<float>>

Properties ​

Raw pixel data.

cpp
PixelData data {};

height unsigned ​

Image height in pixels.

cpp
unsigned height {};

width unsigned ​

Image width in pixels.

cpp
unsigned width {};

Released under the MIT License.