depth_buffer.hpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once


#include <planet/vk/image.hpp>

#include <array>
#include <span>


namespace planet::vk::engine {


    struct depth_buffer {
        depth_buffer(device_memory_allocator &, swap_chain &);

        vk::image image;
        vk::image_view image_view;


        static VkFormat default_format(physical_device const &);

        static VkFormat find_supported_format(
                physical_device const &,
                std::span<VkFormat> candidates,
                VkImageTiling,
                VkFormatFeatureFlags);

        template<std::size_t N>
        static VkFormat find_supported_format(
                physical_device const &pd,
                std::array<VkFormat, N> candidates,
                VkImageTiling const t,
                VkFormatFeatureFlags const f) {
            return find_supported_format(pd, std::span{candidates}, t, f);
        }

        VkAttachmentDescription
                attachment_description(physical_device const &) const;
    };


    inline bool has_stencil_component(VkFormat const f) {
        return f == VK_FORMAT_D32_SFLOAT_S8_UINT
                or f == VK_FORMAT_D24_UNORM_S8_UINT;
    }


}