HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
paged_image.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 "../geometry/extent.hpp"
8#include <cstdlib>
9#include <span>
10#include <atomic>
11#include <string>
12#include <vector>
13
14namespace hi::inline v1 {
15
16template<typename T>
17class pixel_map;
18class png;
19class sfloat_rgba16;
20class gfx_surface;
21class gfx_device;
22
26 enum class state_type { uninitialized, drawing, uploaded };
27
28 static constexpr std::size_t page_size = 62; // 64x64 including a 1 pixel border.
29
30 mutable std::atomic<state_type> state = state_type::uninitialized;
31 gfx_device *device = nullptr;
32 std::size_t width;
33 std::size_t height;
35
37 constexpr paged_image() noexcept = default;
38 paged_image(paged_image &&other) noexcept;
39 paged_image &operator=(paged_image &&other) noexcept;
40 paged_image(paged_image const &other) = delete;
41 paged_image &operator=(paged_image const &other) = delete;
42
43 paged_image(gfx_surface const *surface, std::size_t width, std::size_t height) noexcept;
44 paged_image(gfx_surface const *surface, pixel_map<sfloat_rgba16> const &image) noexcept;
45 paged_image(gfx_surface const *surface, png const &image) noexcept;
46
47 [[nodiscard]] constexpr explicit operator bool() const noexcept
48 {
49 return device != nullptr;
50 }
51
52 [[nodiscard]] constexpr extent2 size() const noexcept
53 {
54 return extent2{narrow_cast<float>(width), narrow_cast<float>(height)};
55 }
56
57 [[nodiscard]] constexpr std::pair<std::size_t, std::size_t> size_in_int_pages() const noexcept
58 {
59 hilet num_columns = (width + page_size - 1) / page_size;
60 hilet num_rows = (height + page_size - 1) / page_size;
61 return {num_columns, num_rows};
62 }
63
64 [[nodiscard]] constexpr extent2 size_in_float_pages() const noexcept
65 {
66 constexpr auto page_size_ = f32x4{narrow_cast<float>(page_size), narrow_cast<float>(page_size)};
67 auto size = f32x4{i32x4{narrow_cast<int32_t>(width), narrow_cast<int32_t>(height), 1, 1}};
68 return extent2{size / page_size_};
69 }
70
73 void upload(pixel_map<sfloat_rgba16> const &image) noexcept;
74
77 void upload(png const &image) noexcept;
78};
79
80} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
Definition png.hpp:23
Definition gfx_device.hpp:22
Definition gfx_surface.hpp:16
A 2D canvas of pixels.
Definition pixel_map.hpp:110
This is a image that is uploaded into the texture atlas.
Definition paged_image.hpp:25
void upload(png const &image) noexcept
Upload image to atlas.
void upload(pixel_map< sfloat_rgba16 > const &image) noexcept
Upload image to atlas.