Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: vertical retrace



> Is it possible to sync to the vertical retrace in Carbon? OSX? I am
> getting a lot of shimmering on the screen as I update, and I have heard
> that the VBL interrupt is used to eliminate that in games.

Hmm. I just realized you said shimmering. I do not think I would describe
the sort of image tearing you get from lack of VBL sync as shimmering.
Lack of VBL sync can cause moving images to appear to momentarily fracture
along a horizontal line, a process called tearing. It is usually not that
obvious, except in a few cases usually involving fast motion of tall
objects, typically with high contrast -- light objects drawn over dark
ones or vice versa. If this is what you see, please forgive the following
unrelated discussion.

However, there are lots of ways to get what I think of as shimmering --
flickery areas on screen that may seem ghostly or unreal. Shimmering can
be quite disturbing. All of them have to do with either erasing live on
screen or sending unfinished frames to the screen:

You can see shimmering effects if you draw directly to the screen and
erase live on the screen before drawing the next frame. I suppose proper
VBL sync could hide said shimmers, but the VBL is not really the problem.
You should not be rendering directly to the screen like that. This is
because you A) get shimmering because all of your drawing and erasing is
being rendered live on screen for the user to see and B) drawing directly
to the screen is a no-no. Instead, draw to an offscreen drawing surface
(such as the window's back buffer) making sure that you do all your
erasing there and use a OS provided blitting function (such as
QDFlushPortBuffer) to copy the dirty areas to the screen when the frame is
done. This way, only correct fully rendered images ever end up on screen.
Also, because offscreen drawing areas are cacheable, it is usually faster
to render offscreen, even though you added a copy step.

Calling dcbz on VRAM before copying your backbuffer to it will also cause
shimmering. You may have done this if you wrote your own function to copy
your offscreen drawing surface to the screen. Calling dcbz on VRAM should
never be done -- VRAM is not cacheable, meaning you take a nice long
exception for each such dcbz. The exception zeros out the VRAM bits
before your blitter overwrites them, so you will see shimmery areas where
the beam manages to traverse the area being zeroed during the exception.
Once again: drawing directly to the screen is a no-no.

Failure to call LockPortBits before writing directly to the window back
buffer can cause direct writing to the screen when you thought you were
writing to the back buffer, leading to the above mentioned problems:

http://developer.apple.com/qa/qa2001/qa1015.html

Done just wrong, you could end up drawing your entire image directly to
the screen by mistake and then immediately erase it when you flush the
empty backbuffer to he screen. :-) That would look shimmery too.

Also calling QDFlushPortBuffer, TEIdle or WaitNextEvent before you finish
drawing a video frame to a window backbuffer can cause partially rendered
images to end up on screen. This may have a shimmery appearance.

http://developer.apple.com/technotes/tn/tn2051.html#Section3
http://developer.apple.com/techpubs/macosx/Essentials/Performance/Carbon/Carbon_and___X_Graphics.html

---------------------------------------------------
Ian Ollmann, Ph.D. email@hidden
---------------------------------------------------
_______________________________________________
mac-games-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/mac-games-dev
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.