• 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: Bitmaps and Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Bitmaps and Cocoa (From: Darren Ford <email@hidden>)

  • Prev by Date: Forum for advanced Cocoa questions
  • Next by Date: Re: Becomeing foreground process [was XRe: Problem receiving key events in CLI created window]
  • Previous by thread: Bitmaps and Cocoa
  • Next by thread: Re: Bitmaps and Cocoa
  • Index(es):
    • Date
    • Thread