HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gfx_pipeline_override_vulkan_intf.hpp
1// Copyright Take Vos 2022.
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_intf.hpp"
8#include "../container/container.hpp"
9#include "../image/image.hpp"
10#include "../color/color.hpp"
11#include "../geometry/geometry.hpp"
12#include "../macros.hpp"
13#include <vma/vk_mem_alloc.h>
14#include <vulkan/vulkan.hpp>
15#include <span>
16#include <vector>
17
18hi_export_module(hikogui.GFX : gfx_pipeline_override_intf);
19
20hi_export namespace hi { inline namespace v1 {
21
24class gfx_pipeline_override : public gfx_pipeline {
25public:
29 struct alignas(16) vertex {
32 sfloat_rgba32 position;
33
37 sfloat_rgba32 clipping_rectangle;
38
41 sfloat_rgba16 color;
42
45 sfloat_rgba16 blend_factor;
46
47 vertex(sfloat_rgba32 position, sfloat_rgba32 clipping_rectangle, sfloat_rgba16 color, sfloat_rgba16 blend_factor) noexcept :
49 {
50 }
51
52 static vk::VertexInputBindingDescription inputBindingDescription()
53 {
54 return {0, sizeof(vertex), vk::VertexInputRate::eVertex};
55 }
56
57 static std::vector<vk::VertexInputAttributeDescription> inputAttributeDescriptions()
58 {
59 return {
60 {0, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(vertex, position)},
61 {1, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(vertex, clipping_rectangle)},
62 {2, 0, vk::Format::eR16G16B16A16Sfloat, offsetof(vertex, color)},
63 {3, 0, vk::Format::eR16G16B16A16Sfloat, offsetof(vertex, blend_factor)},
64 };
65 }
66 };
67
69 sfloat_rg32 windowExtent = extent2{0.0, 0.0};
70 sfloat_rg32 viewportScale = scale2{0.0, 0.0};
71
72 static std::vector<vk::PushConstantRange> pushConstantRanges()
73 {
74 return {{vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, 0, sizeof(push_constants)}};
75 }
76 };
77
79 gfx_device const& device;
80
81 vk::ShaderModule vertexShaderModule;
82 vk::ShaderModule fragmentShaderModule;
84
85 device_shared(gfx_device const& device);
87
88 device_shared(device_shared const&) = delete;
89 device_shared& operator=(device_shared const&) = delete;
90 device_shared(device_shared&&) = delete;
91 device_shared& operator=(device_shared&&) = delete;
92
96 void destroy(gfx_device const *vulkanDevice);
97
98 void drawInCommandBuffer(vk::CommandBuffer const& commandBuffer);
99
100 static void place_vertices(vector_span<vertex>& vertices, aarectangle clipping_rectangle, quad box, quad_color color, quad_color blend_factor);
101
102 private:
103 void buildShaders();
104 void teardownShaders(gfx_device const *vulkanDevice);
105 };
106
107 vector_span<vertex> vertexBufferData;
108
109 ~gfx_pipeline_override() = default;
111 gfx_pipeline_override& operator=(const gfx_pipeline_override&) = delete;
113 gfx_pipeline_override& operator=(gfx_pipeline_override&&) = delete;
114
115 gfx_pipeline_override(gfx_surface *surface) : gfx_pipeline(surface) {}
116
117 void draw_in_command_buffer(vk::CommandBuffer commandBuffer, draw_context const& context) override;
118
119protected:
120 push_constants pushConstants;
121
122 vk::Buffer vertexBuffer;
123 VmaAllocation vertexBufferAllocation;
124
125 [[nodiscard]] std::vector<vk::PipelineColorBlendAttachmentState> getPipelineColorBlendAttachmentStates() const override;
126 [[nodiscard]] std::vector<vk::PipelineShaderStageCreateInfo> createShaderStages() const override;
127 [[nodiscard]] std::vector<vk::DescriptorSetLayoutBinding> createDescriptorSetLayoutBindings() const override;
128 [[nodiscard]] std::vector<vk::WriteDescriptorSet> createWriteDescriptorSet() const override;
129 [[nodiscard]] size_t getDescriptorSetVersion() const override;
130 [[nodiscard]] std::vector<vk::PushConstantRange> createPushConstantRanges() const override;
131 [[nodiscard]] vk::VertexInputBindingDescription createVertexInputBindingDescription() const override;
132 [[nodiscard]] std::vector<vk::VertexInputAttributeDescription> createVertexInputAttributeDescriptions() const override;
133
134private:
135 void build_vertex_buffers() override;
136 void teardown_vertex_buffers() override;
137};
138
139}} // namespace hi::v1
Defined the color type.
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
Definition scale2.hpp:18
Draw context for drawing using the HikoGUI shaders.
Definition draw_context_intf.hpp:209
Definition gfx_pipeline_override_vulkan_intf.hpp:24
Definition gfx_pipeline_override_vulkan_intf.hpp:29
sfloat_rgba32 clipping_rectangle
The position in pixels of the clipping rectangle relative to the bottom-left corner of the window,...
Definition gfx_pipeline_override_vulkan_intf.hpp:37
sfloat_rgba16 color
The color value of the resulting pixels inside the quad.
Definition gfx_pipeline_override_vulkan_intf.hpp:41
sfloat_rgba32 position
The pixel-coordinates where the origin is located relative to the bottom-left corner of the window.
Definition gfx_pipeline_override_vulkan_intf.hpp:32
sfloat_rgba16 blend_factor
The blend-factor value of the resulting pixels inside the quad.
Definition gfx_pipeline_override_vulkan_intf.hpp:45
Definition gfx_pipeline_override_vulkan_intf.hpp:68
Definition gfx_pipeline_override_vulkan_intf.hpp:78
void destroy(gfx_device const *vulkanDevice)
Definition gfx_pipeline_override_vulkan_impl.hpp:140