mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Add worker consumer
This commit is contained in:
parent
93450b1664
commit
269d94b145
@ -67,14 +67,24 @@ func NewContext() *Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gl mgl.Context
|
gl mgl.Context
|
||||||
worker mgl.Worker
|
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() {
|
func (c *Context) init() {
|
||||||
gl, worker = mgl.NewContext()
|
gl, worker = mgl.NewContext()
|
||||||
|
close(workerCreated)
|
||||||
// Textures' pixel formats are alpha premultiplied.
|
// Textures' pixel formats are alpha premultiplied.
|
||||||
gl.Enable(mgl.BLEND)
|
gl.Enable(mgl.BLEND)
|
||||||
gl.BlendFunc(mgl.ONE, mgl.ONE_MINUS_SRC_ALPHA)
|
gl.BlendFunc(mgl.ONE, mgl.ONE_MINUS_SRC_ALPHA)
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
glfw "github.com/go-gl/glfw/v3.1/glfw"
|
glfw "github.com/go-gl/glfw/v3.1/glfw"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Now() int64 {
|
func Now() int64 {
|
||||||
@ -51,18 +52,22 @@ func Init() {
|
|||||||
funcs: make(chan func()),
|
funcs: make(chan func()),
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
runtime.LockOSThread()
|
|
||||||
u.window.MakeContextCurrent()
|
|
||||||
glfw.SwapInterval(1)
|
|
||||||
for f := range u.funcs {
|
for f := range u.funcs {
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
go func() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
u.window.MakeContextCurrent()
|
||||||
|
glfw.SwapInterval(1)
|
||||||
|
opengl.Loop()
|
||||||
|
}()
|
||||||
|
|
||||||
currentUI = u
|
currentUI = u
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExecOnUIThread(f func()) {
|
func ExecOnUIThread(f func()) {
|
||||||
|
// TODO: Rename this function: f is actually NOT executed on UI threads
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
currentUI.funcs <- func() {
|
currentUI.funcs <- func() {
|
||||||
defer close(ch)
|
defer close(ch)
|
||||||
|
1
run.go
1
run.go
@ -57,7 +57,6 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
|
|||||||
ui.ExecOnUIThread(func() {
|
ui.ExecOnUIThread(func() {
|
||||||
glContext.Check()
|
glContext.Check()
|
||||||
})
|
})
|
||||||
|
|
||||||
graphicsContext, err := newGraphicsContext(width, height, actualScale)
|
graphicsContext, err := newGraphicsContext(width, height, actualScale)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user