blob: 274d7996897bc4cb3c173b82d0e7605ce1828d3e [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.
//go:build !android
// +build !android
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
}