mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Add worker consumer
This commit is contained in:
parent
93450b1664
commit
269d94b145
@ -67,14 +67,24 @@ func NewContext() *Context {
|
||||
}
|
||||
|
||||
var (
|
||||
gl mgl.Context
|
||||
worker mgl.Worker
|
||||
gl mgl.Context
|
||||
worker mgl.Worker
|
||||
workerCreated = make(chan struct{})
|
||||
)
|
||||
|
||||
// TODO: Implement updating Worker
|
||||
func Loop() {
|
||||
<-workerCreated
|
||||
for {
|
||||
select {
|
||||
case <-worker.WorkAvailable():
|
||||
worker.DoWork()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) init() {
|
||||
gl, worker = mgl.NewContext()
|
||||
close(workerCreated)
|
||||
// Textures' pixel formats are alpha premultiplied.
|
||||
gl.Enable(mgl.BLEND)
|
||||
gl.BlendFunc(mgl.ONE, mgl.ONE_MINUS_SRC_ALPHA)
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
glfw "github.com/go-gl/glfw/v3.1/glfw"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||
)
|
||||
|
||||
func Now() int64 {
|
||||
@ -51,18 +52,22 @@ func Init() {
|
||||
funcs: make(chan func()),
|
||||
}
|
||||
go func() {
|
||||
runtime.LockOSThread()
|
||||
u.window.MakeContextCurrent()
|
||||
glfw.SwapInterval(1)
|
||||
for f := range u.funcs {
|
||||
f()
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
runtime.LockOSThread()
|
||||
u.window.MakeContextCurrent()
|
||||
glfw.SwapInterval(1)
|
||||
opengl.Loop()
|
||||
}()
|
||||
|
||||
currentUI = u
|
||||
}
|
||||
|
||||
func ExecOnUIThread(f func()) {
|
||||
// TODO: Rename this function: f is actually NOT executed on UI threads
|
||||
ch := make(chan struct{})
|
||||
currentUI.funcs <- func() {
|
||||
defer close(ch)
|
||||
|
Loading…
Reference in New Issue
Block a user