Enable wayland support for examples/triangle

This commit is contained in:
Park Joon-Kyu 2020-01-02 17:10:45 +09:00
parent fc85128c41
commit e91cfa4dc3
2 changed files with 16 additions and 4 deletions

View File

@ -15,7 +15,11 @@ elseif(APPLE)
set(OS_LIBRARIES "-framework Cocoa" "-framework CoreVideo" "-framework IOKit" "-framework QuartzCore")
target_compile_options(${TARGET_NAME} PRIVATE -x objective-c)
else(MSVC)
add_definitions(-DWGPU_TARGET=WGPU_TARGET_LINUX)
if(USE_WAYLAND)
add_definitions(-DWGPU_TARGET=WGPU_TARGET_LINUX_WAYLAND)
else(USE_WAYLAND)
add_definitions(-DWGPU_TARGET=WGPU_TARGET_LINUX_X11)
endif(USE_WAYLAND)
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
endif(MSVC)

View File

@ -12,8 +12,9 @@
#include <stdlib.h>
#define WGPU_TARGET_MACOS 1
#define WGPU_TARGET_LINUX 2
#define WGPU_TARGET_LINUX_X11 2
#define WGPU_TARGET_WINDOWS 3
#define WGPU_TARGET_LINUX_WAYLAND 4
#if WGPU_TARGET == WGPU_TARGET_MACOS
#include <Foundation/Foundation.h>
@ -23,8 +24,9 @@
#include <GLFW/glfw3.h>
#if WGPU_TARGET == WGPU_TARGET_MACOS
#define GLFW_EXPOSE_NATIVE_COCOA
#elif WGPU_TARGET == WGPU_TARGET_LINUX
#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11
#define GLFW_EXPOSE_NATIVE_X11
#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND
#define GLFW_EXPOSE_NATIVE_WAYLAND
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
#define GLFW_EXPOSE_NATIVE_WIN32
@ -174,12 +176,18 @@ int main() {
[ns_window.contentView setLayer:metal_layer];
surface = wgpu_create_surface_from_metal_layer(metal_layer);
}
#elif WGPU_TARGET == WGPU_TARGET_LINUX
#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11
{
Display *x11_display = glfwGetX11Display();
Window x11_window = glfwGetX11Window(window);
surface = wgpu_create_surface_from_xlib((const void **)x11_display, x11_window);
}
#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND
{
struct wl_display *wayland_display = glfwGetWaylandDisplay();
struct wl_surface *wayland_surface = glfwGetWaylandWindow(window);
surface = wgpu_create_surface_from_wayland(wayland_surface, wayland_display);
}
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
{
HWND hwnd = glfwGetWin32Window(window);