gioui.org/ui@v0.0.0-20190926171558-ce74bc0cbaea/app/egl_linux.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package app
     4  
     5  /*
     6  #cgo LDFLAGS: -lEGL
     7  
     8  #include <EGL/egl.h>
     9  #include <EGL/eglext.h>
    10  #include <GLES2/gl2.h>
    11  #include <GLES3/gl3.h>
    12  */
    13  import "C"
    14  
    15  type (
    16  	_EGLint     = C.EGLint
    17  	_EGLDisplay = C.EGLDisplay
    18  	_EGLConfig  = C.EGLConfig
    19  	_EGLContext = C.EGLContext
    20  	_EGLSurface = C.EGLSurface
    21  )
    22  
    23  func eglChooseConfig(disp _EGLDisplay, attribs []_EGLint) (_EGLConfig, bool) {
    24  	var cfg C.EGLConfig
    25  	var ncfg C.EGLint
    26  	if C.eglChooseConfig(disp, &attribs[0], &cfg, 1, &ncfg) != C.EGL_TRUE {
    27  		return nil, false
    28  	}
    29  	return _EGLConfig(cfg), true
    30  }
    31  
    32  func eglCreateContext(disp _EGLDisplay, cfg _EGLConfig, shareCtx _EGLContext, attribs []_EGLint) _EGLContext {
    33  	ctx := C.eglCreateContext(disp, cfg, shareCtx, &attribs[0])
    34  	return _EGLContext(ctx)
    35  }
    36  
    37  func eglDestroySurface(disp _EGLDisplay, surf _EGLSurface) bool {
    38  	return C.eglDestroySurface(disp, surf) == C.EGL_TRUE
    39  }
    40  
    41  func eglDestroyContext(disp _EGLDisplay, ctx _EGLContext) bool {
    42  	return C.eglDestroyContext(disp, ctx) == C.EGL_TRUE
    43  }
    44  
    45  func eglGetConfigAttrib(disp _EGLDisplay, cfg _EGLConfig, attr _EGLint) (_EGLint, bool) {
    46  	var val _EGLint
    47  	ret := C.eglGetConfigAttrib(disp, cfg, attr, &val)
    48  	return val, ret == C.EGL_TRUE
    49  }
    50  
    51  func eglGetError() _EGLint {
    52  	return C.eglGetError()
    53  }
    54  
    55  func eglInitialize(disp _EGLDisplay) (_EGLint, _EGLint, bool) {
    56  	var maj, min _EGLint
    57  	ret := C.eglInitialize(disp, &maj, &min)
    58  	return maj, min, ret == C.EGL_TRUE
    59  }
    60  
    61  func eglMakeCurrent(disp _EGLDisplay, draw, read _EGLSurface, ctx _EGLContext) bool {
    62  	return C.eglMakeCurrent(disp, draw, read, ctx) == C.EGL_TRUE
    63  }
    64  
    65  func eglReleaseThread() bool {
    66  	return C.eglReleaseThread() == C.EGL_TRUE
    67  }
    68  
    69  func eglSwapBuffers(disp _EGLDisplay, surf _EGLSurface) bool {
    70  	return C.eglSwapBuffers(disp, surf) == C.EGL_TRUE
    71  }
    72  
    73  func eglSwapInterval(disp _EGLDisplay, interval _EGLint) bool {
    74  	return C.eglSwapInterval(disp, interval) == C.EGL_TRUE
    75  }
    76  
    77  func eglTerminate(disp _EGLDisplay) bool {
    78  	return C.eglTerminate(disp) == C.EGL_TRUE
    79  }
    80  
    81  func eglQueryString(disp _EGLDisplay, name _EGLint) string {
    82  	return C.GoString(C.eglQueryString(disp, name))
    83  }