7#include "gfx_pipeline_override_vulkan_intf.hpp"
8#include "gfx_device_vulkan_impl.hpp"
9#include "../macros.hpp"
10#include <vulkan/vulkan.hpp>
12hi_export_module(hikogui.GFX : gfx_pipeline_override_impl);
14hi_export
namespace hi {
inline namespace v1 {
33 vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB |
34 vk::ColorComponentFlagBits::eA}};
37hi_inline
void gfx_pipeline_override::draw_in_command_buffer(vk::CommandBuffer commandBuffer, draw_context
const&
context)
39 gfx_pipeline::draw_in_command_buffer(commandBuffer,
context);
41 hi_axiom_not_null(device());
42 device()->flushAllocation(vertexBufferAllocation, 0, vertexBufferData.size() *
sizeof(vertex));
48 device()->override_pipeline->drawInCommandBuffer(commandBuffer);
53 pushConstants.viewportScale = scale2{2.0f / extent.width, 2.0f / extent.height};
54 commandBuffer.pushConstants(
56 vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
58 sizeof(push_constants),
64 device()->cmdBeginDebugUtilsLabelEXT(commandBuffer,
"draw alpha overlays");
66 device()->cmdEndDebugUtilsLabelEXT(commandBuffer);
71 hi_axiom_not_null(device());
72 return device()->override_pipeline->shaderStages;
85hi_inline
size_t gfx_pipeline_override::getDescriptorSetVersion()
const
92 return push_constants::pushConstantRanges();
95hi_inline vk::VertexInputBindingDescription gfx_pipeline_override::createVertexInputBindingDescription()
const
97 return vertex::inputBindingDescription();
102 return vertex::inputAttributeDescriptions();
105hi_inline
void gfx_pipeline_override::build_vertex_buffers()
111 vk::BufferCreateFlags(),
113 vk::BufferUsageFlagBits::eVertexBuffer,
114 vk::SharingMode::eExclusive};
120 hi_axiom_not_null(device());
122 device()->setDebugUtilsObjectNameEXT(vertexBuffer,
"alpha-pipeline vertex buffer");
123 vertexBufferData = device()->mapMemory<vertex>(vertexBufferAllocation);
126hi_inline
void gfx_pipeline_override::teardown_vertex_buffers()
128 hi_axiom_not_null(device());
129 device()->unmapMemory(vertexBufferAllocation);
130 device()->destroyBuffer(vertexBuffer, vertexBufferAllocation);
133hi_inline gfx_pipeline_override::device_shared::device_shared(gfx_device
const& device) : device(device)
138hi_inline gfx_pipeline_override::device_shared::~device_shared() {}
140hi_inline
void gfx_pipeline_override::device_shared::destroy(gfx_device
const*vulkanDevice)
142 hi_assert_not_null(vulkanDevice);
143 teardownShaders(vulkanDevice);
146hi_inline
void gfx_pipeline_override::device_shared::drawInCommandBuffer(vk::CommandBuffer
const& commandBuffer)
148 commandBuffer.bindIndexBuffer(device.quadIndexBuffer, 0, vk::IndexType::eUint16);
151hi_inline
void gfx_pipeline_override::device_shared::place_vertices(vector_span<vertex>& vertices,
aarectangle clipping_rectangle, quad box,
quad_color color,
quad_color blend_factor)
153 auto const clipping_rectangle_ = sfloat_rgba32{clipping_rectangle};
155 vertices.emplace_back(box.p0, clipping_rectangle_,
color.p0, blend_factor.
p0);
156 vertices.emplace_back(box.p1, clipping_rectangle_,
color.p1, blend_factor.
p1);
157 vertices.emplace_back(box.p2, clipping_rectangle_,
color.p2, blend_factor.
p2);
158 vertices.emplace_back(box.p3, clipping_rectangle_,
color.p3, blend_factor.
p3);
161hi_inline
void gfx_pipeline_override::device_shared::buildShaders()
163 vertexShaderModule = device.loadShader(URL(
"resource:override_vulkan.vert.spv"));
164 device.setDebugUtilsObjectNameEXT(vertexShaderModule,
"alpha-pipeline vertex shader");
166 fragmentShaderModule = device.loadShader(URL(
"resource:override_vulkan.frag.spv"));
167 device.setDebugUtilsObjectNameEXT(vertexShaderModule,
"alpha-pipeline fragment shader");
170 {vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule,
"main"},
171 {vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule,
"main"}};
174hi_inline
void gfx_pipeline_override::device_shared::teardownShaders(gfx_device
const*vulkanDevice)
176 hi_assert_not_null(vulkanDevice);
177 vulkanDevice->destroy(vertexShaderModule);
178 vulkanDevice->destroy(fragmentShaderModule);
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
std::ptrdiff_t ssize_t
Signed size/index into an array.
Definition misc.hpp:32
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
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
color p0
left-bottom
Definition quad_color.hpp:24
color p2
left-top
Definition quad_color.hpp:26
color p3
right-top
Definition quad_color.hpp:27
color p1
right-bottom
Definition quad_color.hpp:25
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33