Summarizing the application flow

In this section, we will summarize the flow of swapchain creation and the building of the presentation window. It consists of two parts: initialization and rendering.

Initialization

The initialization process initializes, creates, and processes the swapchain. The swapchain is not yet connected to the framebuffer render process and the primitives. Therefore, the rendered output will be a blank presentation window for now.

First, VulkanRenderer initializes the presentation window and creates a native platform-specific empty window (500 x 500). This window renders the swapchain's front buffer drawing image. Next, it initializes the swapchain to meet swapchain prerequisites. The swapchain image view layouts are created using command buffers that are allocated from the preallocated pool of command buffers.

During the initialization of the swapchain, the WSI extensions are queried and stored in the form of function pointers. The logical swapchain surface object is created and associated with the presentation window. Next, a suitable graphics queue is queried from the logical device supporting the presentation; this queue is used to draw operations and present the swapchain images to the display output window. Finally, the device is also checked for all the possible image formats that can used for swapchain images. The creation of the swapchain includes querying the swapchain surface capabilities that specify surface configurations, such as the maximum size of the drawing surface, the available presentation modes, and so on. Using this surface configuration, the swapchain image objects are retrieved. Once the swapchain retrieves the images, it can be used to render the primitives. The swapchain images are retrieved by the WSI; therefore, the application does not own these. These images are finally converted into image views to allow the application to use them in the implementation.

We will also need to create the depth image for depth/stencil testing, and unlike the swapchain image, the depth image is solely the responsibility of the application. The application owns it and therefore can apply the image layout transition on the depth image with an optimal depth layout scheme. The image transition is applied using the memory barrier command, which is packed in the command buffer and submitted to the queue for upfront processing. The memory barrier inserts special instructions that guarantees the transitioning of the layout before it gets consumed.

Rendering - displaying the output window

The following code renders the presentation window:

void VulkanRenderer::render(){ 
    MSG msg;   // message 
    while (1) { 
        PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); 
        if (msg.message == WM_QUIT) { 
        break; // If Quit message the exit the render loop 
   } 
     TranslateMessage(&msg); 
     DispatchMessage(&msg); 
 
     // Display the window 
     RedrawWindow(window, NULL, NULL, RDW_INTERNALPAINT); 
    } 
} 

The following is the output of the preceding code implementation:

Rendering - displaying the output window

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.95.245