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

Skip to content

Commit f6648d7

Browse files
committed
Add change to transitionImageLayout
1 parent 5f58334 commit f6648d7

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

09_Generating_Mipmaps.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(texWidth, texHei
3030

3131
This calculates the number of levels in the mip chain. The `max` function selects the largest dimension. The `log2` function calculates how many times that dimension can be divided by 2. The `floor` function handles cases where the largest dimension is not a power of 2. `1` is added so that the original image has a mip level.
3232

33-
To use this value, we need to change the `createImage` and `createImageView` functions to allow us to specify the number of mip levels. Add a `mipLevels` parameter to the functions:
33+
To use this value, we need to change the `createImage`, `createImageView`, and 'transitionImageLayout` functions to allow us to specify the number of mip levels. Add a `mipLevels` parameter to the functions:
3434

3535
```c++
3636
void createImage(uint32_t width, uint32_t height, uint32_t mipLevels, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
@@ -45,6 +45,12 @@ VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags a
4545
viewInfo.subresourceRange.levelCount = mipLevels;
4646
...
4747
```
48+
```c++
49+
void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels) {
50+
...
51+
barrier.subresourceRange.levelCount = mipLevels;
52+
...
53+
```
4854
4955
Update all calls to these functions to use the right values:
5056
@@ -60,6 +66,11 @@ depthImageView = createImageView(depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_
6066
...
6167
textureImageView = createImageView(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT, mipLevels);
6268
```
69+
```c++
70+
transitionImageLayout(depthImage, depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1);
71+
...
72+
transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, mipLevels);
73+
```
6374
6475
6576

0 commit comments

Comments
 (0)