diff --git a/app/internal/gl/gl_js.go b/app/internal/gl/gl_js.go index ffb18316..bc16cbf3 100644 --- a/app/internal/gl/gl_js.go +++ b/app/internal/gl/gl_js.go @@ -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) diff --git a/app/internal/gl/types.go b/app/internal/gl/types.go index 2f007ca2..291001fa 100644 --- a/app/internal/gl/types.go +++ b/app/internal/gl/types.go @@ -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 +} diff --git a/app/internal/gl/types_js.go b/app/internal/gl/types_js.go index 61be5608..8f0419a8 100644 --- a/app/internal/gl/types_js.go +++ b/app/internal/gl/types_js.go @@ -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)) } diff --git a/app/internal/gl/util.go b/app/internal/gl/util.go index 0e438636..ead9590f 100644 --- a/app/internal/gl/util.go +++ b/app/internal/gl/util.go @@ -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) diff --git a/app/internal/gpu/gpu.go b/app/internal/gpu/gpu.go index d194630d..05ab150d 100644 --- a/app/internal/gpu/gpu.go +++ b/app/internal/gpu/gpu.go @@ -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) diff --git a/app/internal/window/gl_js.go b/app/internal/window/gl_js.go index acb49e27..798ff4ae 100644 --- a/app/internal/window/gl_js.go +++ b/app/internal/window/gl_js.go @@ -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} diff --git a/app/internal/window/os_js.go b/app/internal/window/os_js.go index 010f7c8a..e537eb96 100644 --- a/app/internal/window/os_js.go +++ b/app/internal/window/os_js.go @@ -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) } }