From 8219c56dd8a5fc61fdbc67b0e3521ca2c285e3bf Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 23 Oct 2016 03:37:21 +0900 Subject: [PATCH] graphics: Accurate calculation of vbo values --- imageparts.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/imageparts.go b/imageparts.go index be1400c5c..c67b5007c 100644 --- a/imageparts.go +++ b/imageparts.go @@ -84,9 +84,10 @@ type textureQuads struct { } func (t *textureQuads) vertices() []uint8 { - size := graphics.QuadVertexSizeInBytes() + totalSize := graphics.QuadVertexSizeInBytes() + oneSize := totalSize / 4 l := t.parts.Len() - vertices := make([]uint8, l*size) + vertices := make([]uint8, l*totalSize) p := t.parts w, h := t.width, t.height width2p := graphics.NextPowerOf2Int(w) @@ -123,16 +124,16 @@ func (t *textureQuads) vertices() []uint8 { // Use direct assign here. `append` function might be slow on browsers. if endian.IsLittle() { for i, v := range vs { - vertices[size*n+2*i] = uint8(v) - vertices[size*n+2*i+1] = uint8(v >> 8) + vertices[totalSize*n+oneSize*(i/4)+2*(i%4)] = uint8(v) + vertices[totalSize*n+oneSize*(i/4)+2*(i%4)+1] = uint8(v >> 8) } } else { for i, v := range vs { - vertices[size*n+2*i] = uint8(v >> 8) - vertices[size*n+2*i+1] = uint8(v) + vertices[totalSize*n+oneSize*(i/4)+2*(i%4)] = uint8(v >> 8) + vertices[totalSize*n+oneSize*(i/4)+2*(i%4)+1] = uint8(v) } } n++ } - return vertices[:n*size] + return vertices[:n*totalSize] }