~eliasnaur/gio-example

9861f99f710de8a40bd59f98d1db910e6b79b029 — Elias Naur 2 months ago e95d9c9
opengl: make context current at each draw

macOS uses a single thread for all window event loops, which means
the window context must be made current at each draw. The "opengl"
example doesn't create multiple windows, but programs based on it
may.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 4 insertions(+), 0 deletions(-)

M opengl/main.go
M opengl/main.go => opengl/main.go +4 -0
@@ 119,6 119,10 @@ func loop(w *app.Window) error {
			gtx := layout.NewContext(&ops, e)
			drawUI(th, gtx)
			w.Run(func() {
				if ok := C.eglMakeCurrent(ctx.disp, ctx.surf, ctx.surf, ctx.ctx); ok != C.EGL_TRUE {
					err := fmt.Errorf("eglMakeCurrent failed (%#x)", C.eglGetError())
					log.Fatal(err)
				}
				// Trigger window resize detection in ANGLE.
				C.eglWaitClient()
				// Draw custom OpenGL content.