texture.hpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#pragma once


#include <planet/affine/rectangle2d.hpp>
#include <planet/vk/image.hpp>
#include <planet/ui/scale.hpp>


namespace planet::vk {


    class device;

Sampler

16
17
18
19
20
    class sampler final {
        using handle_type = vk::device_handle<VkSampler, vkDestroySampler>;
        handle_type handle;

      public:

Construct

22
23
        sampler() {}
        sampler(vk::device &, std::uint32_t mip_levels);

Query sampler

28
29
30
        device_view device;
        auto get() const noexcept { return handle.get(); }
    };

Texture map

34
35
    class texture final {
      public:

Construction

37
38
39
40
41
42
43
44
45
46
47
        struct args {
            device_memory_allocator &allocator;
            vk::command_pool &command_pool;
            vk::buffer<std::byte> const &buffer;
            std::uint32_t width;
            std::uint32_t height;
            ui::scale scale = ui::scale::lock_aspect;
            VkFormat format = VK_FORMAT_B8G8R8A8_SRGB;
        };
        static texture create_with_mip_levels_from(args);
        static texture create_without_mip_levels_from(args);

Attributes

51
52
53
54
        vk::image image;
        vk::image_view image_view;
        vk::sampler sampler;
        ui::scale fit = ui::scale::lock_aspect;

Queries

57
58
        explicit operator bool() const noexcept;
    };

A rectangular area within another texture

Used for sprite sheets

63
64
65
66
67
    using sub_texture =
            std::pair<vk::texture const &, planet::affine::rectangle2d>;


}