Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.84k stars 819 forks source link

Reusing saved RenderState in DisplayObjectContainer? #920

Closed vroad closed 7 years ago

vroad commented 7 years ago

DisplayObjectContainer saves current render state every time when it renders a child object, but is this unavoidable? I think that you could do something like this instead:

  1. Save current render state to stack if you haven't done it already. (Just call BatchProcessor.fillToken if you did that already)
  2. Render child object
  3. Copy render state from saved state, but don't change _stateStackPos
  4. Decrement _stateStackPos outside of for-loop

That way you don't need to call Painter.pushState every time before rendering child objects, and will help in improving the performance of DisplayObjectContainer which has many child objects. I've tried this in my repo and seems to be working fine.

PrimaryFeather commented 7 years ago

Thanks a lot for the suggestion, and sorry for the late reply (I was on a vacation).

That sounds like a very smart idea! That push/pop stuff is some of the most expensive in Starling's render loop, so it would be extremely helpful to optimize this.

I'll definitely try this out!! 😄

PrimaryFeather commented 7 years ago

Thanks again for bringing this up! This avoids lots of unnecessary CPU cycles. 👍