From aef00a5235c430a2d582ea808aea16e557b948ea Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 27 Mar 2022 01:22:50 +0900 Subject: [PATCH] internal/shader: bug fix: wrong type deduction at (scalar)*(matrix) Updates #2037 --- internal/shader/expr.go | 2 +- shader_test.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/shader/expr.go b/internal/shader/expr.go index c03370f23..f53aff37d 100644 --- a/internal/shader/expr.go +++ b/internal/shader/expr.go @@ -232,7 +232,7 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", lhst.String(), e.Op, rhst.String())) return nil, nil, nil, false } - t = lhst + t = rhst default: cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", lhst.String(), e.Op, rhst.String())) return nil, nil, nil, false diff --git a/shader_test.go b/shader_test.go index e301356d6..ec4341cab 100644 --- a/shader_test.go +++ b/shader_test.go @@ -734,9 +734,10 @@ func TestShaderUniformMatrix2(t *testing.T) { s, err := ebiten.NewShader([]byte(`package main var Mat2 mat2 +var F float func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - return vec4(Mat2 * vec2(1), 1, 1) + return vec4(F * Mat2 * vec2(1), 1, 1) } `)) if err != nil { @@ -749,13 +750,14 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { 1.0 / 256.0, 2.0 / 256.0, 3.0 / 256.0, 4.0 / 256.0, }, + "F": float32(2), } dst.DrawRectShader(w, h, s, op) for j := 0; j < h; j++ { for i := 0; i < w; i++ { got := dst.At(i, j).(color.RGBA) - want := color.RGBA{4, 6, 0xff, 0xff} + want := color.RGBA{8, 12, 0xff, 0xff} if !sameColors(got, want, 2) { t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want) }