mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
mipmap: Bug fix: Crash at DrawTrianglesWithShader
This commit is contained in:
parent
c4c9771b78
commit
52773e1d12
@ -88,7 +88,9 @@ func (m *Mipmap) Pixels(x, y, width, height int) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, images []*Mipmap) {
|
||||
level := math.MaxInt32
|
||||
level := 0
|
||||
if src != nil && !src.volatile && filter != driver.FilterScreen {
|
||||
level = math.MaxInt32
|
||||
for i := 0; i < len(indices)/3; i++ {
|
||||
const n = graphics.VertexFloatNum
|
||||
dx0 := vertices[n*indices[3*i]+0]
|
||||
@ -103,16 +105,17 @@ func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16
|
||||
dy2 := vertices[n*indices[3*i+2]+1]
|
||||
sx2 := vertices[n*indices[3*i+2]+2]
|
||||
sy2 := vertices[n*indices[3*i+2]+3]
|
||||
if l := src.mipmapLevelFromDistance(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, filter); level > l {
|
||||
if l := mipmapLevelFromDistance(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, filter); level > l {
|
||||
level = l
|
||||
}
|
||||
if l := src.mipmapLevelFromDistance(dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, filter); level > l {
|
||||
if l := mipmapLevelFromDistance(dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, filter); level > l {
|
||||
level = l
|
||||
}
|
||||
if l := src.mipmapLevelFromDistance(dx2, dy2, dx0, dy0, sx2, sy2, sx0, sy0, filter); level > l {
|
||||
if l := mipmapLevelFromDistance(dx2, dy2, dx0, dy0, sx2, sy2, sx0, sy0, filter); level > l {
|
||||
level = l
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if colorm != nil && colorm.ScaleOnly() {
|
||||
body, _ := colorm.UnsafeElements()
|
||||
@ -257,13 +260,10 @@ func (m *Mipmap) disposeMipmaps() {
|
||||
}
|
||||
|
||||
// mipmapLevel returns an appropriate mipmap level for the given distance.
|
||||
func (m *Mipmap) mipmapLevelFromDistance(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1 float32, filter driver.Filter) int {
|
||||
func mipmapLevelFromDistance(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1 float32, filter driver.Filter) int {
|
||||
if filter == driver.FilterScreen {
|
||||
return 0
|
||||
}
|
||||
if m.volatile {
|
||||
return 0
|
||||
}
|
||||
|
||||
d := (dx1-dx0)*(dx1-dx0) + (dy1-dy0)*(dy1-dy0)
|
||||
s := (sx1-sx0)*(sx1-sx0) + (sy1-sy0)*(sy1-sy0)
|
||||
|
Loading…
Reference in New Issue
Block a user