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