HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
pipeline_image_device_shared.hpp
1// Copyright Take Vos 2019-2020.
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 "../required.hpp"
11#include "../rapid/sfloat_rgba16.hpp"
12#include "../geometry/quad.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;
20template<typename T>
21class pixel_map;
22
23namespace pipeline_image {
24
26 static constexpr std::size_t atlas_num_pages_per_axis = 8;
27 static constexpr std::size_t atlas_num_pages_per_image = atlas_num_pages_per_axis * atlas_num_pages_per_axis;
28 static constexpr std::size_t atlas_image_axis_size = atlas_num_pages_per_axis * (paged_image::page_size + 2);
29 static constexpr std::size_t atlas_maximum_num_images = 64;
30 static constexpr std::size_t staging_image_width = 1024;
31 static constexpr std::size_t staging_image_height = 1024;
32
33 gfx_device_vulkan const &device;
34
35 vk::ShaderModule vertex_shader_module;
36 vk::ShaderModule fragment_shader_module;
38
39 texture_map staging_texture;
40 std::vector<texture_map> atlas_textures;
41
43 vk::Sampler atlas_sampler;
44 vk::DescriptorImageInfo atlas_sampler_descriptor_image_info;
45
46 device_shared(gfx_device_vulkan const &device);
48
49 device_shared(device_shared const &) = delete;
50 device_shared &operator=(device_shared const &) = delete;
51 device_shared(device_shared &&) = delete;
52 device_shared &operator=(device_shared &&) = delete;
53
58 void destroy(gfx_device_vulkan *vulkanDevice);
59
63
66 void free_pages(std::vector<std::size_t> const &pages) noexcept;
67
68 void draw_in_command_buffer(vk::CommandBuffer &commandBuffer);
69
74 hi::pixel_map<sfloat_rgba16> get_staging_pixel_map();
75
79
89 vector_span<vertex> &vertices,
90 aarectangle const &clipping_rectangle,
91 quad const &box,
92 paged_image const &image) noexcept;
93
94private:
95 std::vector<std::size_t> _atlas_free_pages;
96
99 hi::pixel_map<sfloat_rgba16> get_staging_pixel_map(std::size_t width, std::size_t height)
100 {
101 return get_staging_pixel_map().submap(0, 0, width, height);
102 }
103
108 void make_staging_border_transparent(aarectangle border_rectangle) noexcept;
109
115 void clear_staging_between_border_and_upload(aarectangle border_rectangle, aarectangle upload_rectangle) noexcept;
116
127 void prepare_staging_for_upload(paged_image const &image) noexcept;
128
131 void update_atlas_with_staging_pixel_map(paged_image const &image) noexcept;
132
133 void build_shaders();
134 void teardown_shaders(gfx_device_vulkan *vulkan_device);
135 void add_atlas_image();
136 void build_atlas();
137 void teardown_atlas(gfx_device_vulkan *vulkan_device);
138
139 friend paged_image;
140};
141
142} // namespace pipeline_image
143} // namespace hi::inline v1
This file includes required definitions.
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Definition quad.hpp:14
Definition gfx_device_vulkan.hpp:21
This is a image that is uploaded into the texture atlas.
Definition paged_image.hpp:25
Definition pipeline_image_device_shared.hpp:25
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 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::pixel_map< sfloat_rgba16 > get_staging_pixel_map()
Get the full staging pixel map excluding border.
void destroy(gfx_device_vulkan *vulkanDevice)
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:17
Definition vector_span.hpp:134