HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gfx_pipeline_alpha_vulkan.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.hpp"
8#include "../container/module.hpp"
9#include "../macros.hpp"
10#include <vma/vk_mem_alloc.h>
11#include <span>
12
13namespace hi { inline namespace v1 {
14
17class gfx_pipeline_alpha : public gfx_pipeline {
18public:
22 struct alignas(16) vertex {
25 sfloat_rgba32 position;
26
30 sfloat_rgba32 clipping_rectangle;
31
34 float alpha;
35
36 vertex(sfloat_rgba32 position, sfloat_rgba32 clipping_rectangle, float alpha) noexcept :
38 {
39 }
40
41 static vk::VertexInputBindingDescription inputBindingDescription()
42 {
43 return {0, sizeof(vertex), vk::VertexInputRate::eVertex};
44 }
45
46 static std::vector<vk::VertexInputAttributeDescription> inputAttributeDescriptions()
47 {
48 return {
49 {0, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(vertex, position)},
50 {1, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(vertex, clipping_rectangle)},
51 {2, 0, vk::Format::eR32Sfloat, offsetof(vertex, alpha)},
52 };
53 }
54 };
55
57 sfloat_rg32 windowExtent = extent2{0.0, 0.0};
58 sfloat_rg32 viewportScale = scale2{0.0, 0.0};
59
60 static std::vector<vk::PushConstantRange> pushConstantRanges()
61 {
62 return {{vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, 0, sizeof(push_constants)}};
63 }
64 };
65
67 gfx_device const& device;
68
69 vk::ShaderModule vertexShaderModule;
70 vk::ShaderModule fragmentShaderModule;
72
73 device_shared(gfx_device const& device);
75
76 device_shared(device_shared const&) = delete;
77 device_shared& operator=(device_shared const&) = delete;
78 device_shared(device_shared&&) = delete;
79 device_shared& operator=(device_shared&&) = delete;
80
84 void destroy(gfx_device const *vulkanDevice);
85
86 void drawInCommandBuffer(vk::CommandBuffer const& commandBuffer);
87
88 static void place_vertices(vector_span<vertex>& vertices, aarectangle clipping_rectangle, quad box, float alpha);
89
90 private:
91 void buildShaders();
92 void teardownShaders(gfx_device const *vulkanDevice);
93 };
94
95 vector_span<vertex> vertexBufferData;
96
97 ~gfx_pipeline_alpha() = default;
99 gfx_pipeline_alpha& operator=(const gfx_pipeline_alpha&) = delete;
101 gfx_pipeline_alpha& operator=(gfx_pipeline_alpha&&) = delete;
102
103 gfx_pipeline_alpha(gfx_surface *surface) : gfx_pipeline(surface) {}
104
105 void draw_in_command_buffer(vk::CommandBuffer commandBuffer, draw_context const& context) override;
106
107protected:
108 push_constants pushConstants;
109
110 vk::Buffer vertexBuffer;
111 VmaAllocation vertexBufferAllocation;
112
113 [[nodiscard]] std::vector<vk::PipelineColorBlendAttachmentState> getPipelineColorBlendAttachmentStates() const override;
114 [[nodiscard]] std::vector<vk::PipelineShaderStageCreateInfo> createShaderStages() const override;
115 [[nodiscard]] std::vector<vk::DescriptorSetLayoutBinding> createDescriptorSetLayoutBindings() const override;
116 [[nodiscard]] std::vector<vk::WriteDescriptorSet> createWriteDescriptorSet() const override;
117 [[nodiscard]] size_t getDescriptorSetVersion() const override;
118 [[nodiscard]] std::vector<vk::PushConstantRange> createPushConstantRanges() const override;
119 [[nodiscard]] vk::VertexInputBindingDescription createVertexInputBindingDescription() const override;
120 [[nodiscard]] std::vector<vk::VertexInputAttributeDescription> createVertexInputAttributeDescriptions() const override;
121
122private:
123 void build_vertex_buffers() override;
124 void teardown_vertex_buffers() override;
125};
126
127}} // 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
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
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_alpha_vulkan.hpp:17
Definition gfx_pipeline_alpha_vulkan.hpp:22
sfloat_rgba32 clipping_rectangle
The position in pixels of the clipping rectangle relative to the bottom-left corner of the window,...
Definition gfx_pipeline_alpha_vulkan.hpp:30
float alpha
The alpha value of the resulting pixels inside the quad.
Definition gfx_pipeline_alpha_vulkan.hpp:34
sfloat_rgba32 position
The pixel-coordinates where the origin is located relative to the bottom-left corner of the window.
Definition gfx_pipeline_alpha_vulkan.hpp:25
Definition gfx_pipeline_alpha_vulkan.hpp:56
Definition gfx_pipeline_alpha_vulkan.hpp:66
void destroy(gfx_device const *vulkanDevice)
Definition gfx_pipeline_alpha_vulkan_impl.hpp:131