-
Notifications
You must be signed in to change notification settings - Fork 28
/
Ch10FixedFunctions.diff
117 lines (107 loc) · 5.7 KB
/
Ch10FixedFunctions.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
diff --git "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch09ShaderModules.java" "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch10FixedFunctions.java"
index bbc4d8f..8660672 100644
--- "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch09ShaderModules.java"
+++ "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch10FixedFunctions.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 Ch09ShaderModules {
+public class Ch10FixedFunctions {
private static class HelloTriangleApplication {
@@ -129,6 +129,8 @@ public class Ch09ShaderModules {
private int swapChainImageFormat;
private VkExtent2D swapChainExtent;
+ private long pipelineLayout;
+
// ======= METHODS ======= //
public void run() {
@@ -177,6 +179,8 @@ public class Ch09ShaderModules {
private void cleanup() {
+ vkDestroyPipelineLayout(device, pipelineLayout, null);
+
swapChainImageViews.forEach(imageView -> vkDestroyImageView(device, imageView, null));
vkDestroySwapchainKHR(device, swapChain, null);
@@ -504,6 +508,85 @@ public class Ch09ShaderModules {
fragShaderStageInfo.module(fragShaderModule);
fragShaderStageInfo.pName(entryPoint);
+ // ===> VERTEX STAGE <===
+
+ VkPipelineVertexInputStateCreateInfo vertexInputInfo = VkPipelineVertexInputStateCreateInfo.calloc(stack);
+ vertexInputInfo.sType(VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO);
+
+ // ===> ASSEMBLY STAGE <===
+
+ VkPipelineInputAssemblyStateCreateInfo inputAssembly = VkPipelineInputAssemblyStateCreateInfo.calloc(stack);
+ inputAssembly.sType(VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO);
+ inputAssembly.topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
+ inputAssembly.primitiveRestartEnable(false);
+
+ // ===> VIEWPORT & SCISSOR
+
+ VkViewport.Buffer viewport = VkViewport.calloc(1, stack);
+ viewport.x(0.0f);
+ viewport.y(0.0f);
+ viewport.width(swapChainExtent.width());
+ viewport.height(swapChainExtent.height());
+ viewport.minDepth(0.0f);
+ viewport.maxDepth(1.0f);
+
+ VkRect2D.Buffer scissor = VkRect2D.calloc(1, stack);
+ scissor.offset(VkOffset2D.calloc(stack).set(0, 0));
+ scissor.extent(swapChainExtent);
+
+ VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.calloc(stack);
+ viewportState.sType(VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO);
+ viewportState.pViewports(viewport);
+ viewportState.pScissors(scissor);
+
+ // ===> RASTERIZATION STAGE <===
+
+ VkPipelineRasterizationStateCreateInfo rasterizer = VkPipelineRasterizationStateCreateInfo.calloc(stack);
+ rasterizer.sType(VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO);
+ rasterizer.depthClampEnable(false);
+ rasterizer.rasterizerDiscardEnable(false);
+ rasterizer.polygonMode(VK_POLYGON_MODE_FILL);
+ rasterizer.lineWidth(1.0f);
+ rasterizer.cullMode(VK_CULL_MODE_BACK_BIT);
+ rasterizer.frontFace(VK_FRONT_FACE_CLOCKWISE);
+ rasterizer.depthBiasEnable(false);
+
+ // ===> MULTISAMPLING <===
+
+ VkPipelineMultisampleStateCreateInfo multisampling = VkPipelineMultisampleStateCreateInfo.calloc(stack);
+ multisampling.sType(VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO);
+ multisampling.sampleShadingEnable(false);
+ multisampling.rasterizationSamples(VK_SAMPLE_COUNT_1_BIT);
+
+ // ===> COLOR BLENDING <===
+
+ VkPipelineColorBlendAttachmentState.Buffer colorBlendAttachment = VkPipelineColorBlendAttachmentState.calloc(1, stack);
+ colorBlendAttachment.colorWriteMask(VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT);
+ colorBlendAttachment.blendEnable(false);
+
+ VkPipelineColorBlendStateCreateInfo colorBlending = VkPipelineColorBlendStateCreateInfo.calloc(stack);
+ colorBlending.sType(VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO);
+ colorBlending.logicOpEnable(false);
+ colorBlending.logicOp(VK_LOGIC_OP_COPY);
+ colorBlending.pAttachments(colorBlendAttachment);
+ colorBlending.blendConstants(stack.floats(0.0f, 0.0f, 0.0f, 0.0f));
+
+ // ===> PIPELINE LAYOUT CREATION <===
+
+ VkPipelineLayoutCreateInfo pipelineLayoutInfo = VkPipelineLayoutCreateInfo.calloc(stack);
+ pipelineLayoutInfo.sType(VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO);
+
+ LongBuffer pPipelineLayout = stack.longs(VK_NULL_HANDLE);
+
+ if(vkCreatePipelineLayout(device, pipelineLayoutInfo, null, pPipelineLayout) != VK_SUCCESS) {
+ throw new RuntimeException("Failed to create pipeline layout");
+ }
+
+ pipelineLayout = pPipelineLayout.get(0);
+
+
+ // ===> RELEASE RESOURCES <===
+
vkDestroyShaderModule(device, vertShaderModule, null);
vkDestroyShaderModule(device, fragShaderModule, null);