-
Notifications
You must be signed in to change notification settings - Fork 28
/
Ch11RenderPasses.diff
83 lines (72 loc) · 3.64 KB
/
Ch11RenderPasses.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\\Ch10FixedFunctions.java" "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch11RenderPasses.java"
index 8660672..216e0f1 100644
--- "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch10FixedFunctions.java"
+++ "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch11RenderPasses.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 Ch10FixedFunctions {
+public class Ch11RenderPasses {
private static class HelloTriangleApplication {
@@ -129,6 +129,7 @@ public class Ch10FixedFunctions {
private int swapChainImageFormat;
private VkExtent2D swapChainExtent;
+ private long renderPass;
private long pipelineLayout;
// ======= METHODS ======= //
@@ -166,6 +167,7 @@ public class Ch10FixedFunctions {
createLogicalDevice();
createSwapChain();
createImageViews();
+ createRenderPass();
createGraphicsPipeline();
}
@@ -181,6 +183,8 @@ public class Ch10FixedFunctions {
vkDestroyPipelineLayout(device, pipelineLayout, null);
+ vkDestroyRenderPass(device, renderPass, null);
+
swapChainImageViews.forEach(imageView -> vkDestroyImageView(device, imageView, null));
vkDestroySwapchainKHR(device, swapChain, null);
@@ -478,6 +482,44 @@ public class Ch10FixedFunctions {
}
}
+ private void createRenderPass() {
+
+ try(MemoryStack stack = stackPush()) {
+
+ VkAttachmentDescription.Buffer colorAttachment = VkAttachmentDescription.calloc(1, stack);
+ colorAttachment.format(swapChainImageFormat);
+ colorAttachment.samples(VK_SAMPLE_COUNT_1_BIT);
+ colorAttachment.loadOp(VK_ATTACHMENT_LOAD_OP_CLEAR);
+ colorAttachment.storeOp(VK_ATTACHMENT_STORE_OP_STORE);
+ colorAttachment.stencilLoadOp(VK_ATTACHMENT_LOAD_OP_DONT_CARE);
+ colorAttachment.stencilStoreOp(VK_ATTACHMENT_STORE_OP_DONT_CARE);
+ colorAttachment.initialLayout(VK_IMAGE_LAYOUT_UNDEFINED);
+ colorAttachment.finalLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
+
+ VkAttachmentReference.Buffer colorAttachmentRef = VkAttachmentReference.calloc(1, stack);
+ colorAttachmentRef.attachment(0);
+ colorAttachmentRef.layout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
+
+ VkSubpassDescription.Buffer subpass = VkSubpassDescription.calloc(1, stack);
+ subpass.pipelineBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
+ subpass.colorAttachmentCount(1);
+ subpass.pColorAttachments(colorAttachmentRef);
+
+ VkRenderPassCreateInfo renderPassInfo = VkRenderPassCreateInfo.calloc(stack);
+ renderPassInfo.sType(VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
+ renderPassInfo.pAttachments(colorAttachment);
+ renderPassInfo.pSubpasses(subpass);
+
+ LongBuffer pRenderPass = stack.mallocLong(1);
+
+ if(vkCreateRenderPass(device, renderPassInfo, null, pRenderPass) != VK_SUCCESS) {
+ throw new RuntimeException("Failed to create render pass");
+ }
+
+ renderPass = pRenderPass.get(0);
+ }
+ }
+
private void createGraphicsPipeline() {
try(MemoryStack stack = stackPush()) {