HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
PipelineImage_DeviceShared.hpp
1// Copyright 2019 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/GUI/PipelineImage_TextureMap.hpp"
7#include "TTauri/GUI/PipelineImage_Page.hpp"
8#include "TTauri/GUI/GUIDevice_forward.hpp"
9#include "TTauri/Foundation/required.hpp"
10#include "TTauri/Foundation/R16G16B16A16SFloat.hpp"
11#include <vma/vk_mem_alloc.h>
12#include <vulkan/vulkan.hpp>
13#include <mutex>
14
15namespace tt {
16template<typename T> struct PixelMap;
17}
18
19namespace tt::PipelineImage {
20
21struct Image;
22
23struct DeviceShared final {
24 static constexpr int atlasNrHorizontalPages = 16;
25 static constexpr int atlasNrVerticalPages = 16;
26 static constexpr int atlasImageWidth = atlasNrHorizontalPages * Page::widthIncludingBorder;
27 static constexpr int atlasImageHeight = atlasNrVerticalPages * Page::heightIncludingBorder;
28 static constexpr int atlasNrPagesPerImage = atlasNrHorizontalPages * atlasNrVerticalPages;
29 static constexpr int atlasMaximumNrImages = 16;
30 static constexpr int stagingImageWidth = 1024;
31 static constexpr int stagingImageHeight = 1024;
32
33 GUIDevice const &device;
34
35 vk::ShaderModule vertexShaderModule;
36 vk::ShaderModule fragmentShaderModule;
38
39 TextureMap stagingTexture;
40 std::vector<TextureMap> atlasTextures;
41
43 vk::Sampler atlasSampler;
44 vk::DescriptorImageInfo atlasSamplerDescriptorImageInfo;
45
46 std::vector<Page> atlasFreePages;
47
48 DeviceShared(GUIDevice const &device);
50
51 DeviceShared(DeviceShared const &) = delete;
52 DeviceShared &operator=(DeviceShared const &) = delete;
53 DeviceShared(DeviceShared &&) = delete;
54 DeviceShared &operator=(DeviceShared &&) = delete;
55
59 void destroy(GUIDevice *vulkanDevice);
60
65 static ivec getAtlasPositionFromPage(Page page) noexcept {
66 ttlet imageIndex = page.nr / atlasNrPagesPerImage;
67 ttlet pageNrInsideImage = page.nr % atlasNrPagesPerImage;
68
69 ttlet pageY = pageNrInsideImage / atlasNrVerticalPages;
70 ttlet pageX = pageNrInsideImage % atlasNrVerticalPages;
71
72 ttlet x = pageX * Page::widthIncludingBorder + Page::border;
73 ttlet y = pageY * Page::heightIncludingBorder + Page::border;
74
75 return ivec{x, y, imageIndex, 1};
76 }
77
80 std::vector<Page> allocatePages(int const nrPages) noexcept;
81
84 void freePages(std::vector<Page> const &pages) noexcept;
85
89 Image makeImage(ivec extent) noexcept;
90
91 void drawInCommandBuffer(vk::CommandBuffer &commandBuffer);
92
93 tt::PixelMap<R16G16B16A16SFloat> getStagingPixelMap();
94
95 void prepareAtlasForRendering();
96
97private:
98 tt::PixelMap<R16G16B16A16SFloat> getStagingPixelMap(ivec extent) {
99 return getStagingPixelMap().submap({{0,0}, extent});
100 }
101
102 void updateAtlasWithStagingPixelMap(Image const &image);
103
104 void buildShaders();
105 void teardownShaders(GUIDevice_vulkan *vulkanDevice);
106 void addAtlasImage();
107 void buildAtlas();
108 void teardownAtlas(GUIDevice_vulkan *vulkanDevice);
109
110 friend Image;
111};
112
113}
A 4D vector.
Definition ivec.hpp:37
A 2D canvas of pixels.
Definition PixelMap.hpp:83
Definition GUIDevice_vulkan.hpp:22
Definition PipelineImage_DeviceShared.hpp:23
static ivec getAtlasPositionFromPage(Page page) noexcept
Definition PipelineImage_DeviceShared.hpp:65
void destroy(GUIDevice *vulkanDevice)
void freePages(std::vector< Page > const &pages) noexcept
Deallocate pages back to the atlas.
std::vector< Page > allocatePages(int const nrPages) noexcept
Allocate pages from the atlas.
Image makeImage(ivec extent) noexcept
Allocate an image in the atlas.
This is a image that is uploaded into the texture atlas.
Definition PipelineImage_Image.hpp:31
Definition PipelineImage_Page.hpp:11
Definition PipelineImage_TextureMap.hpp:14