~sircmpwn/xrgears

ref: c4afd33e13398688fc03f60ef3d0a498bf40bfdd xrgears/vkc/vkcSwapChain.hpp -rw-r--r-- 1.5 KiB
c4afd33e — Lubosz Sarnecki add new abstract classes for interfaces between vks and vkc. 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
#pragma once

#include <vulkan/vulkan.h>

#define MAX_NUM_IMAGES 4

namespace vkc {

struct RenderBuffer {
  VkImage image;
  VkImageView view;
  VkFramebuffer framebuffer;
};

class SwapChain {
public:
  RenderBuffer buffers[MAX_NUM_IMAGES];

  SwapChain() {}
  ~SwapChain() {}

  void init_buffer(VkDevice device, VkFormat image_format, VkRenderPass render_pass,
                   uint32_t width, uint32_t height, RenderBuffer *b) {
    VkImageViewCreateInfo imageviewinfo = {
      .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
      .image = b->image,
      .viewType = VK_IMAGE_VIEW_TYPE_2D,
      .format = image_format,
      .components = {
        .r = VK_COMPONENT_SWIZZLE_R,
        .g = VK_COMPONENT_SWIZZLE_G,
        .b = VK_COMPONENT_SWIZZLE_B,
        .a = VK_COMPONENT_SWIZZLE_A,
      },
      .subresourceRange = {
        .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
        .baseMipLevel = 0,
        .levelCount = 1,
        .baseArrayLayer = 0,
        .layerCount = 1,
      },
    };

    vkCreateImageView(device,
                      &imageviewinfo,
                      NULL,
                      &b->view);


    VkFramebufferCreateInfo framebufferinfo = {
      .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
      .renderPass = render_pass,
      .attachmentCount = 1,
      .pAttachments = &b->view,
      .width = width,
      .height = height,
      .layers = 1
    };

    vkCreateFramebuffer(device,
                        &framebufferinfo,
                        NULL,
                        &b->framebuffer);
  }
};
}