Skip to content

Commit

Permalink
internal/shader: bug fix: wrong type deduction at (scalar)*(matrix)
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Mar 26, 2022
1 parent 6bd3c81 commit aef00a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/shader/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions shader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit aef00a5

Please sign in to comment.