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

Skip to content

Commit 32b7278

Browse files
committed
Fix mip dimension calculation
1 parent 07086a8 commit 32b7278

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

09_Generating_Mipmaps.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ This barrier transitions mip level `i - 1` to `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_
197197
198198
```c++
199199
...
200-
mipWidth /= 2;
201-
mipHeight /= 2;
200+
if (mipWidth > 1) mipWidth /= 2;
201+
if (mipHeight > 1) mipHeight /= 2;
202202
}
203203
```
204204

205-
At the end of the loop, we divide the current mip dimensions by two.
205+
At the end of the loop, we divide the current mip dimensions by two. We check each dimension before the division to ensure that dimension never becomes 0. This handles cases where the image is not square, since one of the mip dimensions would reach 1 before the other dimension. When this happens, that dimension should remain 1 for all remaining levels.
206206

207207
```c++
208208

code/28_mipmapping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,8 @@ class HelloTriangleApplication {
880880
0, nullptr,
881881
1, &barrier);
882882

883-
mipWidth /= 2;
884-
mipHeight /= 2;
883+
if (mipWidth > 1) mipWidth /= 2;
884+
if (mipHeight > 1) mipHeight /= 2;
885885
}
886886

887887
barrier.subresourceRange.baseMipLevel = mipLevels - 1;

0 commit comments

Comments
 (0)