Skip to content

Commit 022c46e

Browse files
committed
Code: Use uint32_t for WIDTH and HEIGHT to prevent narrowing conversion
A warning would otherwise be raised from "Swap chain" onward when using GCC 9.3.0: ``` g++ -std=c++17 -o HelloTriangle main.cpp `pkg-config --static --libs glfw3` -lvulkan main.cpp: In member function ‘VkExtent2D HelloTriangleApplication::chooseSwapExtent(const VkSurfaceCapabilitiesKHR&)’: main.cpp:458:40: warning: narrowing conversion of ‘(int)((HelloTriangleApplication*)this)->HelloTriangleApplication::WIDTH’ from ‘int’ to ‘uint32_t’ {aka ‘unsigned int’} [-Wnarrowing] 458 | VkExtent2D actualExtent = {WIDTH, HEIGHT}; | ^~~~~ main.cpp:458:47: warning: narrowing conversion of ‘(int)((HelloTriangleApplication*)this)->HelloTriangleApplication::HEIGHT’ from ‘int’ to ‘uint32_t’ {aka ‘unsigned int’} [-Wnarrowing] 458 | VkExtent2D actualExtent = {WIDTH, HEIGHT}; | ^~~~~~ ```
1 parent 674031b commit 022c46e

36 files changed

+72
-72
lines changed

code/00_base_code.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <stdexcept>
66
#include <cstdlib>
77

8-
const int WIDTH = 800;
9-
const int HEIGHT = 600;
8+
const uint32_t WIDTH = 800;
9+
const uint32_t HEIGHT = 600;
1010

