Re: NSView drawRect: QuickDraw, CoreGraphics, OpenGL ? DP.1
Re: NSView drawRect: QuickDraw, CoreGraphics, OpenGL ? DP.1
- Subject: Re: NSView drawRect: QuickDraw, CoreGraphics, OpenGL ? DP.1
- From: Nat! <email@hidden>
- Date: Thu, 31 Oct 2002 01:03:45 +0100
Well the original message I got from Dietmar was cc:ed to this list.
It's larger than 8K so it got stuck in moderation. It is still up for
moderation and it's been almost three weeks now. I suspect that the
mail is just lost. I repost it here, because it is very interesting.
It's split in two parts to avoid it's previous fate...
Von: Dietmar Planitzer <email@hidden>
Datum: Sam, 12. Okt 2002 16:21:05 Europe/Berlin
An: Nat! <email@hidden>, <email@hidden>
Betreff: Re: NSView drawRect: QuickDraw, CoreGraphics, OpenGL ?
From: Nat! <email@hidden>
Date: Sat, 12 Oct 2002 02:25:57 +0200
So the suggestions I got from my previous thread "Can I get AppKit to
draw this faster ?", confirmed my impression that AppKit is unsuitable
for performant blitting operations. Offhand I can see four ways to get
what I want
a) write my own "graphics kit" and render into a NSBitmapImageRep. That
would be painful.
b) use OpenGL. Do I still need NSOpenGLView ? Can a NSOpenGLView be
transparent now ? Can I use a mixture of OpenGL calls and AppKit calls
now in 10.2 ? F.i. can I draw a border with NSBezierPath, draw lines
with OpenGL and then put some text over it with NSAttributedString ? I
think I read somewhere that this is possible now.
You can draw via OpenGL into any NSView subclass. You just need to
create an
NSOpenGLContext instance and link that to your view by calling -setView:
with your view on the GL context class.
Since 10.2 its possible to mix Quartz and GL drawing in the same view.
Note
though, that this can be quite slow on machines which do not support
Quartz
Extreme.
c) use CoreGraphics call. I am also unsure whether I can freely mix
CoreGraphics calls and AppKit calls. Is NSGraphicsContext "toll free
bridged" with CGGraphicsContext ?
CGContextRef and NSGraphicsContext are not bridged. You can get the
CGContextRef underlying a NSGraphicsContext by calling its -graphicsPort
method.
You can freely mix Quartz and AppKit drawing calls, because after all,
AppKit's graphics related objects like NSImage, NSBezierPath, NSColor..
are
just wrappers around the corrsponding Quartz calls.
d) Quickdraw. Can I use Quickdraw calls inside drawRect: and how ?
You can use QD calls inside a NSQuickDrawView subclass. However, QD
doesn't
support automatic color matching, anti-aliasing, image interpolation,
vectorized patterns, shadings, functions, affine transformations,
arbitrary
image sources, alpha compositing...
e) what's the Apple suggested way to do performant graphics operations
in Cocoa ?
What I recommend is:
If graphics performance is important to your application, then use
Quartz
calls directly. They give you more performance and also more flexibility
plus access to the full PDF imaging model. Sadly, AppKit especially its
NSImage and NSColor classes have retained the limitations which once DPS
imposed on them. I.e. NSColor doesn't allow one to set the stroke and
fill
colors independetly. Also NSImage doesn't allow one to access the
pixels of
a cached image directly.
NSImage could be made orders of magnitudes more powerful and useful at
the
same time if it would provide a way to tell it what kind of NSImageRep
to
use for its internal cache. I.e. it could provide a choice between an
NSCachedImageRep and a NSBitmapImageRep. The former could be used for
situtations where redraw performance would be more important than direct
pixel access (i.e. would store the data in VRAM) while the latter would
be a
bit slower but allow an application to access pixels directly - just
like a
QD GWorld.
<continued in next mail>
------------------------------------------------------
Some people drink deep from the fountains of life, and
some just gargle. -- DLR
_______________________________________________
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.