7#include "gfx_pipeline_vulkan.hpp"
8#include "../container/module.hpp"
9#include "../font/font.hpp"
10#include "../macros.hpp"
11#include <vma/vk_mem_alloc.h>
14namespace hi {
inline namespace v1 {
43 static vk::VertexInputBindingDescription inputBindingDescription()
45 return {0,
sizeof(
vertex), vk::VertexInputRate::eVertex};
51 {0, 0, vk::Format::eR32G32B32Sfloat, offsetof(vertex,
position)},
53 {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(vertex,
textureCoord)},
54 {3, 0, vk::Format::eR16G16B16A16Sfloat, offsetof(vertex,
color)}};
59 sfloat_rg32 window_extent =
extent2{0.0, 0.0};
60 sfloat_rg32 viewport_scale =
scale2{0.0, 0.0};
61 sfloat_rg32 red_subpixel_offset =
vector2{0.0, 0.0};
62 sfloat_rg32 blue_subpixel_offset =
vector2{0.0, 0.0};
63 VkBool32 has_subpixels =
false;
67 return {{vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, 0,
sizeof(
push_constants)}};
72 float sdf_r8maxDistance;
73 float atlasImageWidth;
91 VmaAllocation allocation = {};
94 vk::ImageLayout layout = vk::ImageLayout::eUndefined;
96 void transitionLayout(
const gfx_device& device, vk::Format format, vk::ImageLayout nextLayout);
99 struct device_shared {
106 constexpr static int atlasImageWidth = 256;
107 constexpr static int atlasImageHeight = 256;
108 static_assert(atlasImageWidth == atlasImageHeight,
"needed for fwidth(textureCoord)");
110 constexpr static int atlasMaximumNrImages = 128;
111 constexpr static int stagingImageWidth = 64;
112 constexpr static int stagingImageHeight = 64;
114 constexpr static float atlasTextureCoordinateMultiplier = 1.0f / atlasImageWidth;
115 constexpr static float drawfontSize = 28.0f;
116 constexpr static float drawBorder = sdf_r8::max_distance;
117 constexpr static float scaledDrawBorder = drawBorder / drawfontSize;
119 gfx_device
const& device;
121 vk::ShaderModule vertexShaderModule;
122 vk::ShaderModule fragmentShaderModule;
126 vk::SpecializationInfo fragmentShaderSpecializationInfo;
133 vk::Sampler atlasSampler;
134 vk::DescriptorImageInfo atlasSamplerDescriptorImageInfo;
136 point3 atlas_allocation_position = {};
140 device_shared(gfx_device
const& device);
143 device_shared(device_shared
const&) =
delete;
144 device_shared& operator=(device_shared
const&) =
delete;
145 device_shared(device_shared&&) =
delete;
146 device_shared& operator=(device_shared&&) =
delete;
151 void destroy(gfx_device
const *vulkanDevice);
158 void drawInCommandBuffer(vk::CommandBuffer
const& commandBuffer);
184 vector_span<vertex>& vertices,
187 hi::font
const& font,
193 void teardownShaders(gfx_device
const *vulkanDevice);
194 void addAtlasImage();
196 void teardownAtlas(gfx_device
const *vulkanDevice);
197 void add_glyph_to_atlas(hi::font
const& font, glyph_id glyph, glyph_atlas_info& info)
noexcept;
203 get_glyph_from_atlas(hi::font
const& font, glyph_id glyph)
noexcept
205 auto& info = font.atlas_info(glyph);
207 if (info) [[likely]] {
208 return {&info,
false};
211 add_glyph_to_atlas(font, glyph, info);
212 return {&info,
true};
217 vector_span<vertex> vertexBufferData;
219 ~gfx_pipeline_SDF() =
default;
220 gfx_pipeline_SDF(
const gfx_pipeline_SDF&) =
delete;
221 gfx_pipeline_SDF& operator=(
const gfx_pipeline_SDF&) =
delete;
222 gfx_pipeline_SDF(gfx_pipeline_SDF&&) =
delete;
223 gfx_pipeline_SDF& operator=(gfx_pipeline_SDF&&) =
delete;
225 gfx_pipeline_SDF(gfx_surface *surface) : gfx_pipeline(surface) {}
227 void draw_in_command_buffer(vk::CommandBuffer commandBuffer, draw_context
const& context)
override;
231 int numberOfAtlasImagesInDescriptor = 0;
233 vk::Buffer vertexBuffer;
234 VmaAllocation vertexBufferAllocation;
236 [[nodiscard]] std::vector<vk::PipelineShaderStageCreateInfo> createShaderStages()
const override;
237 [[nodiscard]] std::vector<vk::DescriptorSetLayoutBinding> createDescriptorSetLayoutBindings()
const override;
238 [[nodiscard]] std::vector<vk::WriteDescriptorSet> createWriteDescriptorSet()
const override;
239 [[nodiscard]]
size_t getDescriptorSetVersion()
const override;
240 [[nodiscard]] std::vector<vk::PushConstantRange> createPushConstantRanges()
const override;
241 [[nodiscard]] vk::VertexInputBindingDescription createVertexInputBindingDescription()
const override;
242 [[nodiscard]] std::vector<vk::VertexInputAttributeDescription> createVertexInputAttributeDescriptions()
const override;
243 [[nodiscard]] std::vector<vk::PipelineColorBlendAttachmentState> getPipelineColorBlendAttachmentStates()
const override;
246 void build_vertex_buffers()
override;
247 void teardown_vertex_buffers()
override;
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
The HikoGUI API version 1.
Definition lookahead_iterator.hpp:6
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
This is a RGBA floating point color.
Definition color.hpp:45
A color for each corner of a quad.
Definition quad_color.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
A high-level geometric extent.
Definition extent2.hpp:29
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:19
Definition gfx_pipeline_SDF_vulkan.hpp:19
Definition gfx_pipeline_SDF_vulkan.hpp:24
sfloat_rgb32 position
The pixel-coordinates where the origin is located relative to the bottom-left corner of the window.
Definition gfx_pipeline_SDF_vulkan.hpp:26
sfloat_rgba16 color
The color of the glyph.
Definition gfx_pipeline_SDF_vulkan.hpp:36
sfloat_rgba32 clippingRectangle
Clipping rectangle. (x,y)=bottom-left, (z,w)=top-right.
Definition gfx_pipeline_SDF_vulkan.hpp:29
sfloat_rgb32 textureCoord
Definition gfx_pipeline_SDF_vulkan.hpp:33
Definition gfx_pipeline_SDF_vulkan.hpp:58
Definition gfx_pipeline_SDF_vulkan.hpp:71
Definition gfx_pipeline_SDF_vulkan.hpp:89
void prepareStagingPixmapForDrawing()
This will transition the staging texture to 'general' for writing by the CPU.
Definition gfx_pipeline_SDF_vulkan_impl.hpp:282
int atlasAllocationMaxHeight
During allocation on a row, we keep track of the tallest glyph.
Definition gfx_pipeline_SDF_vulkan.hpp:138
void prepare_atlas_for_rendering()
This will transition the atlas to 'shader-read'.
Definition gfx_pipeline_SDF_vulkan_impl.hpp:287
bool place_vertices(vector_span< vertex > &vertices, aarectangle const &clipping_rectangle, quad const &box, hi::font const &font, glyph_id glyph, quad_color colors) noexcept
Place vertices for a single glyph.
Definition gfx_pipeline_SDF_vulkan_impl.hpp:342
void destroy(gfx_device const *vulkanDevice)
Definition gfx_pipeline_SDF_vulkan_impl.hpp:210
void uploadStagingPixmapToAtlas(glyph_atlas_info const &location)
Once drawing in the staging pixmap is completed, you can upload it to the atlas.
Definition gfx_pipeline_SDF_vulkan_impl.hpp:254
glyph_atlas_info allocate_rect(extent2 draw_extent, scale2 draw_scale) noexcept
Allocate an glyph in the atlas.
Definition gfx_pipeline_SDF_vulkan_impl.hpp:218
A non-owning 2D pixel-based image.
Definition pixmap_span.hpp:34