• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Speed up drawing of View with multiple NSBezierPaths
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Speed up drawing of View with multiple NSBezierPaths


  • Subject: Re: Speed up drawing of View with multiple NSBezierPaths
  • From: Chuck Soper <email@hidden>
  • Date: Mon, 7 Jul 2003 16:46:41 -0700

At 9:39 PM -0400 7/6/03, publiclook wrote:
On Sunday, July 6, 2003, at 09:09 PM, Chuck Soper wrote:

At 12:13 PM -0700 7/6/03, Henry McGilton wrote:

Depending on your application could you just reduce the number of NSBezierPaths. For example, if you're drawing a thousand rectangles with a thousand NSBezierPaths you should be able to draw a thousand rectangles with one NSBezierPath. Yet, all of the rectangles will need to have the same attributes (line width, color, etc.).

Not quite true. Check out the AppKit function NSRectFillListWithColors and
NSRectFillListWithColorsUsingOperation (this second one for the
benefit of those who will not scroll down half a page)

What was "Not quite true" about my statement? Isn't appending a thousand rectangles to a single path (using appendBezierPathWithRect) significantly faster than using a thousand paths each with a single rectangle? The original question was about general optimization not rectangles.


I don't know about the argument you are having with Mr. McGilton, but adding 1000 rectangles to a single NSBezierPath is probably the SLOWEST way to draw a 1000 rectangles using Cocoa. NSBezierPath and Quartz end up using a N squared algorithm or O of 1000000 to determine if any rectangles overlap so that antialiasing and transparency can be handled correctly.

"Cocoa Programming" contains a length discussion of how to efficiently draw points and rectangles. I just checked and Chapter 13 includes a sample showing different ways to draw thousands of points (and rectangles) and times them. The sample source code is available at www.cocoaprogramming.net. Quartz is wonderful for high quality 2D rendering (it's the best available) but is is dog slow and near useless for quick and dirty "as fast as you can" drawing. Ultimately, you must use OpenGL if you want fast drawing on Mac OS X.


I really should have said polygons instead of rectangles. As Henry McGilton pointed out, using NSRectFillListWithColors would be much faster that my suggestion. I was trying to suggest that reducing the number of NSBezierPath instances might be one way to optimize drawing speed. It sounds like that the original poster is taking the right approach to try to improve his algorithms.

The Points example in Chapter 13 is really useful for learning about optimization. I understand that if optimization does not provide enough of a speed gain then OpenGL may be needed.

Does anyone know of Quartz vs. OpenGL comparisons? I've heard that Quartz is much better with transparency. Is that right? What else is lost in terms of quality by moving from Quartz to OpenGL? What about development time comparisons? Perhaps, this is a question for the OpenGL list.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: Speed up drawing of View with multiple NSBezierPaths (From: publiclook <email@hidden>)

  • Prev by Date: Drawing speed
  • Next by Date: nswindow resize question
  • Previous by thread: Re: Speed up drawing of View with multiple NSBezierPaths
  • Next by thread: Re: Speed up drawing of View with multiple NSBezierPaths
  • Index(es):
    • Date
    • Thread