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_page.hpp"
9#include "../required.hpp"
10#include "../color/sfloat_rgba16.hpp"
11#include <vk_mem_alloc.h>
12#include <vulkan/vulkan.hpp>
13#include <mutex>
14
15namespace tt {
16class gui_device_vulkan;
17template<typename T> class pixel_map;
18}
19
20namespace tt::pipeline_image {
21
22struct Image;
23
24struct device_shared final {
25 static constexpr int atlasNrHorizontalPages = 16;
26 static constexpr int atlasNrVerticalPages = 16;
27 static constexpr int atlasImageWidth = atlasNrHorizontalPages * Page::widthIncludingBorder;
28 static constexpr int atlasImageHeight = atlasNrVerticalPages * Page::heightIncludingBorder;
29 static constexpr int atlasNrPagesPerImage = atlasNrHorizontalPages * atlasNrVerticalPages;
30 static constexpr int atlasMaximumNrImages = 16;
31 static constexpr int stagingImageWidth = 1024;
32 static constexpr int stagingImageHeight = 1024;
33
34 gui_device_vulkan const &device;
35
36 vk::ShaderModule vertexShaderModule;
37 vk::ShaderModule fragmentShaderModule;
39
40 texture_map stagingTexture;
41 std::vector<texture_map> atlasTextures;
42
44 vk::Sampler atlasSampler;
45 vk::DescriptorImageInfo atlasSamplerDescriptorImageInfo;
46
47 std::vector<Page> atlasFreePages;
48
49 device_shared(gui_device_vulkan const &device);
51
52 device_shared(device_shared const &) = delete;
53 device_shared &operator=(device_shared const &) = delete;
54 device_shared(device_shared &&) = delete;
55 device_shared &operator=(device_shared &&) = delete;
56
60 void destroy(gui_device_vulkan *vulkanDevice);
61
66 static point3 getAtlasPositionFromPage(Page page) noexcept {
67 ttlet imageIndex = page.nr / atlasNrPagesPerImage;
68 ttlet pageNrInsideImage = page.nr % atlasNrPagesPerImage;
69
70 ttlet pageY = pageNrInsideImage / atlasNrVerticalPages;
71 ttlet pageX = pageNrInsideImage % atlasNrVerticalPages;
72
73 ttlet x = pageX * Page::widthIncludingBorder + Page::border;
74 ttlet y = pageY * Page::heightIncludingBorder + Page::border;
75
76 return point3{narrow_cast<float>(x), narrow_cast<float>(y), narrow_cast<float>(imageIndex)};
77 }
78
81 std::vector<Page> allocatePages(size_t num_pages) noexcept;
82
85 void freePages(std::vector<Page> const &pages) noexcept;
86
92 Image makeImage(size_t width, size_t height) noexcept;
93
94 void drawInCommandBuffer(vk::CommandBuffer &commandBuffer);
95
96 tt::pixel_map<sfloat_rgba16> getStagingPixelMap();
97
98 void prepareAtlasForRendering();
99
100private:
101 tt::pixel_map<sfloat_rgba16> getStagingPixelMap(size_t width, size_t height) {
102 return getStagingPixelMap().submap(0, 0, width, height);
103 }
104
105 void updateAtlasWithStagingPixelMap(Image const &image);
106
107 void buildShaders();
108 void teardownShaders(gui_device_vulkan *vulkanDevice);
109 void addAtlasImage();
110 void buildAtlas();
111 void teardownAtlas(gui_device_vulkan *vulkanDevice);
112
113 friend Image;
114};
115
116}
A 2D canvas of pixels.
Definition pixel_map.hpp:100
Definition gui_device_vulkan.hpp:23
Definition pipeline_image_device_shared.hpp:24
Image makeImage(size_t width, size_t height) noexcept
Allocate an image in the atlas.
void freePages(std::vector< Page > const &pages) noexcept
Deallocate pages back to the atlas.
std::vector< Page > allocatePages(size_t num_pages) noexcept
Allocate pages from the atlas.
static point3 getAtlasPositionFromPage(Page page) noexcept
Definition pipeline_image_device_shared.hpp:66
void destroy(gui_device_vulkan *vulkanDevice)
This is a image that is uploaded into the texture atlas.
Definition pipeline_image_image.hpp:28
Definition pipeline_image_page.hpp:12
Definition pipeline_image_texture_map.hpp:18