From bf163b5617d134b85017f3a774419c2b7fd6c7de Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 1 May 2017 23:23:58 +0900 Subject: [PATCH] graphics: Refactoring: Initialize 'quadFloat32Num' and reuse it --- vertices.go | 6 ++++++ vertices_js.go | 6 ++---- vertices_notjs.go | 6 ++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vertices.go b/vertices.go index dc3664d67..c8d82bd5f 100644 --- a/vertices.go +++ b/vertices.go @@ -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 diff --git a/vertices_js.go b/vertices_js.go index 0df8349d0..7b37a2f04 100644 --- a/vertices_js.go +++ b/vertices_js.go @@ -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) } diff --git a/vertices_notjs.go b/vertices_notjs.go index 47b866a31..2524bb9e6 100644 --- a/vertices_notjs.go +++ b/vertices_notjs.go @@ -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 }