title: Simple multi-touch drawing application on iOS: Too slow (because drawRect() not additive ?)
body: <p>I am using Quartz 2D to make a simple multi-touch drawing iPad game. The game requires me to draw a new stroke at the finger position every 1/30th of a second.</p>
  
  <p>As far as I know, there is basically no way to get drawRect() to not clear the context every time it is called (self.clearsContextBeforeDrawing = NO; does not work), so my solution was to create a back buffer bitmap (or layer, I can use both), draw every new small stroke into that back buffer every iteration for each finger, and then copy the buffer into the screen every call to drawRect(). In other words:</p>
  
  <pre><code>backlayer = CGLayerCreateWithContext(context, CGSizeMake(W, H), NULL);
  offctx = CGLayerGetContext (backlayer); 
  </code></pre>
  
  <p>and then </p>
  
  <pre><code>- (void)drawRect:(CGRect)rect
  {
  
      CGContextRef context = UIGraphicsGetCurrentContext();
  
      //code here to draw small strokes from old finger position to new one
  
      CGContextDrawLayerInRect(context, [self bounds], backlayer);
  }
  </code></pre>
  
  <p>This worked without problems while I was testing on my iPad 2, but yesterday I noticed that this same code runs much slower on the new iPad 3. The performance is abysmal, slowing my game down from 30FPS all the way to about 5 or so, probably due to the larger, retina display. I have the same problem if I use a separate CGBitmapContext that I create, and then every iteration I create an ImageRef from it and paint it with CGContextDrawImage.</p>
  
  <p>What approach could I take to address this? It seems like I must redraw everything every iteration since it's not good enough to even pass a small rectange to drawRect of what has changed (since every iteration there would need to be several rectangles for each finger)</p>
  
  <p>Thank you</p>