(ren *RenderComponent, space *SpaceComponent)
| 321 | } |
| 322 | |
| 323 | func (s *basicShader) makeModelMatrix(ren *RenderComponent, space *SpaceComponent) *engo.Matrix { |
| 324 | // Instead of creating a new model matrix every time, we instead store a global one as a struct member |
| 325 | // and just reset it for every sprite. This prevents us from allocating a bunch of new Matrix instances in memory |
| 326 | // ultimately saving on GC activity. |
| 327 | // When a negative scale is used, we just want to flip the sprite, so this |
| 328 | // makes up for the translation that happens on the openGL side. |
| 329 | transX := space.Position.X |
| 330 | transY := space.Position.Y |
| 331 | if ren.Scale.X < 0 { |
| 332 | transX -= ren.Drawable.Width() * ren.Scale.X |
| 333 | } |
| 334 | if ren.Scale.Y < 0 { |
| 335 | transY -= ren.Drawable.Height() * ren.Scale.Y |
| 336 | } |
| 337 | s.modelMatrix.Identity().Scale(engo.GetGlobalScale().X, engo.GetGlobalScale().Y).Translate(transX, transY) |
| 338 | if space.Rotation != 0 { |
| 339 | s.modelMatrix.Rotate(space.Rotation) |
| 340 | } |
| 341 | s.modelMatrix.Scale(ren.Scale.X, ren.Scale.Y) |
| 342 | return s.modelMatrix |
| 343 | } |
| 344 | |
| 345 | func (s *basicShader) generateBufferContent(ren *RenderComponent, space *SpaceComponent, buffer []float32) bool { |
| 346 | // We shouldn't use SpaceComponent to get width/height, because this usually already contains the Scale (which |
no test coverage detected