sandbox
Loading...
Searching...
No Matches
cube_image.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_GRAPHICS_IMAGES_CUBE_IMAGE_HPP_
3#define LIBSBX_GRAPHICS_IMAGES_CUBE_IMAGE_HPP_
4
5#include <filesystem>
6
7#include <libsbx/utility/timer.hpp>
8
9#include <libsbx/math/vector2.hpp>
10
11#include <libsbx/graphics/images/image.hpp>
12
13#include <libsbx/graphics/buffers/buffer.hpp>
14
15#include <libsbx/graphics/resource_storage.hpp>
16
17#include <libsbx/graphics/images/image2d.hpp>
18
19namespace sbx::graphics {
20
21class cube_image : public image {
22
23public:
24
25 cube_image(const std::filesystem::path& path, const std::string& suffix = ".png", graphics::format format = graphics::format::r8g8b8a8_srgb, VkFilter filter = VK_FILTER_LINEAR, VkSamplerAddressMode address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, bool anisotropic = true, bool mipmap = true);
26
27 cube_image(const math::vector2u& extent, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM, VkImageUsageFlags usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VkFilter filter = VK_FILTER_LINEAR, VkSamplerAddressMode address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT, bool anisotropic = false, bool mipmap = false);
28
29 ~cube_image() override;
30
31 auto name() const noexcept -> std::string override {
32 return "Cube Image";
33 }
34
35 auto write_descriptor_set(std::uint32_t binding, VkDescriptorType descriptor_type) const noexcept -> graphics::write_descriptor_set override {
36 auto descriptor_image_infos = std::vector<VkDescriptorImageInfo>{};
37
38 auto descriptor_image_info = VkDescriptorImageInfo{};
39 descriptor_image_info.imageLayout = (descriptor_type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
40 descriptor_image_info.imageView = (descriptor_type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ? _array_view : _view;
41 descriptor_image_info.sampler = _sampler;
42
43 descriptor_image_infos.push_back(descriptor_image_info);
44
45 auto descriptor_write = VkWriteDescriptorSet{};
46 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
47 descriptor_write.dstSet = nullptr;
48 descriptor_write.dstBinding = binding;
49 descriptor_write.dstArrayElement = 0;
50 descriptor_write.descriptorCount = 1;
51 descriptor_write.descriptorType = descriptor_type;
52
53 return graphics::write_descriptor_set{descriptor_write, descriptor_image_infos};
54 }
55
56private:
57
58 auto _load(const std::filesystem::path& path = {}, const std::string& suffix = {}) -> void;
59
60 inline static constexpr auto side_names = std::array<std::string_view, 6u>{"right", "left", "top", "bottom", "front", "back"};
61
62 bool _anisotropic;
63 bool _mipmap;
64 std::uint8_t _channels;
65
66 VkImageView _array_view;
67
68}; // class cube_image
69
71
72} // namespace sbx::graphics
73
74#endif // LIBSBX_GRAPHICS_IMAGES_CUBE_IMAGE_HPP_
Definition: cube_image.hpp:21
Definition: image.hpp:21
Definition: resource_storage.hpp:18
Definition: descriptor.hpp:13
A vector in two-dimensional space.
Definition: vector2.hpp:28