app/internal/gl: support Go 1.14 change to WebAssembly's js.Value

Gio programs will no longer build with Go 1.13; let's keep it at that
until someone complains.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-11-06 17:59:39 +01:00
parent c3533c3f84
commit 62da32be9c
7 changed files with 53 additions and 21 deletions
+10 -10
View File
@@ -21,16 +21,16 @@ type Functions struct {
func (f *Functions) Init(version int) error {
if version < 2 {
f.EXT_disjoint_timer_query = f.getExtension("EXT_disjoint_timer_query")
if f.getExtension("OES_texture_half_float") == js.Null() && f.getExtension("OES_texture_float") == js.Null() {
if f.getExtension("OES_texture_half_float").IsNull() && f.getExtension("OES_texture_float").IsNull() {
return errors.New("gl: no support for neither OES_texture_half_float nor OES_texture_float")
}
if f.getExtension("EXT_sRGB") == js.Null() {
if f.getExtension("EXT_sRGB").IsNull() {
return errors.New("gl: EXT_sRGB not supported")
}
} else {
// WebGL2 extensions.
f.EXT_disjoint_timer_query_webgl2 = f.getExtension("EXT_disjoint_timer_query_webgl2")
if f.getExtension("EXT_color_buffer_half_float") == js.Null() && f.getExtension("EXT_color_buffer_float") == js.Null() {
if f.getExtension("EXT_color_buffer_half_float").IsNull() && f.getExtension("EXT_color_buffer_float").IsNull() {
return errors.New("gl: no support for neither EXT_color_buffer_half_float nor EXT_color_buffer_float")
}
}
@@ -48,7 +48,7 @@ func (f *Functions) AttachShader(p Program, s Shader) {
f.Ctx.Call("attachShader", js.Value(p), js.Value(s))
}
func (f *Functions) BeginQuery(target Enum, query Query) {
if f.EXT_disjoint_timer_query_webgl2 != js.Null() {
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
f.Ctx.Call("beginQuery", int(target), js.Value(query))
} else {
f.EXT_disjoint_timer_query.Call("beginQueryEXT", int(target), js.Value(query))
@@ -124,7 +124,7 @@ func (f *Functions) DeleteProgram(p Program) {
f.Ctx.Call("deleteProgram", js.Value(p))
}
func (f *Functions) DeleteQuery(query Query) {
if f.EXT_disjoint_timer_query_webgl2 != js.Null() {
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
f.Ctx.Call("deleteQuery", js.Value(query))
} else {
f.EXT_disjoint_timer_query.Call("deleteQueryEXT", js.Value(query))
@@ -164,7 +164,7 @@ func (f *Functions) EnableVertexAttribArray(a Attrib) {
f.Ctx.Call("enableVertexAttribArray", int(a))
}
func (f *Functions) EndQuery(target Enum) {
if f.EXT_disjoint_timer_query_webgl2 != js.Null() {
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
f.Ctx.Call("endQuery", int(target))
} else {
f.EXT_disjoint_timer_query.Call("endQueryEXT", int(target))
@@ -201,7 +201,7 @@ func (f *Functions) GetProgramInfoLog(p Program) string {
return f.Ctx.Call("getProgramInfoLog", js.Value(p)).String()
}
func (f *Functions) GetQueryObjectuiv(query Query, pname Enum) uint {
if f.EXT_disjoint_timer_query_webgl2 != js.Null() {
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
return uint(paramVal(f.Ctx.Call("getQueryParameter", js.Value(query), int(pname))))
} else {
return uint(paramVal(f.EXT_disjoint_timer_query.Call("getQueryObjectEXT", js.Value(query), int(pname))))
@@ -231,8 +231,8 @@ func (f *Functions) GetUniformLocation(p Program, name string) Uniform {
}
func (f *Functions) InvalidateFramebuffer(target, attachment Enum) {
fn := f.Ctx.Get("invalidateFramebuffer")
if fn != js.Undefined() {
if f.int32Buf == (js.Value{}) {
if !fn.IsUndefined() {
if f.int32Buf.IsUndefined() {
f.int32Buf = js.Global().Get("Int32Array").New(1)
}
f.int32Buf.SetIndex(0, int32(attachment))
@@ -306,7 +306,7 @@ func (f *Functions) resizeByteBuffer(n int) {
if n == 0 {
return
}
if f.byteBuf != (js.Value{}) && f.byteBuf.Length() >= n {
if !f.byteBuf.IsUndefined() && f.byteBuf.Length() >= n {
return
}
f.byteBuf = js.Global().Get("Uint8Array").New(n)
+16
View File
@@ -17,3 +17,19 @@ type (
func (u Uniform) Valid() bool {
return u.V != -1
}
func (p Program) Valid() bool {
return p.V != 0
}
func (s Shader) Valid() bool {
return s.V != 0
}
func (t Texture) Valid() bool {
return t.V != 0
}
func (t Texture) Equal(t2 Texture) bool {
return t == t2
}
+18 -2
View File
@@ -16,6 +16,22 @@ type (
Object js.Value
)
func (u Uniform) Valid() bool {
return js.Value(u) != js.Null()
func (p Program) Valid() bool {
return !js.Value(p).IsUndefined() && !js.Value(p).IsNull()
}
func (s Shader) Valid() bool {
return !js.Value(s).IsUndefined() && !js.Value(s).IsNull()
}
func (u Uniform) Valid() bool {
return !js.Value(u).IsUndefined() && !js.Value(u).IsNull()
}
func (t Texture) Valid() bool {
return !js.Value(t).IsUndefined() && !js.Value(t).IsNull()
}
func (t Texture) Equal(t2 Texture) bool {
return js.Value(t).Equal(js.Value(t2))
}
+2 -2
View File
@@ -22,7 +22,7 @@ func CreateProgram(ctx *Functions, vsSrc, fsSrc string, attribs []string) (Progr
}
defer ctx.DeleteShader(fs)
prog := ctx.CreateProgram()
if prog == (Program{}) {
if !prog.Valid() {
return Program{}, errors.New("glCreateProgram failed")
}
ctx.AttachShader(prog, vs)
@@ -49,7 +49,7 @@ func GetUniformLocation(ctx *Functions, prog Program, name string) Uniform {
func createShader(ctx *Functions, typ Enum, src string) (Shader, error) {
sh := ctx.CreateShader(typ)
if sh == (Shader{}) {
if !sh.Valid() {
return Shader{}, errors.New("glCreateShader failed")
}
ctx.ShaderSource(sh, src)
+3 -3
View File
@@ -409,7 +409,7 @@ func (g *GPU) setErr(err error) {
}
func (r *renderer) texHandle(t *texture) gl.Texture {
if t.id != (gl.Texture{}) {
if t.id.Valid() {
return t.id
}
t.id = createTexture(r.ctx)
@@ -419,7 +419,7 @@ func (r *renderer) texHandle(t *texture) gl.Texture {
}
func (t *texture) release(ctx *context) {
if t.id != (gl.Texture{}) {
if t.id.Valid() {
ctx.DeleteTexture(t.id)
}
}
@@ -898,7 +898,7 @@ func (r *renderer) drawOps(ops []imageOp) {
case clipTypeIntersection:
fbo = r.pather.stenciler.intersections.fbos[img.place.Idx]
}
if coverTex != fbo.tex {
if !coverTex.Equal(fbo.tex) {
coverTex = fbo.tex
r.ctx.ActiveTexture(gl.TEXTURE1)
r.ctx.BindTexture(gl.TEXTURE_2D, coverTex)
+2 -2
View File
@@ -25,11 +25,11 @@ func newContext(w *window) (*context, error) {
}
version := 2
ctx := w.cnv.Call("getContext", "webgl2", args)
if ctx == js.Null() {
if ctx.IsNull() {
version = 1
ctx = w.cnv.Call("getContext", "webgl", args)
}
if ctx == js.Null() {
if ctx.IsNull() {
return nil, errors.New("app: webgl is not supported")
}
f := &gl.Functions{Ctx: ctx}
+2 -2
View File
@@ -65,7 +65,7 @@ func NewWindow(win Callbacks, opts *Options) error {
func getContainer(doc js.Value) js.Value {
cont := doc.Call("getElementById", "giowindow")
if cont != js.Null() {
if !cont.IsNull() {
return cont
}
cont = doc.Call("createElement", "DIV")
@@ -252,7 +252,7 @@ func (w *window) touchEvent(typ pointer.Type, e js.Value) {
func (w *window) touchIDFor(touch js.Value) pointer.ID {
id := touch.Get("identifier")
for i, id2 := range w.touches {
if id2 == id {
if id2.Equal(id) {
return pointer.ID(i)
}
}