Re: Bitmaps and Cocoa
Re: Bitmaps and Cocoa
- Subject: Re: Bitmaps and Cocoa
- From: Dietmar Planitzer <email@hidden>
- Date: Sun, 20 Jul 2003 23:45:43 +0200
On Saturday, July 19, 2003, at 11:28 PM, Darren Ford wrote:
<snip>
All of this appears to work fine, however I was wondering whether
there was a more elegant way of approaching raw bitmaps? I'm
concerned with the current implementation in that it is not thread
safe (my accessing the data is, however with Cocoa's automatic
redrawing there's the potential that cocoa tries to read at the same
time I'm trying to write my raw data).
Like you, I'm also currently working on the integration of a ray-tracer
into a Cocoa GUI.
In this project the ray-tracer runs in its own thread and dumbs
scanline by scanline into an offscreen bitmap. Everytime the tracer has
finished one scanline, it invokes a callback which the Cocoa GUI
registered with it before the rendering process started. This callback
then simply takes advantage of the
-performSelectorOnMainThread:withObject:waitUntilDone: method to
execute the display update method on the main thread.
The display update method then uses the often overlooked, but very
handy NSDrawBitmap() AppKit function to draw the newly computed
scanline(s) to the screen (-lockFocusIfCanDraw, NSDrawBitmap(),
-unlockFocus, [[self window] flushWindow] { don't forget this !}).
Using NSDrawBitmap() has the advantage that you don't need to construct
an NSImage and/or NSBitmapImageRep just to draw some pixels into a
view. Just in case you don't know yet: Its not necessary to wrap a
NSBitmapImageRep with an NSImage in order to draw a bitmap. Just tell
the NSBitmapImageRep to draw itself by calling -draw on it.
Another thing you might consider for onscreen display is a frame rate
limiter. I.e. my code only calls NSDrawBitmap() and -flushWindow at
most 24 times per second. This made progressive display of simple
scenes much faster.
Regards,
Dietmar Planitzer
_______________________________________________
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.