7#include "gfx_pipeline_vulkan_intf.hpp"
8#include "../container/container.hpp"
9#include "../geometry/geometry.hpp"
10#include "../image/image.hpp"
11#include "../font/font.hpp"
12#include "../macros.hpp"
13#include <vulkan/vulkan.hpp>
14#include <vma/vk_mem_alloc.h>
17hi_export_module(hikogui.GFX : gfx_pipeline_SDF_intf);
19hi_export
namespace hi {
inline namespace v1 {
48 static vk::VertexInputBindingDescription inputBindingDescription()
50 return {0,
sizeof(
vertex), vk::VertexInputRate::eVertex};
56 {0, 0, vk::Format::eR32G32B32Sfloat, offsetof(vertex,
position)},
58 {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(vertex,
textureCoord)},
59 {3, 0, vk::Format::eR16G16B16A16Sfloat, offsetof(vertex,
color)}};
64 sfloat_rg32 window_extent =
extent2{0.0, 0.0};
65 sfloat_rg32 viewport_scale =
scale2{0.0, 0.0};
66 sfloat_rg32 red_subpixel_offset =
vector2{0.0, 0.0};
67 sfloat_rg32 blue_subpixel_offset =
vector2{0.0, 0.0};
68 VkBool32 has_subpixels =
false;
72 return {{vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, 0,
sizeof(
push_constants)}};
77 float sdf_r8maxDistance;
78 float atlasImageWidth;
96 VmaAllocation allocation = {};
99 vk::ImageLayout layout = vk::ImageLayout::eUndefined;
101 void transitionLayout(
const gfx_device& device, vk::Format format, vk::ImageLayout nextLayout);
111 constexpr static int atlasImageWidth = 256;
112 constexpr static int atlasImageHeight = 256;
113 static_assert(atlasImageWidth == atlasImageHeight,
"needed for fwidth(textureCoord)");
115 constexpr static int atlasMaximumNrImages = 128;
116 constexpr static int stagingImageWidth = 64;
117 constexpr static int stagingImageHeight = 64;
119 constexpr static float atlasTextureCoordinateMultiplier = 1.0f / atlasImageWidth;
120 constexpr static float drawfontSize = 28.0f;
121 constexpr static float drawBorder = sdf_r8::max_distance;
122 constexpr static float scaledDrawBorder = drawBorder / drawfontSize;
124 gfx_device
const& device;
126 vk::ShaderModule vertexShaderModule;
127 vk::ShaderModule fragmentShaderModule;
131 vk::SpecializationInfo fragmentShaderSpecializationInfo;
138 vk::Sampler atlasSampler;
139 vk::DescriptorImageInfo atlasSamplerDescriptorImageInfo;
141 point3 atlas_allocation_position = {};
156 void destroy(gfx_device
const *vulkanDevice);
163 void drawInCommandBuffer(vk::CommandBuffer
const& commandBuffer);
189 vector_span<vertex>& vertices,
192 hi::font
const& font,
198 void teardownShaders(gfx_device
const *vulkanDevice);
199 void addAtlasImage();
201 void teardownAtlas(gfx_device
const *vulkanDevice);
202 void add_glyph_to_atlas(hi::font
const& font, glyph_id glyph, glyph_atlas_info& info)
noexcept;
208 get_glyph_from_atlas(hi::font
const& font, glyph_id glyph)
noexcept
210 auto& info = font.atlas_info(glyph);
212 if (info) [[likely]] {
213 return {&info,
false};
216 add_glyph_to_atlas(font, glyph, info);
217 return {&info,
true};
222 vector_span<vertex> vertexBufferData;
224 ~gfx_pipeline_SDF() =
default;
225 gfx_pipeline_SDF(
const gfx_pipeline_SDF&) =
delete;
226 gfx_pipeline_SDF& operator=(
const gfx_pipeline_SDF&) =
delete;
227 gfx_pipeline_SDF(gfx_pipeline_SDF&&) =
delete;
228 gfx_pipeline_SDF& operator=(gfx_pipeline_SDF&&) =
delete;
230 gfx_pipeline_SDF(gfx_surface *surface) : gfx_pipeline(surface) {}
232 void draw_in_command_buffer(vk::CommandBuffer commandBuffer, draw_context
const& context)
override;
235 push_constants pushConstants;
236 int numberOfAtlasImagesInDescriptor = 0;
238 vk::Buffer vertexBuffer;
239 VmaAllocation vertexBufferAllocation;
244 [[nodiscard]]
size_t getDescriptorSetVersion()
const override;
246 [[nodiscard]] vk::VertexInputBindingDescription createVertexInputBindingDescription()
const override;
251 void build_vertex_buffers()
override;
252 void teardown_vertex_buffers()
override;
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
This is a RGBA floating point color.
Definition color_intf.hpp:49
A color for each corner of a quad.
Definition quad_color.hpp:22
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
A high-level geometric extent.
Definition extent2.hpp:32
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:27
Definition gfx_pipeline_SDF_vulkan_intf.hpp:24
Definition gfx_pipeline_SDF_vulkan_intf.hpp:29
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_intf.hpp:31
sfloat_rgba16 color
The color of the glyph.
Definition gfx_pipeline_SDF_vulkan_intf.hpp:41
sfloat_rgba32 clippingRectangle
Clipping rectangle. (x,y)=bottom-left, (z,w)=top-right.
Definition gfx_pipeline_SDF_vulkan_intf.hpp:34
sfloat_rgb32 textureCoord
The x, y (relative to bottom-left) coordinate inside the texture-atlas, z is used as an index in the ...
Definition gfx_pipeline_SDF_vulkan_intf.hpp:38
Definition gfx_pipeline_SDF_vulkan_intf.hpp:63
Definition gfx_pipeline_SDF_vulkan_intf.hpp:76
Definition gfx_pipeline_SDF_vulkan_intf.hpp:94
Definition gfx_pipeline_SDF_vulkan_intf.hpp:104
void prepareStagingPixmapForDrawing()
This will transition the staging texture to 'general' for writing by the CPU.
Definition gfx_pipeline_SDF_vulkan_impl.hpp:285
int atlasAllocationMaxHeight
During allocation on a row, we keep track of the tallest glyph.
Definition gfx_pipeline_SDF_vulkan_intf.hpp:143
void prepare_atlas_for_rendering()
This will transition the atlas to 'shader-read'.
Definition gfx_pipeline_SDF_vulkan_impl.hpp:290
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:345
void destroy(gfx_device const *vulkanDevice)
Definition gfx_pipeline_SDF_vulkan_impl.hpp:213
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:257
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:221
A non-owning 2D pixel-based image.
Definition pixmap_span.hpp:34
A 2D pixel-based image.
Definition pixmap.hpp:38