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