Images.hpp 2.11 KB
Newer Older
Shu's avatar
Shu committed
1
2
3
4
5
6
7
8
9
10
11
#pragma once

#include "../../api/Images.hpp"
#include "Memory.hpp"

namespace render::vk {

class Image: public render::Image {
public:
    virtual ~Image();

Shu's avatar
Shu committed
12
13
    const VkImageView &getView() const { return view; }

Shu's avatar
Shu committed
14
15
16
17
    static void MakeDefault();

    struct info {
        VkImage ref = nullptr;
Shu's avatar
Shu committed
18
        VkImageView view = nullptr;
Shu's avatar
Shu committed
19
20
21
        VkDeviceSize offset = 0;
    };

Shu's avatar
Shu committed
22
23
    static std::unique_ptr<Image> Create(const requirement &);

Shu's avatar
Shu committed
24
protected:
Shu's avatar
Shu committed
25
26
    Image(VkImage ref, VkImageView view, memory::ptr mem):
        ref(ref), view(view), memory(std::move(mem)) { }
Shu's avatar
Shu committed
27
    VkImage ref;
Shu's avatar
Shu committed
28
    VkImageView view;
Shu's avatar
Shu committed
29
30
31
32
33
34
35
36
37
38
39
40
41
    memory::ptr memory;
};

class Texture: public render::Texture, Image {
public:
    ~Texture();

    const VkDescriptorImageInfo &getDescriptor() const { return descriptor; }

    static std::unique_ptr<Texture> LoadFromFile(const std::string&, const sampling&);

protected:
    Texture(VkSampler sampler, VkImageView view, VkImageLayout layout, VkImage ref, memory::ptr memory):
Shu's avatar
Shu committed
42
        vk::Image(ref, view, std::move(memory)), sampler(sampler), descriptor({sampler, view, layout}) { }
Shu's avatar
Shu committed
43
44
45
46
    VkSampler sampler;
    const VkDescriptorImageInfo descriptor;
};

47
48
49
50
51
52
53
54
55
56
57
58
59
class TextureCube: public render::TextureCube, public Texture {
public:
    /// Looks for .right.dds, .left.dds, .top.dds, .bottom.dds, .front.dds, .back.dds
    static std::unique_ptr<TextureCube> LoadFromFiles(const std::string& prefix, const sampling&);
    static std::unique_ptr<TextureCube> LoadFromFiles(const std::array<std::string, 6>& paths, const sampling&);

protected:
    TextureCube(VkSampler sampler, VkImageView view, VkImageLayout layout, VkImage ref, memory::ptr memory):
        Texture(sampler, view, layout, ref, std::move(memory)) { }
};

class TextureArray: public render::TextureArray, public Texture {
public:
Shu's avatar
Shu committed
60
    static std::unique_ptr<TextureArray> LoadFromFiles(const std::vector<std::string>&, const sampling&, bool srgb = true);
61
62
63
64
65
66

protected:
    TextureArray(uint32_t size, VkSampler sampler, VkImageView view, VkImageLayout layout, VkImage ref, memory::ptr memory):
        render::TextureArray(size), Texture(sampler, view, layout, ref, std::move(memory)) { }
};

Shu's avatar
Shu committed
67
}