mipmap: Bug fix: Use more negative mipmaps when float precision is low

Fixes #1044
This commit is contained in:
Hajime Hoshi 2020-01-03 23:14:41 +09:00
parent c99fd1a742
commit 4c8137ccf5
2 changed files with 15 additions and 3 deletions

View File

@ -26,6 +26,12 @@ import (
"github.com/hajimehoshi/ebiten/internal/shareable"
)
var graphicsDriver driver.Graphics
func SetGraphicsDriver(graphics driver.Graphics) {
graphicsDriver = graphics
}
func BeginFrame() error {
return shareable.BeginFrame()
}
@ -126,8 +132,9 @@ func (m *Mipmap) DrawImage(src *Mipmap, bounds image.Rectangle, geom *GeoM, colo
if level > 6 {
level = 6
}
if level < -6 {
level = -6
// If tooBigScale is 4, level -10 means that the maximum scale is 4 * 2^10 = 4096. This should be enough.
if level < -10 {
level = -10
}
cr, cg, cb, ca := float32(1), float32(1), float32(1), float32(1)
@ -293,7 +300,10 @@ func (m *Mipmap) mipmapLevel(geom *GeoM, width, height int, filter driver.Filter
// Use 'negative' mipmap to render edges correctly (#611, #907).
// It looks like 128 is the enlargement factor that causes edge missings to pass the test TestImageStretch.
const tooBigScale = 128
var tooBigScale float32 = 128
if !graphicsDriver.HasHighPrecisionFloat() {
tooBigScale = 4
}
if sx, sy := geomScaleSize(geom); sx >= tooBigScale || sy >= tooBigScale {
// If the filter is not nearest, the target needs to be rendered with graduation. Don't use mipmaps.
if filter != driver.FilterNearest {

View File

@ -24,10 +24,12 @@ import (
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/internal/hooks"
"github.com/hajimehoshi/ebiten/internal/mipmap"
"github.com/hajimehoshi/ebiten/internal/shareable"
)
func init() {
mipmap.SetGraphicsDriver(uiDriver().Graphics())
shareable.SetGraphicsDriver(uiDriver().Graphics())
graphicscommand.SetGraphicsDriver(uiDriver().Graphics())
}