summaryrefslogtreecommitdiff
path: root/src/vk/graphics_pipeline_2d_solid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vk/graphics_pipeline_2d_solid.cpp')
-rw-r--r--src/vk/graphics_pipeline_2d_solid.cpp67
1 files changed, 34 insertions, 33 deletions
diff --git a/src/vk/graphics_pipeline_2d_solid.cpp b/src/vk/graphics_pipeline_2d_solid.cpp
index b7caaa7..5d210be 100644
--- a/src/vk/graphics_pipeline_2d_solid.cpp
+++ b/src/vk/graphics_pipeline_2d_solid.cpp
@@ -20,7 +20,7 @@
#include "../core.hpp"
#include "sprite.hpp"
-#include "uniform_buffer_object.hpp"
+#include "uniform_data_object.hpp"
namespace
{
@@ -77,7 +77,7 @@ load_pipeline(void *obj)
vert_shader_stage_info.flags = 0;
vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
vert_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->vert2d_shader_module;
+ cg_core.vk_device_with_swapchain->vert2d_solid_shader_module;
vert_shader_stage_info.pName = "main";
vert_shader_stage_info.pSpecializationInfo = nullptr;
@@ -88,7 +88,7 @@ load_pipeline(void *obj)
frag_shader_stage_info.flags = 0;
frag_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
frag_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->frag2d_shader_module;
+ cg_core.vk_device_with_swapchain->frag2d_solid_shader_module;
frag_shader_stage_info.pName = "main";
frag_shader_stage_info.pSpecializationInfo = nullptr;
@@ -177,9 +177,10 @@ load_pipeline(void *obj)
multisampling.alphaToOneEnable = VK_FALSE;
VkPipelineColorBlendAttachmentState color_blend_attachment = {};
- color_blend_attachment.blendEnable = VK_FALSE;
- color_blend_attachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
- color_blend_attachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
+ color_blend_attachment.blendEnable = VK_TRUE;
+ color_blend_attachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ color_blend_attachment.dstColorBlendFactor =
+ VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
color_blend_attachment.colorBlendOp = VK_BLEND_OP_ADD;
color_blend_attachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
color_blend_attachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
@@ -202,16 +203,17 @@ load_pipeline(void *obj)
color_blending.blendConstants[2] = 0.0f;
color_blending.blendConstants[3] = 0.0f;
- VkDynamicState dynamic_states[] = {
+ std::array<VkDynamicState, 3> dynamic_states{
VK_DYNAMIC_STATE_VIEWPORT,
- VK_DYNAMIC_STATE_LINE_WIDTH
+ VK_DYNAMIC_STATE_LINE_WIDTH,
+ VK_DYNAMIC_STATE_BLEND_CONSTANTS
};
VkPipelineDynamicStateCreateInfo dynamic_state_info = {};
dynamic_state_info.sType =
VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
- dynamic_state_info.dynamicStateCount = 2;
- dynamic_state_info.pDynamicStates = dynamic_states;
+ dynamic_state_info.dynamicStateCount = dynamic_states.size();
+ dynamic_state_info.pDynamicStates = dynamic_states.data();
VkGraphicsPipelineCreateInfo pipeline_info{};
pipeline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
@@ -300,31 +302,30 @@ GraphicsPipeline2DSolid::draw(
// Draw sprites
for(auto& [sprite, positions]: view->sprites_to_draw[current_frame])
{
- // Commands
- {
- std::array<VkDescriptorSet, 2> vk_descriptor_sets{
- view->descriptor_sets_2d[image_index],
- sprite->descriptor_sets[image_index]};
- VkDeviceSize offsets[]{0};
-
- vkCmdBindDescriptorSets(
- draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- cg_core.vk_graphics_pipeline_2d_solid_layout->pipeline, 0,
- vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr);
- vkCmdBindPipeline(
- draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- this->graphic_pipeline);
- vkCmdBindVertexBuffers(
- draw_command_buffer, 0, 1, &sprite->vertex_buffer->buffer, offsets);
- vkCmdDraw(
- draw_command_buffer, Sprite::vertex_count, positions.size(), 0, 0);
- }
+ std::array<VkDescriptorSet, 2> vk_descriptor_sets{
+ view->descriptor_sets_2d[image_index],
+ sprite->descriptor_sets[image_index]};
+ VkDeviceSize offsets[]{0};
+
+ vkCmdBindDescriptorSets(
+ draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
+ cg_core.vk_graphics_pipeline_2d_solid_layout->pipeline, 0,
+ vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr);
+ vkCmdBindPipeline(
+ draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
+ this->graphic_pipeline);
+ vkCmdBindVertexBuffers(
+ draw_command_buffer, 0, 1, &sprite->vertex_buffer->buffer, offsets);
- UBOVectors4D ubo_sprite_positions;
for(auto i{0}; i < positions.size(); i++)
- ubo_sprite_positions.vectors[i] = positions[i];
- sprite->ub_sprite_positions[image_index].copy_data(
- &ubo_sprite_positions);
+ {
+ ODOVector4D position{positions[i]};
+ vkCmdPushConstants(
+ draw_command_buffer,
+ cg_core.vk_graphics_pipeline_2d_solid_layout->pipeline,
+ VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(ODOVector4D), &position);
+ vkCmdDraw(draw_command_buffer, Sprite::vertex_count, 1, 0, 0);
+ }
}
// Prepare for the next frame.