optimize batch draw (reduce allocations)
This commit is contained in:
parent
268e1b72f5
commit
c8627e1e93
16
batch.go
16
batch.go
|
@ -80,24 +80,24 @@ func (b *Batch) SetMaskColor(c color.Color) {
|
||||||
type batchTriangles struct {
|
type batchTriangles struct {
|
||||||
Triangles
|
Triangles
|
||||||
trans Triangles
|
trans Triangles
|
||||||
|
data TrianglesData
|
||||||
|
|
||||||
batch *Batch
|
batch *Batch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bt *batchTriangles) Draw() {
|
func (bt *batchTriangles) Draw() {
|
||||||
// need to apply transforms and mask color and picture bounds
|
// need to apply transforms and mask color and picture bounds
|
||||||
trans := make(TrianglesData, bt.Len())
|
bt.data.Update(bt.Triangles)
|
||||||
trans.Update(bt.Triangles)
|
for i := range bt.data {
|
||||||
for i := range trans {
|
|
||||||
transPos := bt.batch.mat.Mul3x1(mgl32.Vec3{
|
transPos := bt.batch.mat.Mul3x1(mgl32.Vec3{
|
||||||
float32(trans[i].Position.X()),
|
float32(bt.data[i].Position.X()),
|
||||||
float32(trans[i].Position.Y()),
|
float32(bt.data[i].Position.Y()),
|
||||||
1,
|
1,
|
||||||
})
|
})
|
||||||
trans[i].Position = V(float64(transPos.X()), float64(transPos.Y()))
|
bt.data[i].Position = V(float64(transPos.X()), float64(transPos.Y()))
|
||||||
trans[i].Color = trans[i].Color.Mul(bt.batch.col)
|
bt.data[i].Color = bt.data[i].Color.Mul(bt.batch.col)
|
||||||
//TODO: texture
|
//TODO: texture
|
||||||
}
|
}
|
||||||
bt.trans.Update(&trans)
|
bt.trans.Update(&bt.data)
|
||||||
bt.batch.cont.Append(bt.trans)
|
bt.batch.cont.Append(bt.trans)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue