HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gfx_pipeline_box_vulkan.hpp
1// Copyright Take Vos 2020-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 "gfx_pipeline_vulkan.hpp"
8#include "../container/module.hpp"
9#include "../image/module.hpp"
10#include "../macros.hpp"
11#include <vma/vk_mem_alloc.h>
12#include <span>
13
14namespace hi { inline namespace v1 {
15
18class gfx_pipeline_box : public gfx_pipeline {
19public:
23 struct alignas(16) vertex {
26 sfloat_rgba32 position;
27
31 sfloat_rgba32 clipping_rectangle;
32
40 sfloat_rgba32 corner_coordinate;
41
44 sfloat_rgba32 corner_radii;
45
48 sfloat_rgba16 fill_color;
49
52 sfloat_rgba16 line_color;
53
54 float line_width;
55
56 vertex(
57 sfloat_rgba32 position,
58 sfloat_rgba32 clipping_rectangle,
59 sfloat_rgba32 corner_coordinate,
60 sfloat_rgba32 corner_radii,
61 sfloat_rgba16 fill_color,
62 sfloat_rgba16 line_color,
63 float line_width) noexcept :
70 line_width(line_width)
71 {
72 }
73
74 static vk::VertexInputBindingDescription inputBindingDescription()
75 {
76 return {0, sizeof(vertex), vk::VertexInputRate::eVertex};
77 }
78
79 static std::vector<vk::VertexInputAttributeDescription> inputAttributeDescriptions()
80 {
81 return {
82 {0, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(vertex, position)},
83 {1, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(vertex, clipping_rectangle)},
84 {2, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(vertex, corner_coordinate)},
85 {3, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(vertex, corner_radii)},
86 {4, 0, vk::Format::eR16G16B16A16Sfloat, offsetof(vertex, fill_color)},
87 {5, 0, vk::Format::eR16G16B16A16Sfloat, offsetof(vertex, line_color)},
88 {6, 0, vk::Format::eR32Sfloat, offsetof(vertex, line_width)},
89 };
90 }
91 };
92
94 sfloat_rg32 windowExtent = extent2{0.0, 0.0};
95 sfloat_rg32 viewportScale = scale2{0.0, 0.0};
96
97 static std::vector<vk::PushConstantRange> pushConstantRanges()
98 {
99 return {{vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, 0, sizeof(push_constants)}};
100 }
101 };
102
104 gfx_device const& device;
105
106 vk::ShaderModule vertexShaderModule;
107 vk::ShaderModule fragmentShaderModule;
109
110 device_shared(gfx_device const& device);
112
113 device_shared(device_shared const&) = delete;
114 device_shared& operator=(device_shared const&) = delete;
115 device_shared(device_shared&&) = delete;
116 device_shared& operator=(device_shared&&) = delete;
117
121 void destroy(gfx_device const *vulkanDevice);
122
123 void drawInCommandBuffer(vk::CommandBuffer const& commandBuffer);
124
125 static void place_vertices(
127 aarectangle clipping_rectangle,
128 quad box,
131 float line_width,
133
134 private:
135 void buildShaders();
136 void teardownShaders(gfx_device const *vulkanDevice);
137 };
138
139 vector_span<vertex> vertexBufferData;
140
141 ~gfx_pipeline_box() = default;
142 gfx_pipeline_box(const gfx_pipeline_box&) = delete;
143 gfx_pipeline_box& operator=(const gfx_pipeline_box&) = delete;
145 gfx_pipeline_box& operator=(gfx_pipeline_box&&) = delete;
146
147 gfx_pipeline_box(gfx_surface *surface) : gfx_pipeline(surface) {}
148
149 void draw_in_command_buffer(vk::CommandBuffer commandBuffer, draw_context const& context) override;
150
151protected:
152 push_constants pushConstants;
153
154 vk::Buffer vertexBuffer;
155 VmaAllocation vertexBufferAllocation;
156
157 [[nodiscard]] std::vector<vk::PipelineShaderStageCreateInfo> createShaderStages() const override;
158 [[nodiscard]] std::vector<vk::DescriptorSetLayoutBinding> createDescriptorSetLayoutBindings() const override;
159 [[nodiscard]] std::vector<vk::WriteDescriptorSet> createWriteDescriptorSet() const override;
160 [[nodiscard]] size_t getDescriptorSetVersion() const override;
161 [[nodiscard]] std::vector<vk::PushConstantRange> createPushConstantRanges() const override;
162 [[nodiscard]] vk::VertexInputBindingDescription createVertexInputBindingDescription() const override;
163 [[nodiscard]] std::vector<vk::VertexInputAttributeDescription> createVertexInputAttributeDescriptions() const override;
164
165private:
166 void build_vertex_buffers() override;
167 void teardown_vertex_buffers() override;
168};
169
170}} // namespace hi::v1
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
A color for each corner of a quad.
Definition quad_color.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:19
A high-level geometric extent.
Definition extent2.hpp:29
Definition scale2.hpp:13
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:208
Definition gfx_pipeline_box_vulkan.hpp:18
Definition gfx_pipeline_box_vulkan.hpp:23
sfloat_rgba16 line_color
border color of the box.
Definition gfx_pipeline_box_vulkan.hpp:52
sfloat_rgba32 corner_radii
Shape of each corner, negative values are cut corners, positive values are rounded corners.
Definition gfx_pipeline_box_vulkan.hpp:44
sfloat_rgba32 corner_coordinate
Double 2D coordinates inside the quad, used to determine the distance from the sides and corner insid...
Definition gfx_pipeline_box_vulkan.hpp:40
sfloat_rgba16 fill_color
background color of the box.
Definition gfx_pipeline_box_vulkan.hpp:48
sfloat_rgba32 position
The pixel-coordinates where the origin is located relative to the bottom-left corner of the window.
Definition gfx_pipeline_box_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_box_vulkan.hpp:31
Definition gfx_pipeline_box_vulkan.hpp:93
Definition gfx_pipeline_box_vulkan.hpp:103
void destroy(gfx_device const *vulkanDevice)
Definition gfx_pipeline_box_vulkan_impl.hpp:117