0% found this document useful (0 votes)
26 views5 pages

Precise Behavior of SDL - Flip and Hardware Buffers - SDL Development - Simple Directmedia Layer

The behavior of the SDL_Flip() function depends on the platform. It may return immediately after changing the display pointer, return immediately before the flip occurs at vertical retrace, or return after the flip occurs at vertical retrace. The next surface lock after a flip will always return after the current frame is displayed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

Precise Behavior of SDL - Flip and Hardware Buffers - SDL Development - Simple Directmedia Layer

The behavior of the SDL_Flip() function depends on the platform. It may return immediately after changing the display pointer, return immediately before the flip occurs at vertical retrace, or return after the flip occurs at vertical retrace. The next surface lock after a flip will always return after the current frame is displayed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Precise behavior of SDL_flip() and hardware buffers

Bob_Pendleton 1 May 20, 2003, 12:50pm

The documentation for SDL_Flip() (http://sdldoc.csn.ul.ie/sdlflip.php)


states:

On hardware that supports double-buffering, this function sets up a


flip and returns. The hardware will wait for vertical retrace, and
then swap video buffers before the next video surface blit or lock
will return.

To me that means that the call returns immediately but the next action
that locks the buffer will be forced to wait until after the next
vertical retrace before the lock can complete. But, when I test this
function on my machine I see that SDL_Flip() does not return
immediately. It appears to return after the next vertical retrace. My
guess is that the documentation is correct for some platforms and wrong
for others. My guess is that depending on the platform the actual
behavior of SDL_Flip() is all of the following:

1. The display pointer changes immediately, you may get tearing,


SDL_Flip() returns instantly.

2. The flip takes place at the next video retrace, but SDL_Flip()
returns immediately. Possibly returning before the flip has happened.

3. The Flip takes place at the next video retrace, and SDL_Flip()
returns after the flip has happened.

Can someone please confirm or deny my guesses? To write portable code it


is necessary to know all the different ways that SDL_Flip() behaves.

Thanks!

Bob Pendleton--

±----------------------------------+

Bob Pendleton: independent writer +


and programmer. +
email: Bob at Pendleton.com +
±----------------------------------+

Julien_Pauty 2 May 21, 2003, 1:15am

Hi I’am also interested by these questions. Here is the problem, which may
be included in one of these questions, I have encountered with SDL_Flip.
I have made my game’s logic independent of the video frame rate. My idea was
to move sprites according to the time elapsed since the last move, and to
display as much frames as possible. This worked fine under linux with X or
the frame buffer, and under windows in windowed mode. In fullscreen
(DoubleBuf) mode with Windows the game speed was well synchronized on the
game clock (objets’ speed was ok) but I lose a lot of frames. I found that
calling SDL_Flip only every 7-10 ms solved the problem, but I wasn’t
satisfied by this solution. My actual solution is to embed the SDL_Flip into
a loop to test the returned result: while (SDL_Flip(screen) < 0); . This
means that some calls to SDL_FLip can fail. What are the reason to SDL_Flip
fail ? Is it a directX related reason ? If the answer completly unrelated
to Bob’s questions please change the subject to something like “SDL_FLip
errors” to not polute this thread.

Thanks

Julien> ----- Original Message -----

From: [email protected] (Bob Pendleton)


To: “SDL Mailing List”
Sent: Tuesday, May 20, 2003 9:49 PM
Subject: [SDL] Precise behavior of SDL_flip() and hardware buffers.

The documentation for SDL_Flip() (http://sdldoc.csn.ul.ie/sdlflip.php)


states:

On hardware that supports double-buffering, this function sets up a


flip and returns. The hardware will wait for vertical retrace, and
then swap video buffers before the next video surface blit or lock
will return.

To me that means that the call returns immediately but the next action
that locks the buffer will be forced to wait until after the next
vertical retrace before the lock can complete. But, when I test this
function on my machine I see that SDL_Flip() does not return
immediately. It appears to return after the next vertical retrace. My
guess is that the documentation is correct for some platforms and wrong
for others. My guess is that depending on the platform the actual
behavior of SDL_Flip() is all of the following:

1. The display pointer changes immediately, you may get tearing,


SDL_Flip() returns instantly.

2. The flip takes place at the next video retrace, but SDL_Flip()
returns immediately. Possibly returning before the flip has happened.

3. The Flip takes place at the next video retrace, and SDL_Flip()
returns after the flip has happened.

Can someone please confirm or deny my guesses? To write portable code it


is necessary to know all the different ways that SDL_Flip() behaves.

Thanks!

Bob Pendleton

±----------------------------------+

Bob Pendleton: independent writer +


and programmer. +
email: Bob at Pendleton.com +
±----------------------------------+

SDL mailing list


SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

slouken 3 May 21, 2003, 10:21pm

The documentation for SDL_Flip() (http://sdldoc.csn.ul.ie/sdlflip.php)


states:

On hardware that supports double-buffering, this function sets up a


flip and returns. The hardware will wait for vertical retrace, and
then swap video buffers before the next video surface blit or lock
will return.

To me that means that the call returns immediately but the next action
that locks the buffer will be forced to wait until after the next
vertical retrace before the lock can complete. But, when I test this
function on my machine I see that SDL_Flip() does not return
immediately. It appears to return after the next vertical retrace. My
guess is that the documentation is correct for some platforms and wrong
for others. My guess is that depending on the platform the actual
behavior of SDL_Flip() is all of the following:

1. The display pointer changes immediately, you may get tearing,


SDL_Flip() returns instantly.

2. The flip takes place at the next video retrace, but SDL_Flip()
returns immediately. Possibly returning before the flip has happened.

3. The Flip takes place at the next video retrace, and SDL_Flip()
returns after the flip has happened.

Can someone please confirm or deny my guesses? To write portable code it


is necessary to know all the different ways that SDL_Flip() behaves.
I believe this is correct. Whenever possible I’ve tried to implement #2.
What is always true is that the next surface lock after a flip will return
after the current framebuffer has been displayed to the end user, and if
vertical retrace sync is available, after the vertical retrace.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Bob_Pendleton 4 May 22, 2003, 5:16am

The documentation for SDL_Flip() (http://sdldoc.csn.ul.ie/sdlflip.php)


states:

On hardware that supports double-buffering, this function sets up a


flip and returns. The hardware will wait for vertical retrace, and
then swap video buffers before the next video surface blit or lock
will return.

To me that means that the call returns immediately but the next action
that locks the buffer will be forced to wait until after the next
vertical retrace before the lock can complete. But, when I test this
function on my machine I see that SDL_Flip() does not return
immediately. It appears to return after the next vertical retrace. My
guess is that the documentation is correct for some platforms and wrong
for others. My guess is that depending on the platform the actual
behavior of SDL_Flip() is all of the following:

1. The display pointer changes immediately, you may get tearing,


SDL_Flip() returns instantly.

2. The flip takes place at the next video retrace, but SDL_Flip()
returns immediately. Possibly returning before the flip has happened.

3. The Flip takes place at the next video retrace, and SDL_Flip()
returns after the flip has happened.

Can someone please confirm or deny my guesses? To write portable code it


is necessary to know all the different ways that SDL_Flip() behaves.

I believe this is correct. Whenever possible I’ve tried to implement #2.


What is always true is that the next surface lock after a flip will return
after the current framebuffer has been displayed to the end user, and if
vertical retrace sync is available, after the vertical retrace.
See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Thanks Sam, that is the information I needed.

Bob PendletonOn Thu, 2003-05-22 at 00:20, Sam Lantinga wrote:

SDL mailing list


SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

±----------------------------------+

Bob Pendleton: independent writer +


and programmer. +
email: Bob at Pendleton.com +
±----------------------------------+

You might also like