Files
gio/app/headless/headless_darwin.go
T
Elias Naur ffe5ab51a2 gpu/gl: remove OpenGL functions parameter from NewBackend
As a consequence, most API is gone from gpu/gl, and embedding Gio in
foreign frameworks don't need to provide an OpenGL implementation.

The next change simplifies the GLFW embedding example accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-04 20:50:22 +01:00

58 lines
1.4 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
package headless
import (
"gioui.org/gpu/backend"
"gioui.org/gpu/gl"
_ "gioui.org/app/internal/cocoainit"
)
/*
#cgo CFLAGS: -DGL_SILENCE_DEPRECATION -Werror -Wno-deprecated-declarations -fmodules -fobjc-arc -x objective-c
#include <CoreFoundation/CoreFoundation.h>
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_headless_newContext(void);
__attribute__ ((visibility ("hidden"))) void gio_headless_releaseContext(CFTypeRef ctxRef);
__attribute__ ((visibility ("hidden"))) void gio_headless_clearCurrentContext(CFTypeRef ctxRef);
__attribute__ ((visibility ("hidden"))) void gio_headless_makeCurrentContext(CFTypeRef ctxRef);
__attribute__ ((visibility ("hidden"))) void gio_headless_prepareContext(CFTypeRef ctxRef);
*/
import "C"
type nsContext struct {
ctx C.CFTypeRef
prepared bool
}
func newGLContext() (context, error) {
ctx := C.gio_headless_newContext()
return &nsContext{ctx: ctx}, nil
}
func (c *nsContext) MakeCurrent() error {
C.gio_headless_makeCurrentContext(c.ctx)
if !c.prepared {
C.gio_headless_prepareContext(c.ctx)
c.prepared = true
}
return nil
}
func (c *nsContext) ReleaseCurrent() {
C.gio_headless_clearCurrentContext(c.ctx)
}
func (c *nsContext) Backend() (backend.Device, error) {
return gl.NewBackend(nil)
}
func (d *nsContext) Release() {
if d.ctx != 0 {
C.gio_headless_releaseContext(d.ctx)
d.ctx = 0
}
}