EDIT: The title was: skip sending vertices when they are out of the region
Inspired by https://github.com/hajimehoshi/ebiten/issues/1130. In theory, we can skip sending the vertices to GPU if they are out of the region. I'm not sure how efficiently we can do it.
Idea: Calculate a circumscribed circle of the region rectangle and a circumscribed circle of a triangle, and see whether those circles are excluded or not.
Before optimization, let's check why pixel can work efficiently first:
Pixel: https://github.com/jrcichra/gollercoaster/blob/62570d8957c033fe121c111bc883e7df919eb24a/game/game.go#L162-L176
Ebiten: https://github.com/jrcichra/gollercoaster/blob/4766cc2cb7e2e36915f656285263117f6341a008/game/game.go#L129-L151
CC @jrcichra
Ah, in the Pixel version, rendering onto the screen happens only when necessary, and that's why.
Yeah and camera movement in pixel, it was easier for me to move around without redrawing.
Because of this line not taking any time: https://github.com/jrcichra/gollercoaster/blob/62570d8957c033fe121c111bc883e7df919eb24a/game/game.go#L129
Thanks!
Yeah and camera movement in pixel, it was easier for me to move around without redrawing.
Ebiten doesn't have a mode not to clear the screen at the beginning of a frame. I'll consider this.
For the camera movement, Ebiten can do a similar thing by (*GeoM).Concat. I think this is a more suitable solution for Ebiten than introducing a global matrix.
Actually I didn't realize Ebiten does this, but this is normally not needed. If you use a tile map, then this will cover the background completely. Clearing the screen at the beginning of the frame should only happen if the back ground is set to a solid color or similar.
@hajimehoshi
I have a commit that adds isClearingSkipped and SetClearingSkipped. Would you like me to PR?
Yes, I appreciate it!
I prefer the name IsClearingScreenSkipped and SetClearingScreenSkipped.
At the moment this is how it's implemented.
if game, ok := c.game.(interface{ Draw(*Image) }); ok {
if !IsClearingSkipped() {
c.offscreen.Clear()
}
game.Draw(c.offscreen)
}
Are there any other clear instructions that should be skipped? I noticed that there were a couple more in uicontext.
There is one more c.offscreen.Clear() call for Update.