Sign in to follow this  

Best way to sync frames in SW 2D rendering?

This topic is 2483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I'm currently using TinyPTC in GDI mode (yeah I know, outdated and stuff) to be able to use a backbuffer and flip it to the GDI surface, it's pretty neat for doing simple 2D rendering the old pixel-fashioned way.
I want to flip the buffer every frame, being 60Hz, how can I do this in a very timing-precise way?

Currently I use a very slow and unaccurate jittering way like this:
[code]

unsigned int buffer[WIDTH * HEIGHT];

static int next_tick = 0;
static int tick_interval = (int)(1.0f * 1000.0f / 60.0f);

void syncframe(void)
{
if (next_tick >= timeGetTime())
{
Sleep(next_tick - timeGetTime());
}

next_tick = timeGetTime() + tick_interval;
}

int main()
{
while (running)
{
/* clear buffer */

/* run functions that plot pixels to buffer */

/* flip buffer and sync frame */
ptc_update(buffer);
syncframe();
}
}
[/code]
It sure does work, but it lags rhythmically. I know there's no way to get 100% fullspeed on a multitask system, because there are several low-level threads in use by the OS....
But there should at least be a way to get 60Hz smooth, 60Hz is not extremely fast - would triple buffering help? Any known tricks and tips to get this working in a simple way? As said, this is simple software 2D stuff.

Any help appreciated!

Share this post


Link to post
Share on other sites
Unfotunately GDI and the win32 APIs don't expose the vsync signal.

Basically you do what you're doing now, more or less. You can probably smooth things out a bit more by sleeping for your current amount, less 5ms (the timer (or sleep) is only guaranteed accurate to 5ms increments, IIRC)... then busy-wait for the last <5ms. This may or may not actually prove better.

In my own renderer I do basically this, IIRC, and framerate is locked pretty tight on 60fps, with an occasional flash into 59fps reported.

Share this post


Link to post
Share on other sites

This topic is 2483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this