summaryrefslogtreecommitdiffstats
path: root/shiny/driver/gldriver/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'shiny/driver/gldriver/context.go')
-rw-r--r--shiny/driver/gldriver/context.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/shiny/driver/gldriver/context.go b/shiny/driver/gldriver/context.go
new file mode 100644
index 0000000..488a388
--- /dev/null
+++ b/shiny/driver/gldriver/context.go
@@ -0,0 +1,37 @@
+// 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
+
+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
+}