Problem with SDL_SwapBuffers()

Hi,

I have a problem with SDL_SwapBuffers() in a SDL/GL game,
this function requires about 9~10 ms. with a resolution of 800x600
and 15~16 ms. with a resolution of 1024x768, but I have tested
other SDL/GL programs/games (Nehe demos, Supertux, etc…) and
usually it requires 1~5 ms. with these resolutions.

Does someone knows a possible cause that can generate this problem?

If this can help, I can post the screen init and surface loading code
in my next message.

Thanx.–

Davide “M3xican” Coppola


email: dmc at dev-labs.net
homep: http://dmc.dev-labs.net
ICQ: 104241710
MSN: bad_hangover at hotmail.it

Don’t use IE and OE!
Download FireFox and ThunderBird: http://www.mozilla.org/

I am by no means an expert in these matters, so I may be entirely wrong.

One possible cause of this problem may be that your SwapBuffers()
waits for the screen refresh (V-Sync) to actually do the swap or
copy or whatever. Whether your application actually does this or not
depends on the flags you pass when setting video mode
(double-buffered or not, hardware buffer or not, full-screen or not)
and also on your graphics card driver’s configuration (easily
modifiable on Windows/nVidia, don’t know about others.)

In order to check whether this is happening or not, measure your
code’s frame rate. If it matches the refresh rate of your desktop,
then it’s almost definitely the V-Sync. To make extra sure, remove a
lot of drawing code (or add a lot, if you’re testing with empty
drawing code) and measure the frame rate again. If it doesn’t change
much, then you’re extra sure.

-yzt

Davide “M3xican” Coppola wrote:> Hi,

I have a problem with SDL_SwapBuffers() in a SDL/GL game,
this function requires about 9~10 ms. with a resolution of 800x600
and 15~16 ms. with a resolution of 1024x768, but I have tested
other SDL/GL programs/games (Nehe demos, Supertux, etc…) and
usually it requires 1~5 ms. with these resolutions.

Does someone knows a possible cause that can generate this problem?

If this can help, I can post the screen init and surface loading code
in my next message.

Thanx.


“Programming is an art that fights back!”

Yaser Zhian Tabasy wrote:

I am by no means an expert in these matters, so I may be entirely wrong.

One possible cause of this problem may be that your SwapBuffers()
waits for the screen refresh (V-Sync) to actually do the swap or
copy or whatever. Whether your application actually does this or not
depends on the flags you pass when setting video mode
(double-buffered or not, hardware buffer or not, full-screen or not)
and also on your graphics card driver’s configuration (easily
modifiable on Windows/nVidia, don’t know about others.)

In order to check whether this is happening or not, measure your
code’s frame rate. If it matches the refresh rate of your desktop,
then it’s almost definitely the V-Sync. To make extra sure, remove a
lot of drawing code (or add a lot, if you’re testing with empty
drawing code) and measure the frame rate again. If it doesn’t change
much, then you’re extra sure.

-yzt

I have done some tests, now I think that vsync is not the problem,
cause FPS doesn’t match with it, but I have discovered that removing
half of blits (moving from 200 to 100 128x64 tiles) the time needed to
swap the buffers is less than half (~5 ms.) in both resolutions.

Any suggestion to solve this?
At the moment the flag I pass to SDL_SetVideoMode() is just SDL_OPENGL.

You can find the source in this SVN repository:
http://svn.sourceforge.net/viewcvs.cgi/mars/mars/trunk/src/graphic/
related files are:
GLScreen.h/.cpp
GLSurface.h/.cpp
GLImage.h/.cpp

Thanx–

Davide “M3xican” Coppola


email: dmc at dev-labs.net
homep: http://dmc.dev-labs.net
ICQ: 104241710
MSN: bad_hangover at hotmail.it

Don’t use IE and OE!
Download FireFox and ThunderBird: http://www.mozilla.org/

Davide “M3xican” Coppola wrote:

I have a problem with SDL_SwapBuffers() in a SDL/GL game,
this function requires about 9~10 ms. with a resolution of 800x600
and 15~16 ms. with a resolution of 1024x768, but I have tested
other SDL/GL programs/games (Nehe demos, Supertux, etc…) and
usually it requires 1~5 ms. with these resolutions.

Does someone knows a possible cause that can generate this problem?

If this can help, I can post the screen init and surface loading code
in my next message.

I have solved the problem using a fixed delay (20 ms. -> 50 FPS),
now the GL_SwapBuffers() requires 0~1 ms.

I don’t know the reason, but I hope this could help someone else
with the same problem.

Cya.–

Davide “M3xican” Coppola


email: dmc at dev-labs.net
homep: http://dmc.dev-labs.net
ICQ: 104241710
MSN: bad_hangover at hotmail.it

Don’t use IE and OE!
Download FireFox and ThunderBird: http://www.mozilla.org/

Davide “M3xican” Coppola wrote:

Davide “M3xican” Coppola wrote:

I have a problem with SDL_SwapBuffers() in a SDL/GL game,
this function requires about 9~10 ms. with a resolution of 800x600
and 15~16 ms. with a resolution of 1024x768, but I have tested
other SDL/GL programs/games (Nehe demos, Supertux, etc…) and
usually it requires 1~5 ms. with these resolutions.

Does someone knows a possible cause that can generate this problem?

If this can help, I can post the screen init and surface loading code
in my next message.

I have solved the problem using a fixed delay (20 ms. -> 50 FPS),
now the GL_SwapBuffers() requires 0~1 ms.

I don’t know the reason, but I hope this could help someone else
with the same problem.

Cya.

Hi,

VSYNC wait is on ?

Pete.

I think opengl only renders when it needs to. Try calling glFinish()
before SDL_SwapBuffers() and check if it’s faster.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060630/4a7de645/attachment.pgpOn Tue, Jun 27, 2006 at 12:57:28PM +0200, Davide M3xican Coppola wrote:

Hi,

I have a problem with SDL_SwapBuffers() in a SDL/GL game,
this function requires about 9~10 ms. with a resolution of 800x600
and 15~16 ms. with a resolution of 1024x768, but I have tested
other SDL/GL programs/games (Nehe demos, Supertux, etc…) and
usually it requires 1~5 ms. with these resolutions.

Does someone knows a possible cause that can generate this problem?

Peter Mulholland wrote:

Hi,

VSYNC wait is on ?

I don’t know how to check this for a certainty, however
looking at nvidia-settings and considerring that I can get
more than 100FPS in 800x600 it should be off.–

Davide “M3xican” Coppola


email: dmc at dev-labs.net
homep: http://dmc.dev-labs.net
ICQ: 104241710
MSN: bad_hangover at hotmail.it

Don’t use IE and OE!
Download FireFox and ThunderBird: http://www.mozilla.org/

Mikael Eriksson wrote:

I think opengl only renders when it needs to. Try calling glFinish()
before SDL_SwapBuffers() and check if it’s faster.

I have tried to use glFinish(), it takes SDL_SwapBuffers() time,
so at the moment limiting the FPS is still the better solution.

Thanx–

Davide “M3xican” Coppola


email: dmc at dev-labs.net
homep: http://dmc.dev-labs.net
ICQ: 104241710
MSN: bad_hangover at hotmail.it

Don’t use IE and OE!
Download FireFox and ThunderBird: http://www.mozilla.org/