surface.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
#pragma once


#include <planet/vk/helpers.hpp>


namespace planet::vk {


    class instance;
    class physical_device;


    class surface final {
        friend class instance;
        VkSurfaceKHR handle;
        surface(vk::instance const &, VkSurfaceKHR);

        std::optional<std::uint32_t> graphics, present;

      public:
        ~surface();

        surface(surface const &) = delete;
        surface(surface &&) = delete;
        surface &operator=(surface const &) = delete;
        surface &operator=(surface &&i) = delete;

        VkSurfaceKHR get() const noexcept { return handle; }

        vk::instance const &instance;

Surface characteristics

Refreshes the characteristics of the surface for the specified GPU

36
        void refresh_characteristics(physical_device const &);

Queue indexes and properties

39
40
41
42
43
44
45
46
47
48
49
        std::vector<VkQueueFamilyProperties> queue_family_properties;

        bool has_queue_families() const noexcept {
            return graphics.has_value() and present.has_value();
        }
        std::uint32_t graphics_queue_index() const noexcept {
            return graphics.value();
        }
        std::uint32_t presentation_queue_index() const noexcept {
            return present.value();
        }

Swap chain support

These are only filled in if the physical device supports the required queues.

56
57
58
59
60
61
62
63
64
65
66
67
68
        VkSurfaceCapabilitiesKHR capabilities;
        std::vector<VkSurfaceFormatKHR> formats;
        VkSurfaceFormatKHR best_format = {};
        std::vector<VkPresentModeKHR> present_modes;
        VkPresentModeKHR best_present_mode = {};

        bool has_adequate_swap_chain_support() const noexcept {
            return not formats.empty() and not present_modes.empty();
        }
    };


}