graphics: Refactoring: Initialize 'quadFloat32Num' and reuse it

This commit is contained in:
Hajime Hoshi 2017-05-01 23:23:58 +09:00
parent 4e22bd770f
commit bf163b5617
3 changed files with 10 additions and 8 deletions

View File

@ -14,8 +14,14 @@
package ebiten
import (
"github.com/hajimehoshi/ebiten/internal/graphics"
)
// texelAdjustment represents a number to be used to adjust texel.
// Texels are adjusted by amount propotional to inverse of texelAdjustment.
// This is necessary not to use unexpected pixels outside of texels.
// See #317.
const texelAdjustment = 256
var quadFloat32Num = graphics.QuadVertexSizeInBytes() / 4

View File

@ -20,14 +20,12 @@ 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 *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)
vs := js.Global.Get("Float32Array").New(l * quadFloat32Num)
g := geo.UnsafeElements()
g0 := g[0]
g1 := g[1]
@ -103,7 +101,7 @@ func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 {
vs.SetIndex(n+38, g4)
vs.SetIndex(n+39, g5)
n += totalSize
n += quadFloat32Num
}
return vs.Interface().([]float32)
}

View File

@ -18,14 +18,12 @@ package ebiten
import (
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/graphics"
)
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)
vs := make([]float32, l*quadFloat32Num)
g := geo.UnsafeElements()
g0 := float32(g[0])
g1 := float32(g[1])
@ -102,7 +100,7 @@ func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 {
vs[n+38] = g4
vs[n+39] = g5
n += totalSize
n += quadFloat32Num
}
return vs
}