mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphics: Add TestImageOutside
This commit is contained in:
parent
704d4cf464
commit
98532d8983
11
image.go
11
image.go
@ -98,11 +98,13 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
if options == nil {
|
||||
options = &DrawImageOptions{}
|
||||
}
|
||||
|
||||
parts := options.ImageParts
|
||||
// Parts is deprecated. This implementations is for backward compatibility.
|
||||
if parts == nil && options.Parts != nil {
|
||||
parts = imageParts(options.Parts)
|
||||
}
|
||||
|
||||
// ImageParts is deprecated. This implementations is for backward compatibility.
|
||||
if parts != nil {
|
||||
l := parts.Len()
|
||||
@ -124,13 +126,18 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
w, h := img.restorable.Size()
|
||||
sx0, sy0, sx1, sy1 := 0, 0, w, h
|
||||
if r := options.SourceRect; r != nil {
|
||||
sx0 = r.Min.X
|
||||
sy0 = r.Min.Y
|
||||
sx1 = r.Max.X
|
||||
sy1 = r.Max.Y
|
||||
if sx1 > r.Max.X {
|
||||
sx1 = r.Max.X
|
||||
}
|
||||
if sy1 > r.Max.Y {
|
||||
sy1 = r.Max.Y
|
||||
}
|
||||
}
|
||||
vs := vertices(sx0, sy0, sx1, sy1, w, h, &options.GeoM.impl)
|
||||
mode := opengl.CompositeMode(options.CompositeMode)
|
||||
|
@ -621,3 +621,42 @@ func TestImageLinear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageOutside(t *testing.T) {
|
||||
src, _ := NewImage(5, 10, FilterNearest) // internal texture size is 16x16.
|
||||
dst, _ := NewImage(4, 4, FilterNearest)
|
||||
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||
|
||||
cases := []struct {
|
||||
X, Y int
|
||||
}{
|
||||
{-4, -4},
|
||||
{5, 0},
|
||||
{0, 10},
|
||||
{5, 10},
|
||||
{16, 0},
|
||||
{0, 16},
|
||||
{16, 16},
|
||||
{16, -4},
|
||||
{-4, 16},
|
||||
}
|
||||
for _, c := range cases {
|
||||
dst.Clear()
|
||||
|
||||
op := &DrawImageOptions{}
|
||||
op.GeoM.Translate(0, 0)
|
||||
r := image.Rect(c.X, c.Y, c.X+4, c.Y+4)
|
||||
op.SourceRect = &r
|
||||
dst.DrawImage(src, op)
|
||||
|
||||
for j := 0; j < 4; j++ {
|
||||
for i := 0; i < 4; i++ {
|
||||
got := color.RGBAModel.Convert(dst.At(i, j)).(color.RGBA)
|
||||
want := color.RGBA{0, 0, 0, 0}
|
||||
if got != want {
|
||||
t.Errorf("src(%d, %d), dst At(%d, %d): got %#v, want: %#v", c.X, c.Y, i, j, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,9 @@ highp vec2 roundTexel(highp vec2 p) {
|
||||
}
|
||||
|
||||
vec4 getColorAt(highp vec2 pos) {
|
||||
if (pos.x < 0.0 || pos.y < 0.0) {
|
||||
return vec4(0, 0, 0, 0);
|
||||
}
|
||||
if (pos.x < varying_tex_coord_min.x ||
|
||||
pos.y < varying_tex_coord_min.y ||
|
||||
varying_tex_coord_max.x <= pos.x ||
|
||||
|
Loading…
Reference in New Issue
Block a user