HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
pipeline_image_device_shared.hpp
1// Copyright Take Vos 2019, 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "pipeline_image_texture_map.hpp"
8#include "pipeline_image_vertex.hpp"
9#include "paged_image.hpp"
10#include "../utility/module.hpp"
11#include "../image/module.hpp"
12#include "../geometry/module.hpp"
13#include "../vector_span.hpp"
14#include <vma/vk_mem_alloc.h>
15#include <vulkan/vulkan.hpp>
16#include <mutex>
17
18namespace hi::inline v1 {
19class gfx_device_vulkan;
20
21namespace pipeline_image {
22
24 static constexpr std::size_t atlas_num_pages_per_axis = 8;
25 static constexpr std::size_t atlas_num_pages_per_image = atlas_num_pages_per_axis * atlas_num_pages_per_axis;
26 static constexpr std::size_t atlas_image_axis_size = atlas_num_pages_per_axis * (paged_image::page_size + 2);
27 static constexpr std::size_t atlas_maximum_num_images = 64;
28 static constexpr std::size_t staging_image_width = 1024;
29 static constexpr std::size_t staging_image_height = 1024;
30
31 gfx_device_vulkan const &device;
32
33 vk::ShaderModule vertex_shader_module;
34 vk::ShaderModule fragment_shader_module;
36
37 texture_map staging_texture;
38 std::vector<texture_map> atlas_textures;
39
41 vk::Sampler atlas_sampler;
42 vk::DescriptorImageInfo atlas_sampler_descriptor_image_info;
43
44 device_shared(gfx_device_vulkan const &device);
46
47 device_shared(device_shared const &) = delete;
48 device_shared &operator=(device_shared const &) = delete;
49 device_shared(device_shared &&) = delete;
50 device_shared &operator=(device_shared &&) = delete;
51
56 void destroy(gfx_device_vulkan const*vulkanDevice);
57
61
64 void free_pages(std::vector<std::size_t> const &pages) noexcept;
65
66 void draw_in_command_buffer(vk::CommandBuffer const &commandBuffer);
67
73
77
87 vector_span<vertex> &vertices,
88 aarectangle const &clipping_rectangle,
89 quad const &box,
90 paged_image const &image) noexcept;
91
92private:
93 std::vector<std::size_t> _atlas_free_pages;
94
97 hi::pixmap_span<sfloat_rgba16> get_staging_pixmap(std::size_t width, std::size_t height)
98 {
99 return get_staging_pixmap().subimage(0, 0, width, height);
100 }
101
106 void make_staging_border_transparent(aarectangle border_rectangle) noexcept;
107
113 void clear_staging_between_border_and_upload(aarectangle border_rectangle, aarectangle upload_rectangle) noexcept;
114
125 void prepare_staging_for_upload(paged_image const &image) noexcept;
126
129 void update_atlas_with_staging_pixmap(paged_image const &image) noexcept;
130
131 void build_shaders();
132 void teardown_shaders(gfx_device_vulkan const *vulkan_device);
133 void add_atlas_image();
134 void build_atlas();
135 void teardown_atlas(gfx_device_vulkan const *vulkan_device);
136
137 friend paged_image;
138};
139
140} // namespace pipeline_image
141} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:13
Definition quad.hpp:17
Definition gfx_device_vulkan.hpp:21
This is a image that is uploaded into the texture atlas.
Definition paged_image.hpp:22
Definition pipeline_image_device_shared.hpp:23
void place_vertices(vector_span< vertex > &vertices, aarectangle const &clipping_rectangle, quad const &box, paged_image const &image) noexcept
Place vertices for a single image.
void destroy(gfx_device_vulkan const *vulkanDevice)
void free_pages(std::vector< std::size_t > const &pages) noexcept
Deallocate pages back to the atlas.
std::vector< std::size_t > allocate_pages(std::size_t num_pages) noexcept
Allocate pages from the atlas.
hi::pixmap_span< sfloat_rgba16 > get_staging_pixmap()
Get the full staging pixel map excluding border.
void prepare_atlas_for_rendering()
Prepare the atlas so that it can be used as a texture map by the shaders.
Definition pipeline_image_texture_map.hpp:16
A non-owning 2D pixel-based image.
Definition pixmap_span.hpp:31
Definition vector_span.hpp:133