-
Notifications
You must be signed in to change notification settings - Fork 28
/
Ch26DepthBuffering.diff
423 lines (368 loc) · 21.1 KB
/
Ch26DepthBuffering.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
diff --git "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch25TextureMapping.java" "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch26DepthBuffering.java"
index faac5b9..5e5873b 100644
--- "a/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch25TextureMapping.java"
+++ "b/G:\\Java-Dev\\Vulkan-Tutorial-Java\\src\\main\\java\\javavulkantutorial\\Ch26DepthBuffering.java"
@@ -38,7 +38,7 @@ import static org.lwjgl.vulkan.KHRSurface.*;
import static org.lwjgl.vulkan.KHRSwapchain.*;
import static org.lwjgl.vulkan.VK10.*;
-public class Ch25TextureMapping {
+public class Ch26DepthBuffering {
private static class HelloTriangleApplication {
@@ -139,16 +139,16 @@ public class Ch25TextureMapping {
private static class Vertex {
- private static final int SIZEOF = (2 + 3 + 2) * Float.BYTES;
+ private static final int SIZEOF = (3 + 3 + 2) * Float.BYTES;
private static final int OFFSETOF_POS = 0;
- private static final int OFFSETOF_COLOR = 2 * Float.BYTES;
- private static final int OFFSETOF_TEXTCOORDS = 5 * Float.BYTES;
+ private static final int OFFSETOF_COLOR = 3 * Float.BYTES;
+ private static final int OFFSETOF_TEXTCOORDS = (3 + 3) * Float.BYTES;
- private Vector2fc pos;
+ private Vector3fc pos;
private Vector3fc color;
private Vector2fc texCoords;
- public Vertex(Vector2fc pos, Vector3fc color, Vector2fc texCoords) {
+ public Vertex(Vector3fc pos, Vector3fc color, Vector2fc texCoords) {
this.pos = pos;
this.color = color;
this.texCoords = texCoords;
@@ -175,7 +175,7 @@ public class Ch25TextureMapping {
VkVertexInputAttributeDescription posDescription = attributeDescriptions.get(0);
posDescription.binding(0);
posDescription.location(0);
- posDescription.format(VK_FORMAT_R32G32_SFLOAT);
+ posDescription.format(VK_FORMAT_R32G32B32_SFLOAT);
posDescription.offset(OFFSETOF_POS);
// Color
@@ -198,14 +198,20 @@ public class Ch25TextureMapping {
}
private static final Vertex[] VERTICES = {
- new Vertex(new Vector2f(-0.5f, -0.5f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector2f(1.0f, 0.0f)),
- new Vertex(new Vector2f(0.5f, -0.5f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector2f(0.0f, 0.0f)),
- new Vertex(new Vector2f(0.5f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector2f(0.0f, 1.0f)),
- new Vertex(new Vector2f(-0.5f, 0.5f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector2f(1.0f, 1.0f))
+ new Vertex(new Vector3f(-0.5f, -0.5f, 0.0f ), new Vector3f(1.0f, 0.0f, 0.0f), new Vector2f(0.0f, 0.0f)),
+ new Vertex(new Vector3f(0.5f, -0.5f, 0.0f ), new Vector3f(0.0f, 1.0f, 0.0f), new Vector2f(1.0f, 0.0f)),
+ new Vertex(new Vector3f(0.5f, 0.5f, 0.0f ), new Vector3f(0.0f, 0.0f, 1.0f), new Vector2f(1.0f, 1.0f)),
+ new Vertex(new Vector3f(-0.5f, 0.5f, 0.0f ), new Vector3f(1.0f, 1.0f, 1.0f), new Vector2f(0.0f, 1.0f)),
+
+ new Vertex(new Vector3f(-0.5f, -0.5f, -0.5f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector2f(0.0f, 0.0f)),
+ new Vertex(new Vector3f(0.5f, -0.5f, -0.5f ), new Vector3f(0.0f, 1.0f, 0.0f), new Vector2f(1.0f, 0.0f)),
+ new Vertex(new Vector3f(0.5f, 0.5f, -0.5f ), new Vector3f(0.0f, 0.0f, 1.0f), new Vector2f(1.0f, 1.0f)),
+ new Vertex(new Vector3f(-0.5f, 0.5f, -0.5f ), new Vector3f(1.0f, 1.0f, 1.0f), new Vector2f(0.0f, 1.0f))
};
private static final /*uint16_t*/ short[] INDICES = {
- 0, 1, 2, 2, 3, 0
+ 0, 1, 2, 2, 3, 0,
+ 4, 5, 6, 6, 7, 4
};
// ======= FIELDS ======= //
@@ -238,6 +244,10 @@ public class Ch25TextureMapping {
private long commandPool;
+ private long depthImage;
+ private long depthImageMemory;
+ private long depthImageView;
+
private long textureImage;
private long textureImageMemory;
private long textureImageView;
@@ -329,6 +339,10 @@ public class Ch25TextureMapping {
private void cleanupSwapChain() {
+ vkDestroyImageView(device, depthImageView, null);
+ vkDestroyImage(device, depthImage, null);
+ vkFreeMemory(device, depthImageMemory, null);
+
uniformBuffers.forEach(ubo -> vkDestroyBuffer(device, ubo, null));
uniformBuffersMemory.forEach(uboMemory -> vkFreeMemory(device, uboMemory, null));
@@ -416,6 +430,7 @@ public class Ch25TextureMapping {
createImageViews();
createRenderPass();
createGraphicsPipeline();
+ createDepthResources();
createFramebuffers();
createUniformBuffers();
createDescriptorPool();
@@ -669,7 +684,7 @@ public class Ch25TextureMapping {
swapChainImageViews = new ArrayList<>(swapChainImages.size());
for(long swapChainImage : swapChainImages) {
- swapChainImageViews.add(createImageView(swapChainImage, swapChainImageFormat));
+ swapChainImageViews.add(createImageView(swapChainImage, swapChainImageFormat, VK_IMAGE_ASPECT_COLOR_BIT));
}
}
@@ -677,7 +692,12 @@ public class Ch25TextureMapping {
try(MemoryStack stack = stackPush()) {
- VkAttachmentDescription.Buffer colorAttachment = VkAttachmentDescription.calloc(1, stack);
+ VkAttachmentDescription.Buffer attachments = VkAttachmentDescription.calloc(2, stack);
+ VkAttachmentReference.Buffer attachmentRefs = VkAttachmentReference.calloc(2, stack);
+
+ // Color attachments
+
+ VkAttachmentDescription colorAttachment = attachments.get(0);
colorAttachment.format(swapChainImageFormat);
colorAttachment.samples(VK_SAMPLE_COUNT_1_BIT);
colorAttachment.loadOp(VK_ATTACHMENT_LOAD_OP_CLEAR);
@@ -687,14 +707,33 @@ public class Ch25TextureMapping {
colorAttachment.initialLayout(VK_IMAGE_LAYOUT_UNDEFINED);
colorAttachment.finalLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
- VkAttachmentReference.Buffer colorAttachmentRef = VkAttachmentReference.calloc(1, stack);
+ int y = attachments.get(0).samples();
+
+ VkAttachmentReference colorAttachmentRef = attachmentRefs.get(0);
colorAttachmentRef.attachment(0);
colorAttachmentRef.layout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
+ // Depth-Stencil attachments
+
+ VkAttachmentDescription depthAttachment = attachments.get(1);
+ depthAttachment.format(findDepthFormat());
+ depthAttachment.samples(VK_SAMPLE_COUNT_1_BIT);
+ depthAttachment.loadOp(VK_ATTACHMENT_LOAD_OP_CLEAR);
+ depthAttachment.storeOp(VK_ATTACHMENT_STORE_OP_DONT_CARE);
+ depthAttachment.stencilLoadOp(VK_ATTACHMENT_LOAD_OP_DONT_CARE);
+ depthAttachment.stencilStoreOp(VK_ATTACHMENT_STORE_OP_DONT_CARE);
+ depthAttachment.initialLayout(VK_IMAGE_LAYOUT_UNDEFINED);
+ depthAttachment.finalLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
+
+ VkAttachmentReference depthAttachmentRef = attachmentRefs.get(1);
+ depthAttachmentRef.attachment(1);
+ depthAttachmentRef.layout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
+
VkSubpassDescription.Buffer subpass = VkSubpassDescription.calloc(1, stack);
subpass.pipelineBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
subpass.colorAttachmentCount(1);
- subpass.pColorAttachments(colorAttachmentRef);
+ subpass.pColorAttachments(VkAttachmentReference.calloc(1, stack).put(0, colorAttachmentRef));
+ subpass.pDepthStencilAttachment(depthAttachmentRef);
VkSubpassDependency.Buffer dependency = VkSubpassDependency.calloc(1, stack);
dependency.srcSubpass(VK_SUBPASS_EXTERNAL);
@@ -706,7 +745,7 @@ public class Ch25TextureMapping {
VkRenderPassCreateInfo renderPassInfo = VkRenderPassCreateInfo.calloc(stack);
renderPassInfo.sType(VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
- renderPassInfo.pAttachments(colorAttachment);
+ renderPassInfo.pAttachments(attachments);
renderPassInfo.pSubpasses(subpass);
renderPassInfo.pDependencies(dependency);
@@ -759,8 +798,8 @@ public class Ch25TextureMapping {
// Let's compile the GLSL shaders into SPIR-V at runtime using the shaderc library
// Check ShaderSPIRVUtils class to see how it can be done
- SPIRV vertShaderSPIRV = compileShaderFile("shaders/25_shader_textures.vert", VERTEX_SHADER);
- SPIRV fragShaderSPIRV = compileShaderFile("shaders/25_shader_textures.frag", FRAGMENT_SHADER);
+ SPIRV vertShaderSPIRV = compileShaderFile("shaders/26_shader_depth.vert", VERTEX_SHADER);
+ SPIRV fragShaderSPIRV = compileShaderFile("shaders/26_shader_depth.frag", FRAGMENT_SHADER);
long vertShaderModule = createShaderModule(vertShaderSPIRV.bytecode());
long fragShaderModule = createShaderModule(fragShaderSPIRV.bytecode());
@@ -835,6 +874,16 @@ public class Ch25TextureMapping {
multisampling.sampleShadingEnable(false);
multisampling.rasterizationSamples(VK_SAMPLE_COUNT_1_BIT);
+ VkPipelineDepthStencilStateCreateInfo depthStencil = VkPipelineDepthStencilStateCreateInfo.calloc(stack);
+ depthStencil.sType(VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO);
+ depthStencil.depthTestEnable(true);
+ depthStencil.depthWriteEnable(true);
+ depthStencil.depthCompareOp(VK_COMPARE_OP_LESS);
+ depthStencil.depthBoundsTestEnable(false);
+ depthStencil.minDepthBounds(0.0f); // Optional
+ depthStencil.maxDepthBounds(1.0f); // Optional
+ depthStencil.stencilTestEnable(false);
+
// ===> COLOR BLENDING <===
VkPipelineColorBlendAttachmentState.Buffer colorBlendAttachment = VkPipelineColorBlendAttachmentState.calloc(1, stack);
@@ -870,6 +919,7 @@ public class Ch25TextureMapping {
pipelineInfo.pViewportState(viewportState);
pipelineInfo.pRasterizationState(rasterizer);
pipelineInfo.pMultisampleState(multisampling);
+ pipelineInfo.pDepthStencilState(depthStencil);
pipelineInfo.pColorBlendState(colorBlending);
pipelineInfo.layout(pipelineLayout);
pipelineInfo.renderPass(renderPass);
@@ -901,7 +951,7 @@ public class Ch25TextureMapping {
try(MemoryStack stack = stackPush()) {
- LongBuffer attachments = stack.mallocLong(1);
+ LongBuffer attachments = stack.longs(VK_NULL_HANDLE, depthImageView);
LongBuffer pFramebuffer = stack.mallocLong(1);
// Lets allocate the create info struct once and just update the pAttachments field each iteration
@@ -947,6 +997,72 @@ public class Ch25TextureMapping {
}
}
+ private void createDepthResources() {
+
+ try(MemoryStack stack = stackPush()) {
+
+ int depthFormat = findDepthFormat();
+
+ LongBuffer pDepthImage = stack.mallocLong(1);
+ LongBuffer pDepthImageMemory = stack.mallocLong(1);
+
+ createImage(
+ swapChainExtent.width(), swapChainExtent.height(),
+ depthFormat,
+ VK_IMAGE_TILING_OPTIMAL,
+ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ pDepthImage,
+ pDepthImageMemory);
+
+ depthImage = pDepthImage.get(0);
+ depthImageMemory = pDepthImageMemory.get(0);
+
+ depthImageView = createImageView(depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT);
+
+ // Explicitly transitioning the depth image
+ transitionImageLayout(depthImage, depthFormat,
+ VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
+
+ }
+ }
+
+ private int findSupportedFormat(IntBuffer formatCandidates, int tiling, int features) {
+
+ try(MemoryStack stack = stackPush()) {
+
+ VkFormatProperties props = VkFormatProperties.calloc(stack);
+
+ for(int i = 0; i < formatCandidates.capacity(); ++i) {
+
+ int format = formatCandidates.get(i);
+
+ vkGetPhysicalDeviceFormatProperties(physicalDevice, format, props);
+
+ if(tiling == VK_IMAGE_TILING_LINEAR && (props.linearTilingFeatures() & features) == features) {
+ return format;
+ } else if(tiling == VK_IMAGE_TILING_OPTIMAL && (props.optimalTilingFeatures() & features) == features) {
+ return format;
+ }
+
+ }
+ }
+
+ throw new RuntimeException("Failed to find supported format");
+ }
+
+
+ private int findDepthFormat() {
+ return findSupportedFormat(
+ stackGet().ints(VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT),
+ VK_IMAGE_TILING_OPTIMAL,
+ VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
+ }
+
+ private boolean hasStencilComponent(int format) {
+ return format == VK_FORMAT_D32_SFLOAT_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT;
+ }
+
private void createTextureImage() {
try(MemoryStack stack = stackPush()) {
@@ -1016,7 +1132,7 @@ public class Ch25TextureMapping {
}
private void createTextureImageView() {
- textureImageView = createImageView(textureImage, VK_FORMAT_R8G8B8A8_SRGB);
+ textureImageView = createImageView(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_ASPECT_COLOR_BIT);
}
private void createTextureSampler() {
@@ -1048,7 +1164,7 @@ public class Ch25TextureMapping {
}
}
- private long createImageView(long image, int format) {
+ private long createImageView(long image, int format, int aspectFlags) {
try(MemoryStack stack = stackPush()) {
@@ -1057,7 +1173,7 @@ public class Ch25TextureMapping {
viewInfo.image(image);
viewInfo.viewType(VK_IMAGE_VIEW_TYPE_2D);
viewInfo.format(format);
- viewInfo.subresourceRange().aspectMask(VK_IMAGE_ASPECT_COLOR_BIT);
+ viewInfo.subresourceRange().aspectMask(aspectFlags);
viewInfo.subresourceRange().baseMipLevel(0);
viewInfo.subresourceRange().levelCount(1);
viewInfo.subresourceRange().baseArrayLayer(0);
@@ -1124,12 +1240,25 @@ public class Ch25TextureMapping {
barrier.srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED);
barrier.dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED);
barrier.image(image);
- barrier.subresourceRange().aspectMask(VK_IMAGE_ASPECT_COLOR_BIT);
+
barrier.subresourceRange().baseMipLevel(0);
barrier.subresourceRange().levelCount(1);
barrier.subresourceRange().baseArrayLayer(0);
barrier.subresourceRange().layerCount(1);
+ if(newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
+
+ barrier.subresourceRange().aspectMask(VK_IMAGE_ASPECT_DEPTH_BIT);
+
+ if(hasStencilComponent(format)) {
+ barrier.subresourceRange().aspectMask(
+ barrier.subresourceRange().aspectMask() | VK_IMAGE_ASPECT_STENCIL_BIT);
+ }
+
+ } else {
+ barrier.subresourceRange().aspectMask(VK_IMAGE_ASPECT_COLOR_BIT);
+ }
+
int sourceStage;
int destinationStage;
@@ -1149,6 +1278,14 @@ public class Ch25TextureMapping {
sourceStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
destinationStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
+ } else if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
+
+ barrier.srcAccessMask(0);
+ barrier.dstAccessMask(VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
+
+ sourceStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
+ destinationStage = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
+
} else {
throw new IllegalArgumentException("Unsupported layout transition");
}
@@ -1306,7 +1443,7 @@ public class Ch25TextureMapping {
try(MemoryStack stack = stackPush()) {
- VkDescriptorPoolSize.Buffer poolSizes = VkDescriptorPoolSize.calloc(2, stack);
+ VkDescriptorPoolSize.Buffer poolSizes = VkDescriptorPoolSize.callocStack(2, stack);
VkDescriptorPoolSize uniformBufferPoolSize = poolSizes.get(0);
uniformBufferPoolSize.type(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
@@ -1316,7 +1453,7 @@ public class Ch25TextureMapping {
textureSamplerPoolSize.type(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
textureSamplerPoolSize.descriptorCount(swapChainImages.size());
- VkDescriptorPoolCreateInfo poolInfo = VkDescriptorPoolCreateInfo.calloc(stack);
+ VkDescriptorPoolCreateInfo poolInfo = VkDescriptorPoolCreateInfo.callocStack(stack);
poolInfo.sType(VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO);
poolInfo.pPoolSizes(poolSizes);
poolInfo.maxSets(swapChainImages.size());
@@ -1340,7 +1477,7 @@ public class Ch25TextureMapping {
layouts.put(i, descriptorSetLayout);
}
- VkDescriptorSetAllocateInfo allocInfo = VkDescriptorSetAllocateInfo.calloc(stack);
+ VkDescriptorSetAllocateInfo allocInfo = VkDescriptorSetAllocateInfo.callocStack(stack);
allocInfo.sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO);
allocInfo.descriptorPool(descriptorPool);
allocInfo.pSetLayouts(layouts);
@@ -1353,16 +1490,16 @@ public class Ch25TextureMapping {
descriptorSets = new ArrayList<>(pDescriptorSets.capacity());
- VkDescriptorBufferInfo.Buffer bufferInfo = VkDescriptorBufferInfo.calloc(1, stack);
+ VkDescriptorBufferInfo.Buffer bufferInfo = VkDescriptorBufferInfo.callocStack(1, stack);
bufferInfo.offset(0);
bufferInfo.range(UniformBufferObject.SIZEOF);
- VkDescriptorImageInfo.Buffer imageInfo = VkDescriptorImageInfo.calloc(1, stack);
+ VkDescriptorImageInfo.Buffer imageInfo = VkDescriptorImageInfo.callocStack(1, stack);
imageInfo.imageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
imageInfo.imageView(textureImageView);
imageInfo.sampler(textureSampler);
- VkWriteDescriptorSet.Buffer descriptorWrites = VkWriteDescriptorSet.calloc(2, stack);
+ VkWriteDescriptorSet.Buffer descriptorWrites = VkWriteDescriptorSet.callocStack(2, stack);
VkWriteDescriptorSet uboDescriptorWrite = descriptorWrites.get(0);
uboDescriptorWrite.sType(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET);
@@ -1486,6 +1623,7 @@ public class Ch25TextureMapping {
for(Vertex vertex : vertices) {
buffer.putFloat(vertex.pos.x());
buffer.putFloat(vertex.pos.y());
+ buffer.putFloat(vertex.pos.z());
buffer.putFloat(vertex.color.x());
buffer.putFloat(vertex.color.y());
@@ -1565,8 +1703,10 @@ public class Ch25TextureMapping {
renderArea.extent(swapChainExtent);
renderPassInfo.renderArea(renderArea);
- VkClearValue.Buffer clearValues = VkClearValue.callocStack(1, stack);
- clearValues.color().float32(stack.floats(0.0f, 0.0f, 0.0f, 1.0f));
+ VkClearValue.Buffer clearValues = VkClearValue.callocStack(2, stack);
+ clearValues.get(0).color().float32(stack.floats(0.0f, 0.0f, 0.0f, 1.0f));
+ clearValues.get(1).depthStencil().set(1.0f, 0);
+
renderPassInfo.pClearValues(clearValues);
for(int i = 0;i < commandBuffersCount;i++) {