简体   繁体   中英

Preprocessor symbol for Wayland, Xlib, XCB, MIR window systems

On Vulkan docs we have the following regarding WSI Platform:

The Vulkan API does not define any type of platform object. Platform-specific WSI extensions are defined, which contain platform-specific functions for using WSI. Use of these extensions is guarded by preprocessor symbols.

• VK_USE_PLATFORM_ANDROID_KHR - Android

• VK_USE_PLATFORM_MIR_KHR - Mir

• VK_USE_PLATFORM_WAYLAND_KHR - Wayland

• VK_USE_PLATFORM_WIN32_KHR - Microsoft Windows

• VK_USE_PLATFORM_XCB_KHR - X Window System, using the XCB library

• VK_USE_PLATFORM_XLIB_KHR - X Window System, using the Xlib library

I understand that I should pick a platform or a Window System, and then define the correct symbol prior to compile. When compiling against Android or Windows, I can just write something like below:

#if defined(ANDROID) || defined (__ANDROID__)
  #define VK_USE_PLATFORM_ANDROID_KHR 1
#elif defined(_WIN32)
  #define VK_USE_PLATFORM_WIN32_KHR 1
#endif

So far, OK. Android and Windows has their own unique window system, which is good enough. But Linux has several windowing systems - Xlib, XCB, Wayland and MIR, afaik.

I'd like to know if there is a C/C++ preprocessor symbol which may help to know which Window System is the one used by that environment, so can write generic code able to deal with each API, without messing then.

Xlib and XCB are two libraries that can both be used interchangeably to interface with an X11 windowing server on Linux. If you need your application to be compatible with older Linux systems, build for Xlib; otherwise, use XCB.

Wayland and Mir are both still highly experimental (as of May 2016), and can safely be ignored.

If you are the one interfacing with the windowing system then you already know what preprocessor symbol you need.

If you are not then as the application code (using a wrapper around the native windowing) then you would ask the wrapper for the vkSurface, if that is not available then raise an issue with the wrapper's maintainers.

If you are a vulkan library then you should be able to handle all linux windowing options. If you enable all preprocessor symbols and manually load the required function as needed depending on which function the application calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM