mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
internal/shader: bug fix: need to covert constant type correctly for assignments
Closes #2934
This commit is contained in:
parent
e7bb66bb2f
commit
7842942b24
@ -582,6 +582,12 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
|
||||
cs.addError(pos, fmt.Sprintf("cannot use type %s as type %s in variable declaration", rts[i].String(), lts[i].String()))
|
||||
return nil, false
|
||||
}
|
||||
switch lts[0].Main {
|
||||
case shaderir.Int:
|
||||
r[i].Const = gconstant.ToInt(r[i].Const)
|
||||
case shaderir.Float:
|
||||
r[i].Const = gconstant.ToFloat(r[i].Const)
|
||||
}
|
||||
}
|
||||
|
||||
if len(lhs) == 1 {
|
||||
|
@ -2559,3 +2559,39 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #2934
|
||||
func TestShaderAssignConst(t *testing.T) {
|
||||
const w, h = 16, 16
|
||||
|
||||
dst := ebiten.NewImage(w, h)
|
||||
s, err := ebiten.NewShader([]byte(`//kage:unit pixels
|
||||
|
||||
package main
|
||||
|
||||
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||
a := 0.0
|
||||
a = 1
|
||||
b, c := 0.0, 0.0
|
||||
b, c = 1, 1
|
||||
d := 0.0
|
||||
d += 1
|
||||
return vec4(a, b, c, d)
|
||||
}
|
||||
`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dst.DrawRectShader(w, h, s, nil)
|
||||
|
||||
for j := 0; j < h; j++ {
|
||||
for i := 0; i < w; i++ {
|
||||
got := dst.At(i, j).(color.RGBA)
|
||||
want := color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
|
||||
if !sameColors(got, want, 2) {
|
||||
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user