egl_unix.go 2.8 KB

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