Re: Best drawing technology for audio waveforms, envelopes, etc.?
Re: Best drawing technology for audio waveforms, envelopes, etc.?
- Subject: Re: Best drawing technology for audio waveforms, envelopes, etc.?
- From: Wade Tregaskis <email@hidden>
- Date: Mon, 25 Jun 2007 14:53:34 -0700
Generally it isn't recommended to draw large numbers of line
segments in a single NSBezierPath (we've been told the reason is
that NSBezierPath [or, presumably, Quartz 2D] finds self-
intersections in order to render semi-transparent paths correctly,
which is a relatively expensive operation). You might therefore
find that you need to break the drawing up in order to get good
performance if you're using NSBezierPath. Of course, if you do
that, then drawing using a transparent colour will create artefacts
whenever the segments overlap (a workaround would be to draw using
an opaque colour into an NSImage or a CGLayer and then composite the
NSImage or CGLayer to get the transparency).
The common wisdom is that big paths are bad, but this really isn't
true for all cases.
Whether to draw as one big path or multiple subpaths depends on what
you're drawing. There's no hard rules - you'll have to sit down with
Shark and/or a stopwatch and benchmark various methods for your
particular app - but in general, the following are helpful guidelines:
- Line intersection & whatever else Quartz does is indeed very
expensive, but only occurs for lines with a width > 1.0 (presumably
device pixels, not drawing units, so you must be wary of view
transforms and whatnot). Drawing of paths <= 1.0 wide is actually
very very fast.
- If you're line segments overlap a lot, you might find yourself
bandwidth-limited if you draw segments individually, in which case it
is sometimes faster - really - to use a single NSBezierPath (even for
line width > 1.0).
- If your path is very jagged, with sharp angles, NSBezierPath will
take a lot longer (for line width > 1.0) than if your path is
relatively smooth, for the same number of segments in each path. The
difference can be massive - in fact, this is probably the most
significant factor of all the things mentioned here.
- Mitered (default) & bezeled join styles are roughly equivalent in
speed, but the rounded style can be multiple orders of magnitude
slower (again, highly dependent on the path being drawn).
- Disabling antialiasing might give you a slight performance boost,
but in the order of 10%, so probably not worth the tradeoff in
aesthetics.
Generally your biggest gains in line drawing performance come from
reducing how much you're trying to draw - which really is the golden
rule for any drawing. Use an averaging algorithm. Calculate min/
max's and draw a polygon that envelopes these. Use a low-pass filter
if it makes sense. Etc.
I'd highly recommend against writing your own rasterizer - it's not
necessarily too difficult, but you then miss out on all the benefits
of using Quartz, and as I've said, it really shouldn't be necessary
for the vast majority of cases.
(fwiw, I haven't compared Quartz vs OpenGL for line drawing, so I
can't comment if that's a worthwhile area to explore, but some of the
same points apply as for writing your own rasterizer)
Wade
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden