Files
gio/app/internal/window/egl_windows.go
T
Elias Naur 8cec7d1a40 app/internal/window: move context refresh to window
Instead of calling from the low level context into the window
for its surface and dimensions, add a Context.MakeCurrent method
that does it directly.

The result is simpler and clearer logic. For example, synchronization
is obviously no longer needed. It wasn't necessary before, but the
reason was unclear.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-01 23:25:04 +01:00

46 lines
861 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
package window
import (
"unsafe"
"gioui.org/app/internal/egl"
"gioui.org/app/internal/gl"
)
type context struct {
win *window
*egl.Context
}
func (w *window) NewContext() (gl.Context, error) {
disp := egl.NativeDisplayType(unsafe.Pointer(w.HDC()))
ctx, err := egl.NewContext(disp)
if err != nil {
return nil, err
}
return &context{win: w, Context: ctx}, nil
}
func (c *context) Release() {
if c.Context != nil {
c.Context.Release()
c.Context = nil
}
}
func (c *context) MakeCurrent() error {
c.Context.ReleaseSurface()
win, width, height := c.win.HWND()
eglSurf := egl.NativeWindowType(win)
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
return err
}
if err := c.Context.MakeCurrent(); err != nil {
return err
}
c.Context.EnableVSync(true)
return nil
}