mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ui: Bug fix: gl* method should be called after looping starts
This commit is contained in:
parent
bae6d62067
commit
bb39766873
@ -49,6 +49,12 @@ func GetProgramID(p Program) ProgramID {
|
||||
|
||||
type context struct{}
|
||||
|
||||
// TODO: These variables can be in the context struct.
|
||||
var (
|
||||
gl mgl.Context
|
||||
worker mgl.Worker
|
||||
)
|
||||
|
||||
func NewContext() *Context {
|
||||
c := &Context{
|
||||
Nearest: mgl.NEAREST,
|
||||
@ -62,27 +68,21 @@ func NewContext() *Context {
|
||||
Triangles: mgl.TRIANGLES,
|
||||
Lines: mgl.LINES,
|
||||
}
|
||||
c.init()
|
||||
gl, worker = mgl.NewContext()
|
||||
return c
|
||||
}
|
||||
|
||||
var (
|
||||
gl mgl.Context
|
||||
worker mgl.Worker
|
||||
workerCreated = make(chan struct{})
|
||||
)
|
||||
|
||||
func Loop() {
|
||||
<-workerCreated
|
||||
for {
|
||||
<-worker.WorkAvailable()
|
||||
worker.DoWork()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) init() {
|
||||
gl, worker = mgl.NewContext()
|
||||
close(workerCreated)
|
||||
func (c *Context) Init() {
|
||||
// This initialization must be done after Loop is called.
|
||||
// This is why Init is separated from NewContext.
|
||||
|
||||
// Textures' pixel formats are alpha premultiplied.
|
||||
gl.Enable(mgl.BLEND)
|
||||
gl.BlendFunc(mgl.ONE, mgl.ONE_MINUS_SRC_ALPHA)
|
||||
|
@ -32,7 +32,6 @@ func Now() int64 {
|
||||
var currentUI *userInterface
|
||||
|
||||
func Init() *opengl.Context {
|
||||
// TODO: Is this OK to lock OS thread only for UI?
|
||||
runtime.LockOSThread()
|
||||
|
||||
err := glfw.Init()
|
||||
@ -53,16 +52,20 @@ func Init() *opengl.Context {
|
||||
u := &userInterface{
|
||||
window: window,
|
||||
}
|
||||
ch := make(chan struct{})
|
||||
go func() {
|
||||
runtime.LockOSThread()
|
||||
u.window.MakeContextCurrent()
|
||||
glfw.SwapInterval(1)
|
||||
close(ch)
|
||||
opengl.Loop()
|
||||
}()
|
||||
|
||||
currentUI = u
|
||||
context := opengl.NewContext()
|
||||
<-ch
|
||||
context.Init()
|
||||
|
||||
return opengl.NewContext()
|
||||
return context
|
||||
}
|
||||
|
||||
func Start(width, height, scale int, title string) (actualScale int, err error) {
|
||||
|
Loading…
Reference in New Issue
Block a user