summaryrefslogtreecommitdiff
path: root/src/vk/graphics_pipeline_2d_solid_layout.cpp
blob: 11d080be32ea9ee845bbc580a987c0bf21f2b9af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright 2022-2023 Frederico de Oliveira Linhares
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "graphics_pipeline_2d_solid_layout.hpp"

#include <array>

#include "../core.hpp"
#include "uniform_data_object.hpp"

namespace
{

void
load_pipeline(void *obj)
{
  auto self = static_cast<VK::GraphicsPipeline2DSolidLayout*>(obj);

  std::array<VkDescriptorSetLayout, 2> set_layouts{
    cg_core.vk_descriptor_set_layout->view,
    cg_core.vk_descriptor_set_layout->texture
  };

  std::array<VkPushConstantRange, 1> push_constants;
  push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
  push_constants[0].offset = 0;
  push_constants[0].size = sizeof(VK::UDOVector4D);

  VkPipelineLayoutCreateInfo pipeline_layout_info{};
  pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
  pipeline_layout_info.setLayoutCount = set_layouts.size();
  pipeline_layout_info.pSetLayouts = set_layouts.data();
  pipeline_layout_info.pushConstantRangeCount = push_constants.size();
  pipeline_layout_info.pPushConstantRanges = push_constants.data();

  if(vkCreatePipelineLayout(
       cg_core.vk_device_with_swapchain->device, &pipeline_layout_info,
       nullptr, &self->pipeline) != VK_SUCCESS)
    throw CommandError{"Failed to create Vulkan pipeline layout."};
}

void
unload_pipeline(void *obj)
{
  auto self = static_cast<VK::GraphicsPipeline2DSolidLayout*>(obj);

  vkDestroyPipelineLayout(
    cg_core.vk_device_with_swapchain->device, self->pipeline, nullptr);
}

const CommandChain loader{
  {&load_pipeline, &unload_pipeline}
};

}

namespace VK
{

GraphicsPipeline2DSolidLayout::GraphicsPipeline2DSolidLayout()
{
  loader.execute(this);
}

GraphicsPipeline2DSolidLayout::~GraphicsPipeline2DSolidLayout()
{
  loader.revert(this);
}

}