~sircmpwn/xrgears

ref: 4d2c57c7eae28e5eab820a11a3ca1ea08fa40441 xrgears/vitamin-k/vikSwapChain.hpp -rw-r--r-- 2.1 KiB
4d2c57c7 — Lubosz Sarnecki rename functions 4 years ago
                                                                                
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
#pragma once

#include <vulkan/vulkan.h>

#include <vector>

#include "../vks/vksLog.hpp"

namespace vik {

struct SwapChainBuffer {
  VkImage image;
  VkImageView view;
};

class SwapChain {
public:
  std::vector<SwapChainBuffer> buffers;
  std::vector<VkFramebuffer> frame_buffers;

  uint32_t image_count = 0;

  SwapChain() {}
  ~SwapChain() {}

  void create_image_view(const VkDevice &device, const VkImage& image,
                         const VkFormat &format, VkImageView *view) {
    VkImageViewCreateInfo view_create_info = {};
    view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
    view_create_info.pNext = NULL;
    view_create_info.format = format;
    view_create_info.components = {
      VK_COMPONENT_SWIZZLE_R,
      VK_COMPONENT_SWIZZLE_G,
      VK_COMPONENT_SWIZZLE_B,
      VK_COMPONENT_SWIZZLE_A
    };
    view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
    view_create_info.subresourceRange.baseMipLevel = 0;
    view_create_info.subresourceRange.levelCount = 1;
    view_create_info.subresourceRange.baseArrayLayer = 0;
    view_create_info.subresourceRange.layerCount = 1;
    view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
    view_create_info.flags = 0;
    view_create_info.image = image;

    vik_log_check(vkCreateImageView(device, &view_create_info, nullptr, view));
  }

  void create_frame_buffer(const VkDevice &device,
                           const VkRenderPass &render_pass, VkImageView *view,
                           uint32_t width, uint32_t height,
                           VkFramebuffer *frame_buffer) {
    VkFramebufferCreateInfo framebufferinfo = {};
    framebufferinfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
    framebufferinfo.renderPass = render_pass;
    framebufferinfo.attachmentCount = 1;
    framebufferinfo.pAttachments = view;
    framebufferinfo.width = width;
    framebufferinfo.height = height;
    framebufferinfo.layers = 1;

    vkCreateFramebuffer(device,
                        &framebufferinfo,
                        NULL,
                        frame_buffer);
  }

};
}