github.com/Seikaijyu/gio@v0.0.1/internal/vk/vulkan_wayland.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  //go:build ((linux && !android) || freebsd) && !nowayland
     4  // +build linux,!android freebsd
     5  // +build !nowayland
     6  
     7  package vk
     8  
     9  /*
    10  #cgo linux pkg-config: wayland-client
    11  
    12  #define VK_USE_PLATFORM_WAYLAND_KHR
    13  #define VK_NO_PROTOTYPES 1
    14  #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
    15  #include <vulkan/vulkan.h>
    16  
    17  static VkResult vkCreateWaylandSurfaceKHR(PFN_vkCreateWaylandSurfaceKHR f, VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
    18  	return f(instance, pCreateInfo, pAllocator, pSurface);
    19  }
    20  */
    21  import "C"
    22  import (
    23  	"fmt"
    24  	"unsafe"
    25  )
    26  
    27  var wlFuncs struct {
    28  	vkCreateWaylandSurfaceKHR C.PFN_vkCreateWaylandSurfaceKHR
    29  }
    30  
    31  func init() {
    32  	loadFuncs = append(loadFuncs, func(dlopen func(name string) *[0]byte) {
    33  		wlFuncs.vkCreateWaylandSurfaceKHR = dlopen("vkCreateWaylandSurfaceKHR")
    34  	})
    35  }
    36  
    37  func CreateWaylandSurface(inst Instance, disp unsafe.Pointer, wlSurf unsafe.Pointer) (Surface, error) {
    38  	inf := C.VkWaylandSurfaceCreateInfoKHR{
    39  		sType:   C.VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
    40  		display: (*C.struct_wl_display)(disp),
    41  		surface: (*C.struct_wl_surface)(wlSurf),
    42  	}
    43  	var surf Surface
    44  	if err := vkErr(C.vkCreateWaylandSurfaceKHR(wlFuncs.vkCreateWaylandSurfaceKHR, inst, &inf, nil, &surf)); err != nil {
    45  		return 0, fmt.Errorf("vulkan: vkCreateWaylandSurfaceKHR: %w", err)
    46  	}
    47  	return surf, nil
    48  }