blob: 63fb1706513cdee2cb3c2b6dfd3cf8d17fe77570 [file] [log] [blame]
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gldriver
import (
"runtime"
"golang.org/x/mobile/gl"
)
// NewContext creates an OpenGL ES context with a dedicated processing thread.
func NewContext() (gl.Context, error) {
glctx, worker := gl.NewContext()
errCh := make(chan error)
workAvailable := worker.WorkAvailable()
go func() {
runtime.LockOSThread()
err := surfaceCreate()
errCh <- err
if err != nil {
return
}
for range workAvailable {
worker.DoWork()
}
}()
if err := <-errCh; err != nil {
return nil, err
}
return glctx, nil
}