github.com/Seikaijyu/gio@v0.0.1/internal/egl/egl_unix.go (about)

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