From 40b1948baa7b7fa5d05211d33ea970d4754f851a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 20 Feb 2018 01:17:21 +0900 Subject: [PATCH] graphics: Stop unnecessary copy of elements --- internal/affine/colorm.go | 2 +- internal/graphics/program.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/affine/colorm.go b/internal/affine/colorm.go index c81dcb128..079ccbb2f 100644 --- a/internal/affine/colorm.go +++ b/internal/affine/colorm.go @@ -44,7 +44,7 @@ var ( // The initial value is identity. type ColorM struct { // When elements is nil, this matrix is identity. - // elements is immutable and a new array must be created when updating. + // elements are immutable and a new array must be created when updating. body []float32 translate []float32 } diff --git a/internal/graphics/program.go b/internal/graphics/program.go index 649127439..02317364a 100644 --- a/internal/graphics/program.go +++ b/internal/graphics/program.go @@ -271,14 +271,16 @@ func (s *openGLState) useProgram(proj []float32, texture opengl.Texture, sourceW if s.lastColorMatrix == nil { s.lastColorMatrix = make([]float32, 16) } - copy(s.lastColorMatrix, esBody) + // ColorM's elements are immutable. It's OK to hold the reference without copying. + s.lastColorMatrix = esBody } if !areSameFloat32Array(s.lastColorMatrixTranslation, esTranslate) { c.UniformFloats(program, "color_matrix_translation", esTranslate) if s.lastColorMatrixTranslation == nil { s.lastColorMatrixTranslation = make([]float32, 4) } - copy(s.lastColorMatrixTranslation, esTranslate) + // ColorM's elements are immutable. It's OK to hold the reference without copying. + s.lastColorMatrixTranslation = esTranslate } if program == s.programLinear {