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) { func (g *Game) Draw(screen *ebiten.Image) {
op := &ebiten.DrawTrianglesOptions{} op := &ebiten.DrawTrianglesOptions{}
op.Address = ebiten.AddressUnsafe
indices := []uint16{} indices := []uint16{}
for i := 0; i < g.ngon; i++ { for i := 0; i < g.ngon; i++ {
indices = append(indices, uint16(i), uint16(i+1)%uint16(g.ngon), uint16(g.ngon)) 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 means that texture coordinates wrap to the other side of the texture.
AddressRepeat Address = Address(driver.AddressRepeat) 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. // DrawTrianglesOptions represents options to render triangles on an image.
@ -323,12 +326,15 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
is := make([]uint16, len(indices)) is := make([]uint16, len(indices))
copy(is, indices) copy(is, indices)
b := img.Bounds() var sr driver.Region
sr := driver.Region{ if options.Address != AddressUnsafe {
X: float32(b.Min.X), b := img.Bounds()
Y: float32(b.Min.Y), sr = driver.Region{
Width: float32(b.Dx()), X: float32(b.Min.X),
Height: float32(b.Dy()), 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) i.buffered.DrawTriangles(img.buffered, vs, is, options.ColorM.impl, mode, filter, driver.Address(options.Address), sr, nil, nil)