@@ -37,9 +37,16 @@ works in this tutorial.
3737
3838Start by adding a `surface` class member right below the debug callback.
3939
40- [,c++]
40+ [source,multilang,c++,c]
41+ .Surface member
4142----
43+ // START c++
4244vk::raii::SurfaceKHR surface = nullptr;
45+ // END c++
46+
47+ // START c
48+ VkSurfaceKHR surface = VK_NULL_HANDLE;
49+ // END c
4350----
4451
4552Although the `VkSurfaceKHR` object and its usage is platform-agnostic, its
@@ -72,12 +79,22 @@ Because a window surface is a Vulkan object, it comes with a
7279important parameters: `hwnd` and `hinstance`. These are the handles to the
7380window and the process.
7481
75- [,c++]
82+ [source,multilang,c++,c]
83+ .Win32 surface create info
7684----
85+ // START c++
86+ vk::Win32SurfaceCreateInfoKHR createInfo{
87+ .hwnd = glfwGetWin32Window(window),
88+ .hinstance = GetModuleHandle(nullptr)
89+ };
90+ // END c++
91+
92+ // START c
7793VkWin32SurfaceCreateInfoKHR createInfo{};
7894createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
7995createInfo.hwnd = glfwGetWin32Window(window);
8096createInfo.hinstance = GetModuleHandle(nullptr);
97+ // END c
8198----
8299
83100The `glfwGetWin32Window` function is used to get the raw `HWND` from the GLFW
@@ -91,11 +108,18 @@ Technically, this is a WSI extension function, but it is so commonly used
91108that the standard Vulkan loader includes it, so unlike other extensions, you
92109don't need to explicitly load it.
93110
94- [,c++]
111+ [source,multilang,c++,c]
112+ .Create the Win32 surface
95113----
114+ // START c++
115+ surface = vk::raii::SurfaceKHR(instance, createInfo);
116+ // END c++
117+
118+ // START c
96119if (vkCreateWin32SurfaceKHR(instance, &createInfo, nullptr, &surface) != VK_SUCCESS) {
97120 throw std::runtime_error("failed to create window surface!");
98121}
122+ // END c
99123----
100124
101125The process is similar for other platforms like Linux, where
@@ -125,15 +149,26 @@ void createSurface() {
125149The GLFW call takes simple parameters instead of a struct which makes the
126150implementation of the function very straightforward:
127151
128- [,c++]
152+ [source,multilang,c++,c]
153+ .GLFW window surface creation
129154----
155+ // START c++
130156void createSurface() {
131- VkSurfaceKHR _surface;
157+ VkSurfaceKHR _surface;
132158 if (glfwCreateWindowSurface(*instance, window, nullptr, &_surface) != 0) {
133159 throw std::runtime_error("failed to create window surface!");
134160 }
135161 surface = vk::raii::SurfaceKHR(instance, _surface);
136162}
163+ // END c++
164+
165+ // START c
166+ void createSurface() {
167+ if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {
168+ throw std::runtime_error("failed to create window surface!");
169+ }
170+ }
171+ // END c
137172----
138173
139174However, as you see in the above, GLFW only deals with the Vulkan C API.
@@ -165,9 +200,17 @@ to our window surface. The function to check for that is
165200queue family index and surface as parameters. Add a call to it
166201in the same loop as the `VK_QUEUE_GRAPHICS_BIT`:
167202
168- [,c++]
203+ [source,multilang,c++,c]
204+ .Presentation support query
169205----
170- VkBool32 presentSupport = physicalDevice.getSurfaceSupportKHR( graphicsIndex, *surface );
206+ // START c++
207+ VkBool32 presentSupport = physicalDevice.getSurfaceSupportKHR(graphicsIndex, *surface);
208+ // END c++
209+
210+ // START c
211+ VkBool32 presentSupport = VK_FALSE;
212+ vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, graphicsIndex, surface, &presentSupport);
213+ // END c
171214----
172215
173216Then check the value of the boolean and store the presentation family
0 commit comments