Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a349ff1

Browse files
committed
Remove VDeleter from depth buffer and model loading chapters
1 parent 7216342 commit a349ff1

5 files changed

Lines changed: 392 additions & 363 deletions

File tree

06_Texture_mapping/01_Image_view_and_sampler.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ The `vkGetPhysicalDeviceFeatures` repurposes the `VkPhysicalDeviceFeatures`
341341
struct to indicate which features are supported rather than requested by setting
342342
the boolean values.
343343
344+
Instead of enforcing the availability of anisotropic filtering, it's also
345+
possible to simply not use it by conditionally setting:
346+
347+
```c++
348+
samplerInfo.anisotropyEnable = VK_FALSE;
349+
samplerInfo.maxAnisotropy = 1;
350+
```
351+
344352
In the next chapter we will expose the image and sampler objects to the shaders
345353
to draw the texture onto the square.
346354

07_Depth_buffering.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ running at once. The depth image will again require the trifecta of resources:
130130
image, memory and image view.
131131

132132
```c++
133-
VDeleter<VkImage> depthImage{device, vkDestroyImage};
134-
VDeleter<VkDeviceMemory> depthImageMemory{device, vkFreeMemory};
135-
VDeleter<VkImageView> depthImageView{device, vkDestroyImageView};
133+
VkImage depthImage;
134+
VkDeviceMemory depthImageMemory;
135+
VkImageView depthImageView;
136136
```
137137

138138
Create a new function `createDepthResources` to set up these resources:
@@ -272,15 +272,15 @@ We now have all the required information to invoke our `createImage` and
272272

273273
```c++
274274
createImage(swapChainExtent.width, swapChainExtent.height, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, depthImage, depthImageMemory);
275-
createImageView(depthImage, depthFormat, depthImageView);
275+
depthImageView = createImageView(depthImage, depthFormat);
276276
```
277277
278278
However, the `createImageView` function currently assumes that the subresource
279279
is always the `VK_IMAGE_ASPECT_COLOR_BIT`, so we will need to turn that field
280280
into a parameter:
281281
282282
```c++
283-
void createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, VDeleter<VkImageView>& imageView) {
283+
VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags) {
284284
...
285285
viewInfo.subresourceRange.aspectMask = aspectFlags;
286286
...
@@ -290,11 +290,11 @@ void createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFl
290290
Update all calls to this function to use the right aspect:
291291

292292
```c++
293-
createImageView(swapChainImages[i], swapChainImageFormat, VK_IMAGE_ASPECT_COLOR_BIT, swapChainImageViews[i]);
293+
swapChainImageViews[i] = createImageView(swapChainImages[i], swapChainImageFormat, VK_IMAGE_ASPECT_COLOR_BIT);
294294
...
295-
createImageView(depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, depthImageView);
295+
depthImageView = createImageView(depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT);
296296
...
297-
createImageView(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT, textureImageView);
297+
textureImageView = createImageView(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT);
298298
```
299299

300300
That's it for creating the depth image. We don't need to map it or copy another
@@ -396,7 +396,7 @@ buffers.
396396
std::array<VkAttachmentDescription, 2> attachments = {colorAttachment, depthAttachment};
397397
VkRenderPassCreateInfo renderPassInfo = {};
398398
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
399-
renderPassInfo.attachmentCount = attachments.size();
399+
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
400400
renderPassInfo.pAttachments = attachments.data();
401401
renderPassInfo.subpassCount = 1;
402402
renderPassInfo.pSubpasses = &subpass;
@@ -422,7 +422,7 @@ std::array<VkImageView, 2> attachments = {
422422
VkFramebufferCreateInfo framebufferInfo = {};
423423
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
424424
framebufferInfo.renderPass = renderPass;
425-
framebufferInfo.attachmentCount = attachments.size();
425+
framebufferInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
426426
framebufferInfo.pAttachments = attachments.data();
427427
framebufferInfo.width = swapChainExtent.width;
428428
framebufferInfo.height = swapChainExtent.height;
@@ -456,7 +456,7 @@ std::array<VkClearValue, 2> clearValues = {};
456456
clearValues[0].color = {0.0f, 0.0f, 0.0f, 1.0f};
457457
clearValues[1].depthStencil = {1.0f, 0};
458458

459-
renderPassInfo.clearValueCount = clearValues.size();
459+
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
460460
renderPassInfo.pClearValues = clearValues.data();
461461
```
462462
@@ -548,6 +548,18 @@ void recreateSwapChain() {
548548
}
549549
```
550550

551+
The cleanup operations should happen in the swap chain cleanup function:
552+
553+
```c++
554+
void cleanupSwapChain() {
555+
vkDestroyImageView(device, depthImageView, nullptr);
556+
vkDestroyImage(device, depthImage, nullptr);
557+
vkFreeMemory(device, depthImageMemory, nullptr);
558+
559+
...
560+
}
561+
```
562+
551563
Congratulations, your application is now finally ready to render arbitrary 3D
552564
geometry and have it look right. We're going to try this out in the next chapter
553565
by drawing a textured model!

08_Loading_models.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ non-const containers as class members:
8888
```c++
8989
std::vector<Vertex> vertices;
9090
std::vector<uint32_t> indices;
91-
VDeleter<VkBuffer> vertexBuffer{device, vkDestroyBuffer};
92-
VDeleter<VkDeviceMemory> vertexBufferMemory{device, vkFreeMemory};
91+
VkBuffer vertexBuffer;
92+
VkDeviceMemory vertexBufferMemory;
9393
```
9494

9595
You should change the type of the indices from `uint16_t` to `uint32_t`, because
@@ -249,14 +249,14 @@ Unfortunately we're not really taking advantage of the index buffer yet. The
249249
vertices are included in multiple triangles. We should keep only the unique
250250
vertices and use the index buffer to reuse them whenever they come up. A
251251
straightforward way to implement this is to use a `map` or `unordered_map` to
252-
keep track of the unique vertices and their index:
252+
keep track of the unique vertices and respective indices:
253253

254254
```c++
255255
#include <unordered_map>
256256

257257
...
258258

259-
std::unordered_map<Vertex, int> uniqueVertices = {};
259+
std::unordered_map<Vertex, uint32_t> uniqueVertices = {};
260260

261261
for (const auto& shape : shapes) {
262262
for (const auto& index : shape.mesh.indices) {
@@ -265,7 +265,7 @@ for (const auto& shape : shapes) {
265265
...
266266

267267
if (uniqueVertices.count(vertex) == 0) {
268-
uniqueVertices[vertex] = vertices.size();
268+
uniqueVertices[vertex] = static_cast<uint32_t>(vertices.size());
269269
vertices.push_back(vertex);
270270
}
271271

@@ -336,6 +336,7 @@ like:
336336
* Pipeline cache
337337
* Multi-threaded command buffer generation
338338
* Multiple subpasses
339+
* Compute shaders
339340

340341
The current program can be extended in many ways, like adding Blinn-Phong
341342
lighting, post-processing effects and shadow mapping. You should be able to

0 commit comments

Comments
 (0)