aboutsummaryrefslogtreecommitdiff
path: root/vendor/gioui.org/app/internal/window/egl_windows.go
blob: 654d279d5338e549db26c1ebaee12c87bf0068d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: Unlicense OR MIT

package window

import (
	"gioui.org/app/internal/egl"
)

type glContext struct {
	win *window
	*egl.Context
}

func init() {
	backends = append(backends, gpuAPI{
		priority: 2,
		initializer: func(w *window) (Context, error) {
			disp := egl.NativeDisplayType(w.HDC())
			ctx, err := egl.NewContext(disp)
			if err != nil {
				return nil, err
			}
			return &glContext{win: w, Context: ctx}, nil
		},
	})
}

func (c *glContext) Release() {
	if c.Context != nil {
		c.Context.Release()
		c.Context = nil
	}
}

func (c *glContext) 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
}

func (c *glContext) Lock() {}

func (c *glContext) Unlock() {}