Hello again,
I’ve done a bit more experimenting this morning. It looks like using
SDL_RENDERER_PRESENTVSYNC for initialization and calling
SDL_RenderPresent function does almost what I need. If I call this
function in a loop while counting the number of iterations per second
(or FPS), it gives me exactly the refresh rate of the monitor.
However, the first 3 or 4 iterations return immediately. Here is the
actual number of seconds that each call to SDL_RenderPreset took,
starting with the first:
0.002488
0.000065
0.000066
0.006132
0.013291
0.013291
0.013291
…
The refresh rate is 75 Hz, so 13.3 ms is exactly what I should be
getting. Does anyone have an explanation for why the first few frames
are rendered instantly? Is it the fact that vsync goes into effect
only after the first frame is shown and my loop is able to generate 4
or 5 frames prior to the first refresh cycle?
My final question is regarding the actual state of the display when
SDL_RenderPresent returns. In my first message I asked for a function
that would block until just before the next refresh. However, I have a
feeling that SDL_RenderPresent blocks until just after.
Once we’re past the display of the first frame, am I correct in
assuming that SDL_RenderPresent will return as soon as the buffer flip
was performed, which can happen only after the previous refresh is
finished, and only once per refresh cycle. Which of the following two
sequences is correct for understanding what is going on in the
background?
Sequence 1:
- SDL_RenderPresent call 1 blocks
- SDL_RenderPresent call 1 returns
- Monitor refresh
- SDL_RenderPresent call 2 blocks
- SDL_RenderPresent call 2 returns
- Monitor refresh
Sequence 2:
- SDL_RenderPresent call 1 blocks
- Monitor refresh
- SDL_RenderPresent call 1 returns
- SDL_RenderPresent call 2 blocks
- Monitor refresh
- SDL_RenderPresent call 2 returns
- MaxOn Tue, Sep 21, 2010 at 3:01 PM, Maxim Khitrov <@Maxim_Khitrov> wrote:
Hello everyone,
I have fairly limited experience with SDL, but I’m figuring things out
one bit at a time. I have a problem that requires my software to know
as close as possible when the next frame is drawn on the screen. That
basically means that I need to have at least 2 buffers - one that I
can draw on without anything showing up on the monitor, and an active
buffer that is being displayed. At some point, I need to issue a
command that will wait until the next vertical refresh cycle and swap
the two buffers as quickly as possible.
I’m using SDL 1.3 with DirectX driver on Windows XP. Right now I’m at
a point where I can create a full-screen window, attach the correct
renderer, and do some basic color changes using
SDL_SetRenderDrawColor, SDL_RenderClear, and SDL_RenderPresent. The
renderer is initialized using the following flags:
SDL_RENDERER_PRESENTFLIP2
SDL_RENDERER_PRESENTVSYNC
SDL_RENDERER_ACCELERATED
Unfortunately, I don’t have sufficient understanding of DirectX or SDL
to know whether will give me the desired results. I’d appreciate any
example that shows how to properly swap video buffers just prior to a
vertical refresh.
They key is that this must be a synchronous operation. If the swap
command is issued just after the previous refresh, I need it to block
for however many milliseconds necessary until the next refresh cycle.
Thanks for your help,