Re: Getting the best frame rate for NSView drawing
Re: Getting the best frame rate for NSView drawing
- Subject: Re: Getting the best frame rate for NSView drawing
- From: Uli Kusterer <email@hidden>
- Date: Fri, 30 Mar 2012 19:19:10 +0200
On 28.03.2012, at 09:36, Kenneth Baxter wrote:
> For testing purposes, I have a view that is 5,000 x 5,000 and have 100 of my objects which are placed randomly and size 200 x 400.
FWIW, I wrote a little game for a presentation at a conference once:
On the page http://macoun.de/material2010 there's a session with my name, with a link to the source code: http://macoun.de/wp-content/uploads/2010/11/5GS10.zip
Maybe I do something different from you that helps you track down why it's so slow for you with pure Quartz. Though I didn't really write this to be super-fast either. I only use the dirty rect, which means you get huge boxes if two objects that are at opposite ends of the scene change.
> For each object, I save the graphics state, transform my coordinates, clip to the bounds of the object, draw it, and then restore the graphics state.
Have you tried not clipping? Just to see what the performance difference is? If your cached image is already clipped, that would help. Also, for the objects that change, do your frames change uniquely, or could you cache several frames independently? E.g. in my game, I have about 5 frames for the player, which I just rotate through. They're images in my case, but maybe you have something that you could draw once beforehand, then reuse.
Also, you might be able to share frames between sprites, thus reducing the number of images you have to draw.
> This sure does seem to be awfully slow. Instruments tell that the time is all being spent in drawing the object, no matter how I do the drawing.
Some more random thoughts:
1) Are you scaling your images? Intentionally? Accidentally? Have you tried using the drawAtPoint:-methods instead of drawInRect: to draw your images, to make sure you don't incur the cost of scaling?
2) Are you drawing on integral coordinates? Copying a whole pixel from an NSImage onto a whole pixel in your view means it has to interpolate each pixel, instead of just shoveling bytes across.
3) How are you creating your NSImage? The more you let the OS decide the image format, the more likely it is they'll be performant. If you force a certain bit depth or memory layout, you will incur conversion penalties every time you draw.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.masters-of-the-void.com
_______________________________________________
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