Skip to content

Commit

Permalink
Optimize *GLShader.Update() by allocating array before for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl committed Jul 9, 2021
1 parent aae9927 commit bb0a0f4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pixelgl/glshader.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ func NewGLShader(fragmentShader string) *GLShader {

// Update reinitialize GLShader data and recompile the underlying gl shader object
func (gs *GLShader) Update() {
gs.uf = nil
for _, u := range gs.uniforms {
gs.uf = append(gs.uf, glhf.Attr{
Name: u.Name,
Type: u.Type,
})
gs.uf = make([]glhf.Attr, len(gs.uniforms))
for idx := range gs.uniforms {
gs.uf[idx] = glhf.Attr{
Name: gs.uniforms[idx].Name,
Type: gs.uniforms[idx].Type,
}
}

var shader *glhf.Shader
mainthread.Call(func() {
var err error
Expand Down

0 comments on commit bb0a0f4

Please sign in to comment.