shareable: Bug fix: Add the padding to the offsets when there are no sources

Fixes #1320
This commit is contained in:
Hajime Hoshi 2020-08-27 02:00:20 +09:00
parent 0cf5216c29
commit 0f21829867
2 changed files with 50 additions and 6 deletions

View File

@ -345,6 +345,12 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
sourceRegion.X += oxf
sourceRegion.Y += oyf
}
} else {
n := len(vertices) / graphics.VertexFloatNum
for i := 0; i < n; i++ {
vertices[i*graphics.VertexFloatNum+0] += dx
vertices[i*graphics.VertexFloatNum+1] += dy
}
}
var offsets [graphics.ShaderImageNum - 1][2]float32

View File

@ -37,11 +37,49 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
dst.DrawRectShader(w/2, h/2, s, nil)
if got, want := dst.At(0, 0).(color.RGBA), (color.RGBA{0xff, 0, 0, 0xff}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
if got, want := dst.At(w/2, h/2).(color.RGBA), (color.RGBA{}); got != want {
t.Errorf("got: %v, want: %v", got, want)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := dst.At(i, j).(color.RGBA)
var want color.RGBA
if i < w/2 && j < h/2 {
want = color.RGBA{0xff, 0, 0, 0xff}
}
if got != want {
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
}
func TestShaderFillWithDrawImage(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
s, err := NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return vec4(1, 0, 0, 1)
}
`))
if err != nil {
t.Fatal(err)
}
src, _ := NewImage(w/2, h/2, FilterDefault)
op := &DrawImageOptions{}
op.Shader = s
dst.DrawImage(src, op)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := dst.At(i, j).(color.RGBA)
var want color.RGBA
if i < w/2 && j < h/2 {
want = color.RGBA{0xff, 0, 0, 0xff}
}
if got != want {
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
}