From 255da0367ffeadef839bac0d59f57deaee14886a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 20 Jun 2020 18:10:23 +0900 Subject: [PATCH] shader: Bug fix: a binary expression for an int and a float did not work --- internal/shader/shader.go | 8 ++++---- internal/shaderir/glsl.go | 2 +- internal/shaderir/type.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/shader/shader.go b/internal/shader/shader.go index 0315b1d00..0ad3c31f9 100644 --- a/internal/shader/shader.go +++ b/internal/shader/shader.go @@ -855,18 +855,18 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr, t = lhst } else if lhst.Main == shaderir.Float || lhst.Main == shaderir.Int { switch rhst.Main { - case shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4: + case shaderir.Float, shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4: t = rhst default: - cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", e.X, e.Op, e.Y)) + cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", lhst.String(), e.Op, rhst.String())) return nil, nil, nil } } else if rhst.Main == shaderir.Float || rhst.Main == shaderir.Int { switch lhst.Main { - case shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4: + case shaderir.Float, shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4: t = lhst default: - cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", e.X, e.Op, e.Y)) + cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", lhst.String(), e.Op, rhst.String())) return nil, nil, nil } } diff --git a/internal/shaderir/glsl.go b/internal/shaderir/glsl.go index 4ab0fc5e2..c13abce25 100644 --- a/internal/shaderir/glsl.go +++ b/internal/shaderir/glsl.go @@ -60,7 +60,7 @@ func (p *Program) structName(t *Type) string { if t.Main != Struct { panic("shaderir: the given type at structName must be a struct") } - s := t.serialize() + s := t.String() if n, ok := p.structNames[s]; ok { return n } diff --git a/internal/shaderir/type.go b/internal/shaderir/type.go index f18b001fa..910aa20a6 100644 --- a/internal/shaderir/type.go +++ b/internal/shaderir/type.go @@ -43,7 +43,7 @@ func (t *Type) Equal(rhs *Type) bool { return true } -func (t *Type) serialize() string { +func (t *Type) String() string { switch t.Main { case None: return "none" @@ -68,12 +68,12 @@ func (t *Type) serialize() string { case Texture2D: return "sampler2D" case Array: - return fmt.Sprintf("%s[%d]", t.Sub[0].serialize(), t.Length) + return fmt.Sprintf("%s[%d]", t.Sub[0].String(), t.Length) case Struct: str := "struct{" sub := make([]string, 0, len(t.Sub)) for _, st := range t.Sub { - sub = append(sub, st.serialize()) + sub = append(sub, st.String()) } str += strings.Join(sub, ",") str += "}"