graphics: Improve speed when getting elements from geo matrices

This commit is contained in:
Hajime Hoshi 2017-01-19 12:12:20 +09:00
parent 71a4465c6f
commit eec59d5cf8
3 changed files with 20 additions and 15 deletions

View File

@ -152,7 +152,7 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
}
}
w, h := image.impl.restorable.Size()
vs := vertices(parts, w, h, &options.GeoM)
vs := vertices(parts, w, h, &options.GeoM.impl)
if len(vs) == 0 {
return nil
}

View File

@ -18,20 +18,23 @@ package ebiten
import (
"github.com/gopherjs/gopherjs/js"
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/graphics"
)
func vertices(parts ImageParts, width, height int, geo *GeoM) []float32 {
func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 {
// TODO: This function should be in graphics package?
totalSize := graphics.QuadVertexSizeInBytes() / 4
l := parts.Len()
vs := js.Global.Get("Float32Array").New(l * totalSize)
g0 := geo.Element(0, 0)
g1 := geo.Element(0, 1)
g2 := geo.Element(1, 0)
g3 := geo.Element(1, 1)
g4 := geo.Element(0, 2)
g5 := geo.Element(1, 2)
g := geo.Elements()
g0 := g[0]
g1 := g[1]
g2 := g[3]
g3 := g[4]
g4 := g[2]
g5 := g[5]
w := 1.0
h := 1.0
for w < float64(width) {

View File

@ -17,20 +17,22 @@
package ebiten
import (
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/graphics"
)
func vertices(parts ImageParts, width, height int, geo *GeoM) []float32 {
func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 {
// TODO: This function should be in graphics package?
totalSize := graphics.QuadVertexSizeInBytes() / 4
l := parts.Len()
vs := make([]float32, l*totalSize)
g0 := float32(geo.Element(0, 0))
g1 := float32(geo.Element(0, 1))
g2 := float32(geo.Element(1, 0))
g3 := float32(geo.Element(1, 1))
g4 := float32(geo.Element(0, 2))
g5 := float32(geo.Element(1, 2))
g := geo.Elements()
g0 := float32(g[0])
g1 := float32(g[1])
g2 := float32(g[3])
g3 := float32(g[4])
g4 := float32(g[2])
g5 := float32(g[5])
w := float32(1)
h := float32(1)
for w < float32(width) {