mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package cocoa
|
|
|
|
// void* CreateGLContext(void* sharedGLContext);
|
|
// void UseGLContext(void* glContext);
|
|
// void UnuseGLContext(void);
|
|
//
|
|
import "C"
|
|
import (
|
|
"runtime"
|
|
"unsafe"
|
|
)
|
|
|
|
type textureFactory struct {
|
|
sharedContext unsafe.Pointer
|
|
funcs chan func()
|
|
funcsDone chan struct{}
|
|
textureFactoryEvents
|
|
}
|
|
|
|
func runTextureFactory() *textureFactory {
|
|
t := &textureFactory{
|
|
funcs: make(chan func()),
|
|
funcsDone: make(chan struct{}),
|
|
}
|
|
ch := make(chan struct{})
|
|
go func() {
|
|
runtime.LockOSThread()
|
|
t.sharedContext = C.CreateGLContext(unsafe.Pointer(nil))
|
|
close(ch)
|
|
t.loop()
|
|
}()
|
|
<-ch
|
|
return t
|
|
}
|
|
|
|
func (t *textureFactory) loop() {
|
|
for {
|
|
select {
|
|
case f := <-t.funcs:
|
|
C.UseGLContext(t.sharedContext)
|
|
f()
|
|
C.UnuseGLContext()
|
|
t.funcsDone <- struct{}{}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (t *textureFactory) useContext(f func()) {
|
|
t.funcs <- f
|
|
<-t.funcsDone
|
|
}
|
|
|
|
func (t *textureFactory) createWindow(ui *UI, width, height int, title string) *window {
|
|
return runWindow(ui, width, height, title, t.sharedContext)
|
|
}
|