Yesterday I was working on a dirty rectangles method. What it has boiled down to is something similar to a SpatialGrid, whereby I subdivide the context into smaller blocks and determine which ones contain dirty objects. A dirty object would be anything that would change how an object is rendered: line style, points, position, rotation, etc. Additionally, I'm using the z-index to group objects together into "layers" which are rendered together.
Object2D has the idea of a z-index which allows us to position objects in front of, or behind, other objects. Using this z-index would allow me to organize objects into rendering "bins" and perform updates for each bin as a whole. So each frame that is generated would:
- Go through the bin and see which of the rectangles contain dirty objects
- Capture the contents of those rectangles (the dirty rectangles), and
- Draw the objects for the bin.
Each bin would process separately, so it would be possible to have some background layers (objects that don't change very often), and active layers where things do change often. Then, on the next frame we would restore those dirty rectangles, and start the process again. This should reduce the number of times that we need to reset the entire context before redrawing, which in turn reduces the amount of drawing that must occur each frame.
Additionally, each object that isn't dirty doesn't need to be redrawn because it hasn't changed in any way, further reducing the number of drawing calls that must occur. Objects still need to be processed, but most of the time is spent rendering the objects anyway.
Tonight I plan on implementing this method. If anyone has any input for this method, let me know. I've already considered sparse rectangles, but the simplest (and quickest) way I figure it could be done is via subdivision of the viewport.
No comments:
Post a Comment