1111
class HelloTriangleApplication {
1212
public:

code/01_instance_creation.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <stdexcept>
66
#include <cstdlib>
77

8-
const int WIDTH = 800;
9-
const int HEIGHT = 600;
8+
const uint32_t WIDTH = 800;
9+
const uint32_t HEIGHT = 600;
1010

1111
class HelloTriangleApplication {
1212
public:

code/02_validation_layers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <cstring>
88
#include <cstdlib>
99

10-
const int WIDTH = 800;
11-
const int HEIGHT = 600;
10+
const uint32_t WIDTH = 800;
11+
const uint32_t HEIGHT = 600;
1212

1313
const std::vector<const char*> validationLayers = {
1414
"VK_LAYER_KHRONOS_validation"

code/03_physical_device_selection.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <cstdlib>
99
#include <optional>
1010

11-
const int WIDTH = 800;
12-
const int HEIGHT = 600;
11+
const uint32_t WIDTH = 800;
12+
const uint32_t HEIGHT = 600;
1313

1414
const std::vector<const char*> validationLayers = {
1515
"VK_LAYER_KHRONOS_validation"

code/04_logical_device.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <cstdlib>
99
#include <optional>
1010

11-
const int WIDTH = 800;
12-
const int HEIGHT = 600;
11+
const uint32_t WIDTH = 800;
12+
const uint32_t HEIGHT = 600;
1313

1414
const std::vector<const char*> validationLayers = {
1515
"VK_LAYER_KHRONOS_validation"

code/05_window_surface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <optional>
1010
#include <set>
1111

12-
const int WIDTH = 800;
13-
const int HEIGHT = 600;
12+
const uint32_t WIDTH = 800;
13+
const uint32_t HEIGHT = 600;
1414

1515
const std::vector<const char*> validationLayers = {
1616
"VK_LAYER_KHRONOS_validation"

code/06_swap_chain_creation.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <optional>
1212
#include <set>
1313

14-
const int WIDTH = 800;
15-
const int HEIGHT = 600;
14+
const uint32_t WIDTH = 800;
15+
const uint32_t HEIGHT = 600;
1616

1717
const std::vector<const char*> validationLayers = {
1818
"VK_LAYER_KHRONOS_validation"

code/07_image_views.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <optional>
1212
#include <set>
1313

14-
const int WIDTH = 800;
15-
const int HEIGHT = 600;
14+
const uint32_t WIDTH = 800;
15+
const uint32_t HEIGHT = 600;
1616

1717
const std::vector<const char*> validationLayers = {
1818
"VK_LAYER_KHRONOS_validation"

code/08_graphics_pipeline.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <optional>
1212
#include <set>
1313

14-
const int WIDTH = 800;
15-
const int HEIGHT = 600;
14+
const uint32_t WIDTH = 800;
15+
const uint32_t HEIGHT = 600;
1616

1717
const std::vector<const char*> validationLayers = {
1818
"VK_LAYER_KHRONOS_validation"

code/09_shader_modules.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <optional>
1313
#include <set>
1414

15-
const int WIDTH = 800;
16-
const int HEIGHT = 600;
15+
const uint32_t WIDTH = 800;
16+
const uint32_t HEIGHT = 600;
1717

1818
const std::vector<const char*> validationLayers = {
1919
"VK_LAYER_KHRONOS_validation"

code/10_fixed_functions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <optional>
1313
#include <set>
1414

15-
const int WIDTH = 800;
16-
const int HEIGHT = 600;
15+
const uint32_t WIDTH = 800;
16+
const uint32_t HEIGHT = 600;
1717

1818
const std::vector<const char*> validationLayers = {
1919
"VK_LAYER_KHRONOS_validation"

code/11_render_passes.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <optional>
1313
#include <set>
1414

15-
const int WIDTH = 800;
16-
const int HEIGHT = 600;
15+
const uint32_t WIDTH = 800;
16+
const uint32_t HEIGHT = 600;
1717

1818
const std::vector<const char*> validationLayers = {
1919
"VK_LAYER_KHRONOS_validation"

code/12_graphics_pipeline_complete.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <optional>
1313
#include <set>
1414

15-
const int WIDTH = 800;
16-
const int HEIGHT = 600;
15+
const uint32_t WIDTH = 800;
16+
const uint32_t HEIGHT = 600;
1717

1818
const std::vector<const char*> validationLayers = {
1919
"VK_LAYER_KHRONOS_validation"

code/13_framebuffers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <optional>
1313
#include <set>
1414

15-
const int WIDTH = 800;
16-
const int HEIGHT = 600;
15+
const uint32_t WIDTH = 800;
16+
const uint32_t HEIGHT = 600;
1717

1818
const std::vector<const char*> validationLayers = {
1919
"VK_LAYER_KHRONOS_validation"

code/14_command_buffers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <optional>
1313
#include <set>
1414

15-
const int WIDTH = 800;
16-
const int HEIGHT = 600;
15+
const uint32_t WIDTH = 800;
16+
const uint32_t HEIGHT = 600;
1717

1818
const std::vector<const char*> validationLayers = {
1919
"VK_LAYER_KHRONOS_validation"

code/15_hello_triangle.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <optional>
1313
#include <set>
1414

15-
const int WIDTH = 800;
16-
const int HEIGHT = 600;
15+
const uint32_t WIDTH = 800;
16+
const uint32_t HEIGHT = 600;
1717

1818
const int MAX_FRAMES_IN_FLIGHT = 2;
1919

code/16_swap_chain_recreation.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <optional>
1313
#include <set>
1414

15-
const int WIDTH = 800;
16-
const int HEIGHT = 600;
15+
const uint32_t WIDTH = 800;
16+
const uint32_t HEIGHT = 600;
1717

1818
const int MAX_FRAMES_IN_FLIGHT = 2;
1919

code/17_vertex_input.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <optional>
1616
#include <set>
1717

18-
const int WIDTH = 800;
19-
const int HEIGHT = 600;
18+
const uint32_t WIDTH = 800;
19+
const uint32_t HEIGHT = 600;
2020

2121
const int MAX_FRAMES_IN_FLIGHT = 2;
2222

code/18_vertex_buffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <optional>
1616
#include <set>
1717

18-
const int WIDTH = 800;
19-
const int HEIGHT = 600;
18+
const uint32_t WIDTH = 800;
19+
const uint32_t HEIGHT = 600;
2020

2121
const int MAX_FRAMES_IN_FLIGHT = 2;
2222

code/19_staging_buffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <optional>
1616
#include <set>
1717

18-
const int WIDTH = 800;
19-
const int HEIGHT = 600;
18+
const uint32_t WIDTH = 800;
19+
const uint32_t HEIGHT = 600;
2020

2121
const int MAX_FRAMES_IN_FLIGHT = 2;
2222

code/20_index_buffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <optional>
1616
#include <set>
1717

18-
const int WIDTH = 800;
19-
const int HEIGHT = 600;
18+
const uint32_t WIDTH = 800;
19+
const uint32_t HEIGHT = 600;
2020

2121
const int MAX_FRAMES_IN_FLIGHT = 2;
2222

code/21_descriptor_layout.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include <optional>
1919
#include <set>
2020

21-
const int WIDTH = 800;
22-
const int HEIGHT = 600;
21+
const uint32_t WIDTH = 800;
22+
const uint32_t HEIGHT = 600;
2323

2424
const int MAX_FRAMES_IN_FLIGHT = 2;
2525

code/22_descriptor_sets.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include <optional>
1919
#include <set>
2020

21-
const int WIDTH = 800;
22-
const int HEIGHT = 600;
21+
const uint32_t WIDTH = 800;
22+
const uint32_t HEIGHT = 600;
2323

2424
const int MAX_FRAMES_IN_FLIGHT = 2;
2525

code/23_texture_image.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <optional>
2222
#include <set>
2323

24-
const int WIDTH = 800;
25-
const int HEIGHT = 600;
24+
const uint32_t WIDTH = 800;
25+
const uint32_t HEIGHT = 600;
2626

2727
const int MAX_FRAMES_IN_FLIGHT = 2;
2828

code/24_sampler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <optional>
2222
#include <set>
2323

24-
const int WIDTH = 800;
25-
const int HEIGHT = 600;
24+
const uint32_t WIDTH = 800;
25+
const uint32_t HEIGHT = 600;
2626

2727
const int MAX_FRAMES_IN_FLIGHT = 2;
2828

code/25_texture_mapping.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <optional>
2222
#include <set>
2323

24-
const int WIDTH = 800;
25-
const int HEIGHT = 600;
24+
const uint32_t WIDTH = 800;
25+
const uint32_t HEIGHT = 600;
2626

2727
const int MAX_FRAMES_IN_FLIGHT = 2;
2828

code/26_depth_buffering.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include <optional>
2323
#include <set>
2424

25-
const int WIDTH = 800;
26-
const int HEIGHT = 600;
25+
const uint32_t WIDTH = 800;
26+
const uint32_t HEIGHT = 600;
2727

2828
const int MAX_FRAMES_IN_FLIGHT = 2;
2929

code/27_model_loading.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include <set>
2929
#include <unordered_map>
3030

31-
const int WIDTH = 800;
32-
const int HEIGHT = 600;
31+
const uint32_t WIDTH = 800;
32+
const uint32_t HEIGHT = 600;
3333

3434
const std::string MODEL_PATH = "models/chalet.obj";
3535
const std::string TEXTURE_PATH = "textures/chalet.jpg";

code/28_mipmapping.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include <set>
2929
#include <unordered_map>
3030

31-
const int WIDTH = 800;
32-
const int HEIGHT = 600;
31+
const uint32_t WIDTH = 800;
32+
const uint32_t HEIGHT = 600;
3333

3434
const std::string MODEL_PATH = "models/chalet.obj";
3535
const std::string TEXTURE_PATH = "textures/chalet.jpg";

code/29_multisampling.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include <set>
2929
#include <unordered_map>
3030

31-
const int WIDTH = 800;
32-
const int HEIGHT = 600;
31+
const uint32_t WIDTH = 800;
32+
const uint32_t HEIGHT = 600;
3333

3434
const std::string MODEL_PATH = "models/chalet.obj";
3535
const std::string TEXTURE_PATH = "textures/chalet.jpg";

en/03_Drawing_a_triangle/00_Setup/00_Base_code.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ because we'll be referring to these values a couple of times in the future. I've
160160
added the following lines above the `HelloTriangleApplication` class definition:
161161

162162
```c++
163-
const int WIDTH = 800;
164-
const int HEIGHT = 600;
163+
const uint32_t WIDTH = 800;
164+
const uint32_t HEIGHT = 600;
165165
```
166166

167167
and replaced the window creation call with

en/03_Drawing_a_triangle/00_Setup/02_Validation_layers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ whether the program is being compiled in debug mode or not. The `NDEBUG` macro
7676
is part of the C++ standard and means "not debug".
7777

7878
```c++
79-
const int WIDTH = 800;
80-
const int HEIGHT = 600;
79+
const uint32_t WIDTH = 800;
80+
const uint32_t HEIGHT = 600;
8181

8282
const std::vector<const char*> validationLayers = {
8383
"VK_LAYER_KHRONOS_validation"

en/08_Loading_models.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Put two new configuration variables in your program to define the model and
6666
texture paths:
6767

6868
```c++
69-
const int WIDTH = 800;
70-
const int HEIGHT = 600;
69+
const uint32_t WIDTH = 800;
70+
const uint32_t HEIGHT = 600;
7171

7272
const std::string MODEL_PATH = "models/chalet.obj";
7373
const std::string TEXTURE_PATH = "textures/chalet.jpg";

fr/03_Dessiner_un_triangle/00_Mise_en_place/00_Code_de_base.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ Nous devrions plutôt utiliser des constantes pour la hauteur et la largeur dans
145145
valeurs dans le futur. J'ai donc ajouté ceci au-dessus de la définition de la classe `HelloTriangleApplication` :
146146

147147
```c++
148-
const int WIDTH = 800;
149-
const int HEIGHT = 600;
148+
const uint32_t WIDTH = 800;
149+
const uint32_t HEIGHT = 600;
150150
```
151151

152152
et remplacé la création de la fenêtre par :

fr/03_Dessiner_un_triangle/00_Mise_en_place/02_Validation_layers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ choisi d'effectuer ce choix selon si le programme est compilé en mode debug ou
6464
du standard c++ et correspond au second cas.
6565

6666
```c++
67-
const int WIDTH = 800;
68-
const int HEIGHT = 600;
67+
const uint32_t WIDTH = 800;
68+
const uint32_t HEIGHT = 600;
6969

7070
const std::vector<const char*> validationLayers = {
7171
"VK_LAYER_KHRONOS_validation"

fr/08_Charger_des_modèles.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ dossier appelé `models`, et placez l'image dans le dossier `textures`.
5555
Ajoutez deux variables de configuration pour la localisation du modèle et de la texture :
5656

5757
```c++
58-
const int WIDTH = 800;
59-
const int HEIGHT = 600;
58+
const uint32_t WIDTH = 800;
59+
const uint32_t HEIGHT = 600;
6060

6161
const std::string MODEL_PATH = "models/chalet.obj";
6262
const std::string TEXTURE_PATH = "textures/chalet.jpg";

0 commit comments

Comments
 (0)