Skip to content

Add vk::image for various image loading implementations #45

@SpinnerX

Description

@SpinnerX

Brief Overview

Considering in adding an interface called vk::image specifically for switching with specific image loader implementations.

Currently, vulkan-cpp uses stb image for loading images. In the near future, we may use ktx texture formats for loading images. It would be ideal to have ways of having an implementation-specific detail be hidden and automatically be specific in toggling between specific image loader implementations.

Enabling users to opt-in for specific frameworks for loading their images without fully opt-in to using the stb image framework.

Design

The way the interface is essentially used for is to load the image. Then act as a way to read the direct image data to the loaded image file passed to the implementation-specific image loading library.

class image {
public:
    virtual ~image() = default;

    void construct(vk::image_params) { return image_configure(...); }

    std::span<const uint8_t> read() { return image_read(); }

    image_extent size() { return image_size(); }

    bool load(std::filesystem::path&) { return load_image_file(p_filename); }

private:
    // Configure the image loader for loading the image
    // Can be used for enabling for invalidation (if requested).
    virtual void image_construct(vk::image_params) = 0;

    // Retrieve the bytes of the image that has been read.
    virtual std::span<const uint8_t> image_read() = 0;

    // Retrieving the dimension of the loaded image
    virtual image_extent image_size() = 0;

    // Returns true if loaded succesfully or not
    // Specify path for loading in image file
    virtual bool load_image_file(const std::filesystem::path&) = 0;
};

What does task completion look like?

If we had the texture that required an image to be loaded and we wanted to specify our own image loading library, this is how I can see vk::image_loader be utilized:

// stb image specific implementation at construction takes in an image.
vk::stb_image image(std::filesystem::path("images/test.png"));

// Texture uses the loaded image and pass to the texture to use that specific implementation
vk::texture texture_image(logical_device, &image, ...);

Metadata

Metadata

Assignees

Labels

💠coreCritical tasks are reserved for maintainers during fundamental architectural changes.📐designTasks that involve the core systems. Highly involve in API design.
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions