How to implement double buffering?

I want to get rid of the tearing effects I have when
using E-UAE (Amiga emulator) on my arcade monitor.
Hence I’m trying to implement VSync in E-UAEs SDL
graphic routines like it was done for XMAME in the
patch linked below.

http://www.mail-archive.com/xmame at toybox.twisted.org.uk/msg06159.html

Alas, I’m not familiar with SDl programming and I my
attempts to do it just in the above linked example
were not successful. What I did is the following:
I set the flags SDL_DOUBLEBUF and SDL_HWSURFACE before
invoking SDL_SetVideoMode. Furthermore I replaced all
SDL_UpdateRect commands by SDL_Flip and set the
environment variable SDL_videodriver to dga. With
these changes I get an OK looking fullscreen picture
as long as nothing moves, but if something starts to
move the lowest 20% of the screen start to flicker
white and the whole stuff slows down dramatically.
May be the reason is that the original command
SDL_UpdateRect (prSDLScreen, 0, first_line,
current_width, last_line - first_line + 1);
updates only a part of the screen, since I have the
impression that exacly the part below the updated rect
is flickering. However, I have replaced this command
by
SDL_Flip(prSDLScreen);
which does not work. So my question is how to do it
properly, do I have to update the rect by a blit
command before flipping or how can I do it?

Thank you in advance___________________________________________________________
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de

the flickering is probably because either you are trying to draw
things too fast or your resolution is too high.

A better bet than vsync is just using a delay…

SDL_Flip( yourscreen );
SDL_Delay( 100 );

What resolution are you running? if it is very high, as you
mentioned, using SDL_UpdateRect or SDL_UpdateRects should work ok, but
then i suggest going OOP

Alex~On 2/13/06, fari mueller wrote:

I want to get rid of the tearing effects I have when
using E-UAE (Amiga emulator) on my arcade monitor.
Hence I’m trying to implement VSync in E-UAEs SDL
graphic routines like it was done for XMAME in the
patch linked below.

http://www.mail-archive.com/xmame at toybox.twisted.org.uk/msg06159.html

Alas, I’m not familiar with SDl programming and I my
attempts to do it just in the above linked example
were not successful. What I did is the following:
I set the flags SDL_DOUBLEBUF and SDL_HWSURFACE before
invoking SDL_SetVideoMode. Furthermore I replaced all
SDL_UpdateRect commands by SDL_Flip and set the
environment variable SDL_videodriver to dga. With
these changes I get an OK looking fullscreen picture
as long as nothing moves, but if something starts to
move the lowest 20% of the screen start to flicker
white and the whole stuff slows down dramatically.
May be the reason is that the original command
SDL_UpdateRect (prSDLScreen, 0, first_line,
current_width, last_line - first_line + 1);
updates only a part of the screen, since I have the
impression that exacly the part below the updated rect
is flickering. However, I have replaced this command
by
SDL_Flip(prSDLScreen);
which does not work. So my question is how to do it
properly, do I have to update the rect by a blit
command before flipping or how can I do it?

Thank you in advance


Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


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


Smith: “…Why, Mr Anderson, Why - Do - You - Persist?”
Neo: “Because I choose to.”
-Matrix Revolutions

Hello !

Jup. Just replacing all UpdateRects is not the way
as these emu seems to update only parts of the screen.

I would do it that way :

Go through the main loop and comment out
all SDL_UpdateRect, SDL_UpdateRects lines

For example :

SDL_UpdateRects …
with
// DBL: SDL_UpdateRects

That way you can search
where you commented out the lines. You can use Search & Replace in
your texteditor making this task easy.

Add a single SDL_Flip (screen) to the main loop.

Then test it, if everything works okay, great.
If some things are not updating any more, take a look at the code
and maybe replace some of the commented
// DBL: things with SDL_Flip (screen)

CU

Hello !

You can easily test if your system supports VSYNCing with SDL:

Just switch to DGA, start testsprite in the SDL test
directory with ./testsprite -fullscreen -flip -hw.
Then look at the nr. testsprite prints out, it should be
in the range of your monitor, tft whatever.

For example if you are using a 60 Hz TFT, it my be something
like 57,58,59,60 Hz.

CU

What resolution are you running?

I’m running a very low resolution, something like
640x260.
I’ll try implementing this delay line, let’s see what
happens then

Go through the main loop and comment out
all SDL_UpdateRect, SDL_UpdateRects lines

Hard for me to tell what the main loop is. I guess the
main update routine is this:
STATIC_INLINE void sdl_flush_block_nolock (struct
vidbuf_description *gfxinfo, int first_line, int
last_line)
{
SDL_UpdateRect (prSDLScreen, 0, first_line,
current_width, last_line - first_line + 1);
}

For me this looks like the right place to enter
SDL_Flip.
The other place where SDL_UpdateRect occurs is here:
static void sdl_flush_clear_screen (struct
vidbuf_description *gfxinfo)
{
DEBUG_LOG (“Function: flush_clear_screen\n”);

if (prSDLScreen) {
SDL_Rect rect = { 0, 0, prSDLScreen->w,

prSDLScreen->h };
SDL_FillRect (prSDLScreen, &rect, SDL_MapRGB
(prSDLScreen->format, 0,0,0));
SDL_UpdateRect (prSDLScreen, 0, 0, rect.w, rect.h);
}
}

This is probably called in the init phase to clear the
whole screen since the sdl_flush_block_nolock routine
does only update a part of it.
Is it enough to remove the SDL_UpdateRect here without
adding SDL_Flip?___________________________________________________________
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de

Hello !

This is probably called in the init phase to clear the
whole screen since the sdl_flush_block_nolock routine does only update a
part of it. Is it enough to remove the SDL_UpdateRect here without
adding SDL_Flip?

Maybe, just test it :slight_smile:

CU