-
Notifications
You must be signed in to change notification settings - Fork 27
/
Ch13Framebuffers.diff
81 lines (70 loc) · 3.3 KB
/
Ch13Framebuffers.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
diff --git "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch12GraphicsPipelineComplete.java" "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch13Framebuffers.java"
index b836f3e..a12bf81 100644
--- "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch12GraphicsPipelineComplete.java"
+++ "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch13Framebuffers.java"
@@ -28,7 +28,7 @@ import static org.lwjgl.vulkan.KHRSurface.*;
import static org.lwjgl.vulkan.KHRSwapchain.*;
import static org.lwjgl.vulkan.VK10.*;
-public class Ch12GraphicsPipelineComplete {
+public class Ch13Framebuffers {
private static class HelloTriangleApplication {
@@ -125,9 +125,10 @@ public class Ch12GraphicsPipelineComplete {
private long swapChain;
private List<Long> swapChainImages;
- private List<Long> swapChainImageViews;
private int swapChainImageFormat;
private VkExtent2D swapChainExtent;
+ private List<Long> swapChainImageViews;
+ private List<Long> swapChainFramebuffers;
private long renderPass;
private long pipelineLayout;
@@ -170,6 +171,7 @@ public class Ch12GraphicsPipelineComplete {
createImageViews();
createRenderPass();
createGraphicsPipeline();
+ createFramebuffers();
}
private void mainLoop() {
@@ -182,6 +184,8 @@ public class Ch12GraphicsPipelineComplete {
private void cleanup() {
+ swapChainFramebuffers.forEach(framebuffer -> vkDestroyFramebuffer(device, framebuffer, null));
+
vkDestroyPipeline(device, graphicsPipeline, null);
vkDestroyPipelineLayout(device, pipelineLayout, null);
@@ -662,6 +666,38 @@ public class Ch12GraphicsPipelineComplete {
}
}
+ private void createFramebuffers() {
+
+ swapChainFramebuffers = new ArrayList<>(swapChainImageViews.size());
+
+ try(MemoryStack stack = stackPush()) {
+
+ LongBuffer attachments = stack.mallocLong(1);
+ LongBuffer pFramebuffer = stack.mallocLong(1);
+
+ // Lets allocate the create info struct once and just update the pAttachments field each iteration
+ VkFramebufferCreateInfo framebufferInfo = VkFramebufferCreateInfo.calloc(stack);
+ framebufferInfo.sType(VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
+ framebufferInfo.renderPass(renderPass);
+ framebufferInfo.width(swapChainExtent.width());
+ framebufferInfo.height(swapChainExtent.height());
+ framebufferInfo.layers(1);
+
+ for(long imageView : swapChainImageViews) {
+
+ attachments.put(0, imageView);
+
+ framebufferInfo.pAttachments(attachments);
+
+ if(vkCreateFramebuffer(device, framebufferInfo, null, pFramebuffer) != VK_SUCCESS) {
+ throw new RuntimeException("Failed to create framebuffer");
+ }
+
+ swapChainFramebuffers.add(pFramebuffer.get(0));
+ }
+ }
+ }
+
private long createShaderModule(ByteBuffer spirvCode) {
try(MemoryStack stack = stackPush()) {