Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL buffer swap issue

Started by obi-wan shinobi Mar 26, 2009 at 4:22 PM 3 replies 3.5k views
Original Post
obi-wan shinobi
obi-wan shinobi
While running code in SDL, pygame, and SDL.NET, it seems like the time spent swapping the buffers varies. For example, rendering 10 textured triangles (1 call to glBegin and glEnd and 1 texture) will take 0ms during the first second of a SDL app run, then jump up to 16-17ms after the first second of running. Rendering several hundred untextured quads in SDL.NET will always take 16ms of buffer swapping time. Yet, rendering 100 textured quads and 10 text surfaces takes 8ms on one run and no more than 1 ms on another run. Is there a way to force SDL/pygame/SDL.NET to limit the amount of milliseconds it takes to swap the GL buffers so I can maintain 60 FPS in my applications? Also, why do the buffer-swapping times vary if the amount being rendered doesn't matter? edit: In fullscreen PyOpenGL, the time spent swapping buffers is 0-2ms per 16ms, but switching to windowed, it goes up.
HuntsMan
HuntsMan
The swapping isn't made by SDL, it's made by the windowing system. It takes an variable amount to wait for the vertical blank signal, so the FPS is already capped at 60 fps, and you're likely have VSYNC enabled.

So, it's already doing what you want i think :)
Zakwayda
Zakwayda
Quote:
If that's the case, then how do I disable vsync?
In SDL, you can (attempt to) disable v-sync via the SDL_GL_SWAP_CONTROL attribute, e.g.:

SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);

My understanding though is that this may or may not have an effect, depending on the platform and the video and driver settings. For example, the configuration panels for some video cards include on option to force v-sync to 'on' or 'off', in which case any requests made by your application will be ignored.

If you just need to maintain an update rate of 60 hz, v-sync shouldn't be a problem, as the refresh rate should always be 60 hz or greater. If you're falling short of 60 hz for other reasons, having v-sync enabled may cause the frame rate to drop dramatically (e.g. to 30 FPS). Disabling v-sync can cause visual artifacts however (the severity of which depends on the frame rate and on what is being displayed).

This is all as I understand it at least. I'm not sure what the Right Way (tm) to handle this in a game or other real-time simulation is - I'm trying to figure that out myself, actually. Including a 'v-sync' option in the video options menu seems like a reasonable solution, except that there's no way that I know of to guarantee that the option will have any effect (as it may be overridden by the driver settings).
obi-wan shinobi
obi-wan shinobi
Using the swapcontrol setting in SDL.NET doesn't change anything in either setting. In SDL, I get slightly better results when it's set to 1. My GeForce 8500GT settings doesn't appear to have a setting to enable or disable vsync nor is it in my control panel->display area.

My main point wasn't really about vsync, but rather about how to reduce the time OpenGL spends swapping the buffers if possible. I mean, how am I supposed to update every 16ms to maintain 60FPS if it takes me something like 2ms to draw to a buffer, another 2ms to read input/do collision detection/etc. and 16ms to swap? That totals up to 20ms and 20ms > 16ms, meaning I don't get 60FPS regardless of how much rendering is done.

Maybe running in fullscreen means less time is spent swapping the buffers, though I only see a real difference when running pygame & pyopengl.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.