                       How Rendering is Done

                        Matthew Leditschke
                   (Matthew.Leditschke@cselt.it)

Aim:
====

To draw the objects which make up the scene, in back to front order,
performing the mimimal amount of drawing.


How is this achieved:
=====================

Before drawing the objects in the scene, a pre-render traversal of the
tree is performed, enabling all objects to determine where they will
be displayed (cumulation of all of the Transform2D nodes), and what
there drawing order is (also given by the Transform2D node).

During this traversal, nodes which need to be drawn register
themselves with the VisualRenderer, using the AddToDrawList method.
Even if a node has not changed since, it must still register, as the
VisualRenderer will decide what needs to be redrawn.

Once the pre-render traversal is finished, the VisualRenderer sorts
the list of Drawable nodes based on their draw order, and then draws
the nodes in back-to-front order.

Rather than just drawing all nodes in the list, the VisualRenderer
determines the minimum amount of drawing which needs to be performed,
based on which nodes have changed, which ones are transparent, and
their bounding boxes.  This is done as follows:

1. Start with an empty rectangle which indicates what part of the
   final output image has changed, and a second empty rectangle which
   stores what part of the final output image is made up of
   transparent objects.

2. Go through the list of nodes, from front to back, doing the following:

   a. If this node has changed and hence needs to be redrawn, then add
      its bounding rectangle to the overall changed area bounding rectangle.

   b. If this node is transparent (which means that it does not
      completely fill its bounding rectangle), then add its bounding
      rectangle to the overall transparent area bounding rectangle.  

3. Before drawing the nodes, some of the output frame needs to be set
   to the black background before drawing.  This area is indicated by
   the overall transparent area bounding rectangle.

4. Draw all of the node, in back-to-front order, only drawing the
   parts of the objects which lie within the overall changed area
   bounding rectangle.

   Nodes which have not changed are only drawn if they intersect with
   the transparent area, or something behind them has been redrawn.


More details:
=============

Nodes which are to be traversed are to be defined as inheriting from
the Traversable class.  The node then only needs to implement the
PreRender() method, and the Print() method (which is intended only for
debugging purposes).

Nodes which are going to register with the VisualRenderer so that they
can be drawn need to be defined as inheriting from the DrawableNode
class.  The nodes then needs to provide implementation for the
following methods:
  NeedsDrawing()  - return TRUE if the object needs to be drawn.
  IsTransparent() - return TRUE if the object does not entirely fill its
                    bounding box.
  Draw()          - draw the portion of the object which lies within the
                    given rectangle.

There is also a default implementation for PreRender(), which stores
the value of the transform and drawing order, and also a default
implementation for GetDrawingOrder().  These methods can be overridden
if required.

To return the bounding rectangle, the defauly method is to set the
value of the bounding rectangle in PreRender().  A node can override
the GetBoundingBox() method if it wants to do this another way.

