mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
shareable: Bug fix: Add the padding to the offsets when there are no sources
Fixes #1320
This commit is contained in:
parent
0cf5216c29
commit
0f21829867
@ -345,6 +345,12 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
|
|||||||
sourceRegion.X += oxf
|
sourceRegion.X += oxf
|
||||||
sourceRegion.Y += oyf
|
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
|
var offsets [graphics.ShaderImageNum - 1][2]float32
|
||||||
|
@ -37,11 +37,49 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
|
|
||||||
dst.DrawRectShader(w/2, h/2, s, nil)
|
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 {
|
for j := 0; j < h; j++ {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
for i := 0; i < w; i++ {
|
||||||
}
|
got := dst.At(i, j).(color.RGBA)
|
||||||
|
var want color.RGBA
|
||||||
if got, want := dst.At(w/2, h/2).(color.RGBA), (color.RGBA{}); got != want {
|
if i < w/2 && j < h/2 {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user