Surface Creation on Linux
We're going to be writing the Linux specific code for getting a surface in this section. While this code may work on another operating system that uses the XCB library, I cannot guarantee it will.
Surface Create Information
Before we create a surface, we must specify information ahead of time like most Vulkan objects. We'll be using VkXcbSurfaceCreateInfoKHR.
Definition for VkXcbSurfaceCreateInfoKHR:
typedef struct VkXcbSurfaceCreateInfoKHR {
VkStructureType sType;
const void* pNext;
VkXcbSurfaceCreateFlagsKHR flags;
xcb_connection_t* connection;
xcb_window_t window;
} VkXcbSurfaceCreateInfoKHR;
Documentation for VkXcbSurfaceCreateInfoKHR:
sTypeis the type of this structure and must beVK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR.pNextisNULLor a pointer to an extension-specific structure.flagsis reserved for future use.connectionis a pointer to anxcb_connection_tto the X server.windowis thexcb_window_tfor the X11 window to associate the surface with.
Usage for VkXcbSurfaceCreateInfoKHR:
VkXcbSurfaceCreateInfoKHR surfaceCreateInfo = {};
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
surfaceCreateInfo.pNext = NULL;
surfaceCreateInfo.flags = 0;
surfaceCreateInfo.connection = connection;
surfaceCreateInfo.window = window;
Creating the Surface
Now we can create the surface. We'll be calling the vkCreateXcbSurfaceKHR method to do so.
Definition for vkCreateXcbSurfaceKHR:
VkResult vkCreateXcbSurfaceKHR(
VkInstance instance,
const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);
Documentation for vkCreateXcbSurfaceKHR:
instanceis the instance to associate the surface with.pCreateInfois a pointer to an instance of theVkXcbSurfaceCreateInfoKHRstructure containing parameters affecting the creation of the surface object.pAllocatoris the allocator used for host memory allocated for the surface object when there is no more specific allocator available.pSurfacepoints to aVkSurfaceKHRhandle in which the created surface object is returned.
Usage for `vkCreateXcbSurfaceKHR:
VkResult result =
vkCreateXcbSurfaceKHR(instance, &surfaceCreateInfo, NULL, &surface);
assert(result == VK_SUCCESS);
Please go back to the Chapter 5 page to read about determining the color formats and color spaces for the surface.