egl_unix.go raw
1 // SPDX-License-Identifier: Unlicense OR MIT
2
3 // +build linux freebsd openbsd
4
5 package egl
6
7 /*
8 #cgo linux,!android pkg-config: egl
9 #cgo freebsd openbsd android LDFLAGS: -lEGL
10 #cgo freebsd CFLAGS: -I/usr/local/include
11 #cgo freebsd LDFLAGS: -L/usr/local/lib
12 #cgo openbsd CFLAGS: -I/usr/X11R6/include
13 #cgo openbsd LDFLAGS: -L/usr/X11R6/lib
14 #cgo CFLAGS: -DEGL_NO_X11
15
16 #include <EGL/egl.h>
17 #include <EGL/eglext.h>
18 */
19 import "C"
20
21 type (
22 _EGLint = C.EGLint
23 _EGLDisplay = C.EGLDisplay
24 _EGLConfig = C.EGLConfig
25 _EGLContext = C.EGLContext
26 _EGLSurface = C.EGLSurface
27 NativeDisplayType = C.EGLNativeDisplayType
28 NativeWindowType = C.EGLNativeWindowType
29 )
30
31 func loadEGL() error {
32 return nil
33 }
34
35 func eglChooseConfig(disp _EGLDisplay, attribs []_EGLint) (_EGLConfig, bool) {
36 var cfg C.EGLConfig
37 var ncfg C.EGLint
38 if C.eglChooseConfig(disp, &attribs[0], &cfg, 1, &ncfg) != C.EGL_TRUE {
39 return nilEGLConfig, false
40 }
41 return _EGLConfig(cfg), true
42 }
43
44 func eglCreateContext(disp _EGLDisplay, cfg _EGLConfig, shareCtx _EGLContext, attribs []_EGLint) _EGLContext {
45 ctx := C.eglCreateContext(disp, cfg, shareCtx, &attribs[0])
46 return _EGLContext(ctx)
47 }
48
49 func eglDestroySurface(disp _EGLDisplay, surf _EGLSurface) bool {
50 return C.eglDestroySurface(disp, surf) == C.EGL_TRUE
51 }
52
53 func eglDestroyContext(disp _EGLDisplay, ctx _EGLContext) bool {
54 return C.eglDestroyContext(disp, ctx) == C.EGL_TRUE
55 }
56
57 func eglGetConfigAttrib(disp _EGLDisplay, cfg _EGLConfig, attr _EGLint) (_EGLint, bool) {
58 var val _EGLint
59 ret := C.eglGetConfigAttrib(disp, cfg, attr, &val)
60 return val, ret == C.EGL_TRUE
61 }
62
63 func eglGetError() _EGLint {
64 return C.eglGetError()
65 }
66
67 func eglInitialize(disp _EGLDisplay) (_EGLint, _EGLint, bool) {
68 var maj, min _EGLint
69 ret := C.eglInitialize(disp, &maj, &min)
70 return maj, min, ret == C.EGL_TRUE
71 }
72
73 func eglMakeCurrent(disp _EGLDisplay, draw, read _EGLSurface, ctx _EGLContext) bool {
74 return C.eglMakeCurrent(disp, draw, read, ctx) == C.EGL_TRUE
75 }
76
77 func eglReleaseThread() bool {
78 return C.eglReleaseThread() == C.EGL_TRUE
79 }
80
81 func eglSwapBuffers(disp _EGLDisplay, surf _EGLSurface) bool {
82 return C.eglSwapBuffers(disp, surf) == C.EGL_TRUE
83 }
84
85 func eglSwapInterval(disp _EGLDisplay, interval _EGLint) bool {
86 return C.eglSwapInterval(disp, interval) == C.EGL_TRUE
87 }
88
89 func eglTerminate(disp _EGLDisplay) bool {
90 return C.eglTerminate(disp) == C.EGL_TRUE
91 }
92
93 func eglQueryString(disp _EGLDisplay, name _EGLint) string {
94 return C.GoString(C.eglQueryString(disp, name))
95 }
96
97 func eglGetDisplay(disp NativeDisplayType) _EGLDisplay {
98 return C.eglGetDisplay(disp)
99 }
100
101 func eglCreateWindowSurface(disp _EGLDisplay, conf _EGLConfig, win NativeWindowType, attribs []_EGLint) _EGLSurface {
102 eglSurf := C.eglCreateWindowSurface(disp, conf, win, &attribs[0])
103 return eglSurf
104 }
105