ebiten: Bug fix: Source regions should not be passed when not needed

The source region information affects the condition of merging
graphics commands. To avoid performance issues by the big number of
graphcis commands, do not pass the source region whenever possible.

Fixes #1293
This commit is contained in:
Hajime Hoshi 2020-08-12 02:12:32 +09:00
parent 95022ff1a5
commit d4042a5cfa
2 changed files with 24 additions and 12 deletions

View File

@ -271,11 +271,15 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
is := graphics.QuadIndices()
var sr driver.Region
sr = driver.Region{
X: float32(bounds.Min.X),
Y: float32(bounds.Min.Y),
Width: float32(bounds.Dx()),
Height: float32(bounds.Dy()),
// Pass the source region only when the shader is used, since this affects the condition of merging graphics
// commands (#1293).
if options.Shader != nil {
sr = driver.Region{
X: float32(bounds.Min.X),
Y: float32(bounds.Min.Y),
Width: float32(bounds.Dx()),
Height: float32(bounds.Dy()),
}
}
srcs := [graphics.ShaderImageNum]*mipmap.Mipmap{img.mipmap}
@ -430,11 +434,15 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
var sr driver.Region
b := img.Bounds()
sr = driver.Region{
X: float32(b.Min.X),
Y: float32(b.Min.Y),
Width: float32(b.Dx()),
Height: float32(b.Dy()),
// Pass the source region only when the shader is used, since this affects the condition of merging graphics
// commands (#1293).
if options.Shader != nil || options.Address != AddressUnsafe {
sr = driver.Region{
X: float32(b.Min.X),
Y: float32(b.Min.Y),
Width: float32(b.Dx()),
Height: float32(b.Dy()),
}
}
var srcs [graphics.ShaderImageNum]*mipmap.Mipmap

View File

@ -337,8 +337,12 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
vertices[i*graphics.VertexFloatNum+2] += oxf
vertices[i*graphics.VertexFloatNum+3] += oyf
}
sourceRegion.X += oxf
sourceRegion.Y += oyf
// sourceRegion can be delibarately empty when this is not needed in order to avoid unexpected
// performance issue (#1293).
if sourceRegion.Width != 0 && sourceRegion.Height != 0 {
sourceRegion.X += oxf
sourceRegion.Y += oyf
}
}
var offsets [graphics.ShaderImageNum - 1][2]float32