ebiten: Add AddressUnsafe

Fixes #1219
This commit is contained in:
Hajime Hoshi 2020-07-03 00:33:04 +09:00
parent b83f0acc4d
commit f7757ae025
2 changed files with 13 additions and 6 deletions

View File

@ -121,6 +121,7 @@ func (g *Game) Update(screen *ebiten.Image) error {
func (g *Game) Draw(screen *ebiten.Image) {
op := &ebiten.DrawTrianglesOptions{}
op.Address = ebiten.AddressUnsafe
indices := []uint16{}
for i := 0; i < g.ngon; i++ {
indices = append(indices, uint16(i), uint16(i+1)%uint16(g.ngon), uint16(g.ngon))

View File

@ -234,6 +234,9 @@ const (
// AddressRepeat means that texture coordinates wrap to the other side of the texture.
AddressRepeat Address = Address(driver.AddressRepeat)
// AddressUnsafe means there is no guarantee when the texture coodinates are out of range.
AddressUnsafe Address = Address(driver.AddressUnsafe)
)
// DrawTrianglesOptions represents options to render triangles on an image.
@ -323,13 +326,16 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
is := make([]uint16, len(indices))
copy(is, indices)
var sr driver.Region
if options.Address != AddressUnsafe {
b := img.Bounds()
sr := driver.Region{
sr = driver.Region{
X: float32(b.Min.X),
Y: float32(b.Min.Y),
Width: float32(b.Dx()),
Height: float32(b.Dy()),
}
}
i.buffered.DrawTriangles(img.buffered, vs, is, options.ColorM.impl, mode, filter, driver.Address(options.Address), sr, nil, nil)
}