github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/app/internal/wm/egl_windows.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 package wm 4 5 import ( 6 "golang.org/x/sys/windows" 7 8 "github.com/cybriq/giocore/internal/egl" 9 ) 10 11 type glContext struct { 12 win *window 13 *egl.Context 14 } 15 16 func init() { 17 drivers = append(drivers, gpuAPI{ 18 priority: 2, 19 initializer: func(w *window) (Context, error) { 20 disp := egl.NativeDisplayType(w.HDC()) 21 ctx, err := egl.NewContext(disp) 22 if err != nil { 23 return nil, err 24 } 25 return &glContext{win: w, Context: ctx}, nil 26 }, 27 }) 28 } 29 30 func (c *glContext) Release() { 31 if c.Context != nil { 32 c.Context.Release() 33 c.Context = nil 34 } 35 } 36 37 func (c *glContext) Refresh() error { 38 return nil 39 } 40 41 func (c *glContext) MakeCurrent() error { 42 c.Context.ReleaseSurface() 43 var ( 44 win windows.Handle 45 width, height int 46 ) 47 c.win.w.Run(func() { 48 win, width, height = c.win.HWND() 49 }) 50 eglSurf := egl.NativeWindowType(win) 51 if err := c.Context.CreateSurface(eglSurf, width, height); err != nil { 52 return err 53 } 54 if err := c.Context.MakeCurrent(); err != nil { 55 return err 56 } 57 c.Context.EnableVSync(true) 58 return nil 59 } 60 61 func (c *glContext) Lock() {} 62 63 func (c *glContext) Unlock() {}