graphics: Stop unnecessary copy of elements

This commit is contained in:
Hajime Hoshi 2018-02-20 01:17:21 +09:00
parent f1f7e5bcec
commit 40b1948baa
2 changed files with 5 additions and 3 deletions

View File

@ -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
}

View File

@ -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 {