Reduce division operators

It looks like runtime.wasmDiv takes account for a big part at CPU
usages with examples/sprites.
This commit is contained in:
Hajime Hoshi 2019-09-27 03:28:07 +09:00
parent 3cf867035d
commit af6bda48c3
2 changed files with 4 additions and 2 deletions

View File

@ -192,7 +192,8 @@ func (q *commandQueue) Flush() {
const dstAdjustmentFactor = 1.0 / 256.0 const dstAdjustmentFactor = 1.0 / 256.0
const texelAdjustmentFactor = 1.0 / 512.0 const texelAdjustmentFactor = 1.0 / 512.0
for i := 0; i < q.nvertices/graphics.VertexFloatNum; i++ { n := q.nvertices / graphics.VertexFloatNum
for i := 0; i < n; i++ {
s := q.srcSizes[i] s := q.srcSizes[i]
// Convert pixels to texels. // Convert pixels to texels.

View File

@ -303,7 +303,8 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
ox, oy, _, _ := img.region() ox, oy, _, _ := img.region()
oxf, oyf := float32(ox), float32(oy) oxf, oyf := float32(ox), float32(oy)
for i := 0; i < len(vertices)/graphics.VertexFloatNum; i++ { n := len(vertices) / graphics.VertexFloatNum
for i := 0; i < n; i++ {
vertices[i*graphics.VertexFloatNum+2] += oxf vertices[i*graphics.VertexFloatNum+2] += oxf
vertices[i*graphics.VertexFloatNum+3] += oyf vertices[i*graphics.VertexFloatNum+3] += oyf
vertices[i*graphics.VertexFloatNum+4] += oxf vertices[i*graphics.VertexFloatNum+4] += oxf