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 <vma/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 i32x4 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 i32x4{narrow_cast<int>(x), narrow_cast<int>(y), narrow_cast<int>(imageIndex), 1};
77 }
78
81 std::vector<Page> allocatePages(int const nrPages) noexcept;
82
85 void freePages(std::vector<Page> const &pages) noexcept;
86
90 Image makeImage(i32x4 extent) noexcept;
91
92 void drawInCommandBuffer(vk::CommandBuffer &commandBuffer);
93
94 tt::pixel_map<sfloat_rgba16> getStagingPixelMap();
95
96 void prepareAtlasForRendering();
97
98private:
99 tt::pixel_map<sfloat_rgba16> getStagingPixelMap(i32x4 extent) {
100 return getStagingPixelMap().submap({i32x4::point(0,0), extent});
101 }
102
103 void updateAtlasWithStagingPixelMap(Image const &image);
104
105 void buildShaders();
106 void teardownShaders(gui_device_vulkan *vulkanDevice);
107 void addAtlasImage();
108 void buildAtlas();
109 void teardownAtlas(gui_device_vulkan *vulkanDevice);
110
111 friend Image;
112};
113
114}
A 2D canvas of pixels.
Definition pixel_map.hpp:99
Definition gui_device_vulkan.hpp:23
Definition pipeline_image_device_shared.hpp:24
void freePages(std::vector< Page > const &pages) noexcept
Deallocate pages back to the atlas.
static i32x4 getAtlasPositionFromPage(Page page) noexcept
Definition pipeline_image_device_shared.hpp:66
std::vector< Page > allocatePages(int const nrPages) noexcept
Allocate pages from the atlas.
Image makeImage(i32x4 extent) noexcept
Allocate an image in the atlas.
void destroy(gui_device_vulkan *vulkanDevice)
This is a image that is uploaded into the texture atlas.
Definition pipeline_image_image.hpp:30
Definition pipeline_image_page.hpp:12
Definition pipeline_image_texture_map.hpp:18
A 4D vector.
Definition ivec.hpp:38
static constexpr numeric_array point() noexcept
Get a point at the origin.
Definition numeric_array.hpp:90