ebiten: skip rendering when det is 0 at DrawImage and DrawRectShader

This commit is contained in:
Hajime Hoshi 2024-10-17 20:54:44 +09:00
parent 5fd619eea7
commit 810e45c030

View File

@ -103,11 +103,11 @@ func (i *Image) Fill(clr color.Color) {
i.image.Fill(crf, cgf, cbf, caf, i.adjustedBounds()) i.image.Fill(crf, cgf, cbf, caf, i.adjustedBounds())
} }
func canSkipMipmap(geom GeoM, filter builtinshader.Filter) bool { func canSkipMipmap(det float32, filter builtinshader.Filter) bool {
if filter != builtinshader.FilterLinear { if filter != builtinshader.FilterLinear {
return true return true
} }
return math.Abs(geom.det2x2()) >= 0.999 return math.Abs(float64(det)) >= 0.999
} }
// DrawImageOptions represents options for DrawImage. // DrawImageOptions represents options for DrawImage.
@ -253,6 +253,10 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) {
geoM.Translate(float64(offsetX), float64(offsetY)) geoM.Translate(float64(offsetX), float64(offsetY))
} }
a, b, c, d, tx, ty := geoM.elements32() a, b, c, d, tx, ty := geoM.elements32()
det := a*d - b*c
if det == 0 {
return
}
bounds := img.Bounds() bounds := img.Bounds()
sx0, sy0 := img.adjustPosition(bounds.Min.X, bounds.Min.Y) sx0, sy0 := img.adjustPosition(bounds.Min.X, bounds.Min.Y)
@ -286,7 +290,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) {
skipMipmap := options.DisableMipmaps skipMipmap := options.DisableMipmaps
if !skipMipmap { if !skipMipmap {
skipMipmap = canSkipMipmap(geoM, filter) skipMipmap = canSkipMipmap(det, filter)
} }
i.image.DrawTriangles(srcs, vs, is, blend, dr, [graphics.ShaderSrcImageCount]image.Rectangle{img.adjustedBounds()}, shader.shader, i.tmpUniforms, graphicsdriver.FillRuleFillAll, skipMipmap, false, hint) i.image.DrawTriangles(srcs, vs, is, blend, dr, [graphics.ShaderSrcImageCount]image.Rectangle{img.adjustedBounds()}, shader.shader, i.tmpUniforms, graphicsdriver.FillRuleFillAll, skipMipmap, false, hint)
} }
@ -900,6 +904,9 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
geoM.Translate(float64(offsetX), float64(offsetY)) geoM.Translate(float64(offsetX), float64(offsetY))
} }
a, b, c, d, tx, ty := geoM.elements32() a, b, c, d, tx, ty := geoM.elements32()
if det := a*d - b*c; det == 0 {
return
}
cr, cg, cb, ca := options.ColorScale.elements() cr, cg, cb, ca := options.ColorScale.elements()
vs := i.ensureTmpVertices(4 * graphics.VertexFloatCount) vs := i.ensureTmpVertices(4 * graphics.VertexFloatCount)