~eliasnaur/gio-example

gio-example/opengl/egl_linux.go -rw-r--r-- 1.1 KiB
a9116b22Chris Waldon go.*: update to latest gio{,/x} and prune deps 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: Unlicense OR MIT

package main

import (
	"image"
	"unsafe"

	"gioui.org/app"
)

/*
#cgo linux pkg-config: egl wayland-egl
#cgo CFLAGS: -DEGL_NO_X11
#cgo LDFLAGS: -lEGL -lGLESv2

#include <EGL/egl.h>
#include <wayland-client.h>
#include <wayland-egl.h>
#include <GLES3/gl3.h>
#define EGL_EGLEXT_PROTOTYPES
#include <EGL/eglext.h>

*/
import "C"

func getDisplay(ve app.ViewEvent) C.EGLDisplay {
	switch ve := ve.(type) {
	case app.X11ViewEvent:
		return C.eglGetDisplay(C.EGLNativeDisplayType(ve.Display))
	case app.WaylandViewEvent:
		return C.eglGetDisplay(C.EGLNativeDisplayType(ve.Display))
	}
	panic("no display available")
}

func nativeViewFor(e app.ViewEvent, size image.Point) (C.EGLNativeWindowType, func()) {
	switch e := e.(type) {
	case app.X11ViewEvent:
		return C.EGLNativeWindowType(uintptr(e.Window)), func() {}
	case app.WaylandViewEvent:
		eglWin := C.wl_egl_window_create((*C.struct_wl_surface)(e.Surface), C.int(size.X), C.int(size.Y))
		return C.EGLNativeWindowType(uintptr(unsafe.Pointer(eglWin))), func() {
			C.wl_egl_window_destroy(eglWin)
		}
	}
	panic("no native view available")
}