7#include "gfx_pipeline_vulkan.hpp"
8#include "../container/module.hpp"
9#include "../image/module.hpp"
10#include "../codec/codec.hpp"
11#include "../macros.hpp"
12#include <vma/vk_mem_alloc.h>
14namespace hi {
inline namespace v1 {
40 static vk::VertexInputBindingDescription inputBindingDescription()
42 return {0,
sizeof(
vertex), vk::VertexInputRate::eVertex};
56 sfloat_rg32 windowExtent =
extent2{0.0, 0.0};
57 sfloat_rg32 viewportScale =
scale2{0.0, 0.0};
58 sfloat_rg32 atlasExtent =
extent2{0.0, 0.0};
59 sfloat_rg32 atlasScale =
scale2{0.0, 0.0};
63 return {{vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, 0,
sizeof(
push_constants)}};
72 vk::ImageLayout layout = vk::ImageLayout::eUndefined;
74 void transitionLayout(
const gfx_device& device, vk::Format format, vk::ImageLayout
nextLayout);
80 enum class state_type { uninitialized, drawing, uploaded };
85 gfx_device *device =
nullptr;
104 paged_image(gfx_surface
const *surface,
png const& image)
noexcept;
106 [[
nodiscard]]
constexpr explicit operator bool()
const noexcept
108 return device !=
nullptr;
118 hilet num_columns = (width + page_size - 1) / page_size;
119 hilet num_rows = (height + page_size - 1) / page_size;
120 return {num_columns, num_rows};
140 constexpr static std::size_t atlas_num_pages_per_axis = 8;
141 constexpr static std::size_t atlas_num_pages_per_image = atlas_num_pages_per_axis * atlas_num_pages_per_axis;
142 constexpr static std::size_t atlas_image_axis_size = atlas_num_pages_per_axis * (paged_image::page_size + 2);
143 constexpr static std::size_t atlas_maximum_num_images = 64;
144 constexpr static std::size_t staging_image_width = 1024;
145 constexpr static std::size_t staging_image_height = 1024;
147 gfx_device
const& device;
149 vk::ShaderModule vertex_shader_module;
150 vk::ShaderModule fragment_shader_module;
157 vk::Sampler atlas_sampler;
158 vk::DescriptorImageInfo atlas_sampler_descriptor_image_info;
181 void draw_in_command_buffer(vk::CommandBuffer
const& commandBuffer);
240 void prepare_staging_for_upload(
paged_image const& image)
noexcept;
244 void update_atlas_with_staging_pixmap(
paged_image const& image)
noexcept;
246 void build_shaders();
247 void teardown_shaders(gfx_device
const *device);
248 void add_atlas_image();
250 void teardown_atlas(gfx_device
const *device);
265 void draw_in_command_buffer(vk::CommandBuffer commandBuffer,
draw_context const&
context)
override;
268 push_constants pushConstants;
269 int numberOfAtlasImagesInDescriptor = 0;
271 vk::Buffer vertexBuffer;
277 [[
nodiscard]]
size_t getDescriptorSetVersion()
const override;
279 [[
nodiscard]] vk::VertexInputBindingDescription createVertexInputBindingDescription()
const override;
283 void build_vertex_buffers()
override;
284 void teardown_vertex_buffers()
override;
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
A high-level geometric extent.
Definition extent2.hpp:29
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:208
Definition gfx_pipeline_image_vulkan.hpp:19
Definition gfx_pipeline_image_vulkan.hpp:24
sfloat_rgba32 atlas_position
The x, y coordinate inside the texture-atlas, z is used as an index in the texture-atlas array.
Definition gfx_pipeline_image_vulkan.hpp:33
sfloat_rgba32 position
The pixel-coordinates where the origin is located relative to the bottom-left corner of the window.
Definition gfx_pipeline_image_vulkan.hpp:26
sfloat_rgba32 clipping_rectangle
The position in pixels of the clipping rectangle relative to the bottom-left corner of the window,...
Definition gfx_pipeline_image_vulkan.hpp:30
Definition gfx_pipeline_image_vulkan.hpp:55
Definition gfx_pipeline_image_vulkan.hpp:67
This is a image that is uploaded into the texture atlas.
Definition gfx_pipeline_image_vulkan.hpp:79
void upload(pixmap_span< sfloat_rgba16 const > image) noexcept
Upload image to atlas.
Definition gfx_pipeline_image_vulkan_impl.hpp:240
Definition gfx_pipeline_image_vulkan.hpp:139
void destroy(gfx_device const *vulkanDevice)
Definition gfx_pipeline_image_vulkan_impl.hpp:265
void place_vertices(vector_span< vertex > &vertices, aarectangle const &clipping_rectangle, quad const &box, paged_image const &image) noexcept
Place vertices for a single image.
Definition gfx_pipeline_image_vulkan_impl.hpp:623
std::vector< std::size_t > allocate_pages(std::size_t num_pages) noexcept
Allocate pages from the atlas.
Definition gfx_pipeline_image_vulkan_impl.hpp:272
void prepare_atlas_for_rendering()
Prepare the atlas so that it can be used as a texture map by the shaders.
Definition gfx_pipeline_image_vulkan_impl.hpp:460
hi::pixmap_span< sfloat_rgba16 > get_staging_pixmap()
Get the full staging pixel map excluding border.
Definition gfx_pipeline_image_vulkan_impl.hpp:292
void free_pages(std::vector< std::size_t > const &pages) noexcept
Deallocate pages back to the atlas.
Definition gfx_pipeline_image_vulkan_impl.hpp:287
A non-owning 2D pixel-based image.
Definition pixmap_span.hpp:34
A 2D pixel-based image.
Definition pixmap.hpp:38