internal/graphicsdriver/opengl: Avoid allocations by escaping to heap

This commit is contained in:
Hajime Hoshi 2021-10-31 22:34:07 +09:00
parent a3eb8933e5
commit 7661147e31
2 changed files with 6 additions and 2 deletions

View File

@ -418,7 +418,9 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
case shaderir.Mat4: case shaderir.Mat4:
gl.UniformMatrix4fv(l, len, false, (*float32)(gl.Ptr(v))) gl.UniformMatrix4fv(l, len, false, (*float32)(gl.Ptr(v)))
default: default:
panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String())) // Copy shaderir.Type value to avoid heap allocation of typ.
t := typ
panic(fmt.Sprintf("opengl: unexpected type: %s", t.String()))
} }
return true return true
} }

View File

@ -384,7 +384,9 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
case shaderir.Mat4: case shaderir.Mat4:
c.ctx.UniformMatrix4fv(int32(l), false, v) c.ctx.UniformMatrix4fv(int32(l), false, v)
default: default:
panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String())) // Copy shaderir.Type value to avoid heap allocation of typ.
t := typ
panic(fmt.Sprintf("opengl: unexpected type: %s", t.String()))
} }
return true return true
} }