fix window switching
This commit is contained in:
parent
3b929ad5c3
commit
d4e242a59b
23
window.go
23
window.go
|
@ -1,6 +1,8 @@
|
||||||
package pixel
|
package pixel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/faiface/pixel/pixelgl"
|
"github.com/faiface/pixel/pixelgl"
|
||||||
"github.com/go-gl/gl/v3.3-core/gl"
|
"github.com/go-gl/gl/v3.3-core/gl"
|
||||||
"github.com/go-gl/glfw/v3.2/glfw"
|
"github.com/go-gl/glfw/v3.2/glfw"
|
||||||
|
@ -81,19 +83,24 @@ func (w *Window) Update() {
|
||||||
w.End()
|
w.End()
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentWindow *Window = nil
|
var (
|
||||||
|
windowMutex sync.Mutex
|
||||||
|
currentWindow *Window
|
||||||
|
)
|
||||||
|
|
||||||
func (w *Window) Begin() {
|
func (w *Window) Begin() {
|
||||||
pixelgl.Do(func() {
|
needSwitch := pixelgl.DoVal(func() interface{} {
|
||||||
if currentWindow != w {
|
return currentWindow != w
|
||||||
|
}).(bool)
|
||||||
|
if needSwitch {
|
||||||
|
windowMutex.Lock()
|
||||||
|
pixelgl.Do(func() {
|
||||||
w.window.MakeContextCurrent()
|
w.window.MakeContextCurrent()
|
||||||
pixelgl.Init()
|
pixelgl.Init()
|
||||||
currentWindow = w
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) End() {
|
func (w *Window) End() {
|
||||||
// nothing really
|
windowMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue