-
Notifications
You must be signed in to change notification settings - Fork 28
/
Ch07ImageViews.diff
83 lines (73 loc) · 3.47 KB
/
Ch07ImageViews.diff
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
diff --git "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch06SwapChainCreation.java" "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch07ImageViews.java"
index 149ef45..769cc3d 100644
--- "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch06SwapChainCreation.java"
+++ "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch07ImageViews.java"
@@ -23,7 +23,7 @@ import static org.lwjgl.vulkan.KHRSurface.*;
import static org.lwjgl.vulkan.KHRSwapchain.*;
import static org.lwjgl.vulkan.VK10.*;
-public class Ch06SwapChainCreation {
+public class Ch07ImageViews {
private static class HelloTriangleApplication {
@@ -120,6 +120,7 @@ public class Ch06SwapChainCreation {
private long swapChain;
private List<Long> swapChainImages;
+ private List<Long> swapChainImageViews;
private int swapChainImageFormat;
private VkExtent2D swapChainExtent;
@@ -157,6 +158,7 @@ public class Ch06SwapChainCreation {
pickPhysicalDevice();
createLogicalDevice();
createSwapChain();
+ createImageViews();
}
private void mainLoop() {
@@ -169,6 +171,8 @@ public class Ch06SwapChainCreation {
private void cleanup() {
+ swapChainImageViews.forEach(imageView -> vkDestroyImageView(device, imageView, null));
+
vkDestroySwapchainKHR(device, swapChain, null);
vkDestroyDevice(device, null);
@@ -426,6 +430,44 @@ public class Ch06SwapChainCreation {
}
}
+ private void createImageViews() {
+
+ swapChainImageViews = new ArrayList<>(swapChainImages.size());
+
+ try(MemoryStack stack = stackPush()) {
+
+ LongBuffer pImageView = stack.mallocLong(1);
+
+ for(long swapChainImage : swapChainImages) {
+
+ VkImageViewCreateInfo createInfo = VkImageViewCreateInfo.calloc(stack);
+
+ createInfo.sType(VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO);
+ createInfo.image(swapChainImage);
+ createInfo.viewType(VK_IMAGE_VIEW_TYPE_2D);
+ createInfo.format(swapChainImageFormat);
+
+ createInfo.components().r(VK_COMPONENT_SWIZZLE_IDENTITY);
+ createInfo.components().g(VK_COMPONENT_SWIZZLE_IDENTITY);
+ createInfo.components().b(VK_COMPONENT_SWIZZLE_IDENTITY);
+ createInfo.components().a(VK_COMPONENT_SWIZZLE_IDENTITY);
+
+ createInfo.subresourceRange().aspectMask(VK_IMAGE_ASPECT_COLOR_BIT);
+ createInfo.subresourceRange().baseMipLevel(0);
+ createInfo.subresourceRange().levelCount(1);
+ createInfo.subresourceRange().baseArrayLayer(0);
+ createInfo.subresourceRange().layerCount(1);
+
+ if (vkCreateImageView(device, createInfo, null, pImageView) != VK_SUCCESS) {
+ throw new RuntimeException("Failed to create image views");
+ }
+
+ swapChainImageViews.add(pImageView.get(0));
+ }
+
+ }
+ }
+
private VkSurfaceFormatKHR chooseSwapSurfaceFormat(VkSurfaceFormatKHR.Buffer availableFormats) {
return availableFormats.stream()
.filter(availableFormat -> availableFormat.format() == VK_FORMAT_B8G8R8_UNORM)