-
Notifications
You must be signed in to change notification settings - Fork 27
/
context_webgl.go
56 lines (48 loc) · 1.64 KB
/
context_webgl.go
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
52
53
54
55
56
// +build js
package glfw
import (
"errors"
"github.com/gopherjs/gopherjs/js"
)
func newContext(canvas *js.Object, ca *contextAttributes) (context *js.Object, err error) {
if js.Global.Get("WebGLRenderingContext") == js.Undefined {
return nil, errors.New("Your browser doesn't appear to support WebGL.")
}
attrs := map[string]bool{
"alpha": ca.Alpha,
"depth": ca.Depth,
"stencil": ca.Stencil,
"antialias": ca.Antialias,
"premultipliedAlpha": ca.PremultipliedAlpha,
"preserveDrawingBuffer": ca.PreserveDrawingBuffer,
"preferLowPowerToHighPerformance": ca.PreferLowPowerToHighPerformance,
"failIfMajorPerformanceCaveat": ca.FailIfMajorPerformanceCaveat,
}
if gl := canvas.Call("getContext", "webgl", attrs); gl != nil {
return gl, nil
} else if gl := canvas.Call("getContext", "experimental-webgl", attrs); gl != nil {
return gl, nil
} else {
return nil, errors.New("Creating a WebGL context has failed.")
}
}
type contextAttributes struct {
Alpha bool
Depth bool
Stencil bool
Antialias bool
PremultipliedAlpha bool
PreserveDrawingBuffer bool
PreferLowPowerToHighPerformance bool
FailIfMajorPerformanceCaveat bool
}
func defaultAttributes() *contextAttributes {
return &contextAttributes{
Alpha: false,
Depth: true,
Stencil: false,
Antialias: false,
PremultipliedAlpha: false,
PreserveDrawingBuffer: false,
}
}