Author Topic: VBL sync & OpenGL  (Read 9905 times)

0 Members and 1 Guest are viewing this topic.

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
VBL sync & OpenGL
« on: August 04, 2007 »
Hi guys..

I have an issue with VBL sync on some graphic boards. I use the following code to set it:

typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)( int );

PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;

void setVSync(int interval)
{
   
   if (!wglSwapIntervalEXT)
   {
      wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress( "wglSwapIntervalEXT" );
   }

   if( wglSwapIntervalEXT )
   {
      wglSwapIntervalEXT(interval);
   }
   else
   {
      MessageBox(NULL,"Can't Set Vertical Blanking.","ERROR",MB_OK|MB_ICONEXCLAMATION);
   }
}

To set the sync on, I use setVSync(1), to set it off setVSync(0)


This does not seem to work on some ATI boards. Nvidia is fine.

Any idea?

Thanks
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: VBL sync & OpenGL
« Reply #1 on: August 04, 2007 »
possible an driver issue? the ATI cards where it seems not to work, have you tried here to install latest official AT drivers?
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: VBL sync & OpenGL
« Reply #2 on: August 04, 2007 »
Hi stormbringer   :hi:

You can check if this ogl extension exist using this code:
Code: [Select]
if (strstr((const char *)glGetString(GL_EXTENSIONS), "WGL_EXT_swap_control"))
I had the same problem sometime ago, some gfx drivers don't let you change vsync in window mode but in most of the time it works fine on fullscreen.

Btw, you will need to code a good "delta timer" function to make sure your app will run at same speed on all pc configurations.




Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: VBL sync & OpenGL
« Reply #3 on: August 05, 2007 »
well, thanks guys, I did all that... and the extension seems to be supported, but I do not have access to ATI cards (I only have NVidia)

Driver's configuration may be an issue as in some drivers you can override the VBL settings..

delta timing should not be a problem to code with high precision timers, but again this is quite CPU dependent and not reliable on any configuration...

Normally the VSync should lead synchronized display..

I'll investigate some more and have a more robust code that would deal with different configurations..

Thanks to all
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: VBL sync & OpenGL
« Reply #4 on: August 05, 2007 »
Just keep in mind that there are many screen monitor refresh frequencies (60hz,120hz,85hz etc) if you don't have a delta timer you will have troubles even if you can set Vsync.


Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: VBL sync & OpenGL
« Reply #5 on: August 05, 2007 »
Just check your ATI users don't have the VSYNC turned off in their driver options.  Lots of games players do this, but it screws up well written programs.

Jim
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: VBL sync & OpenGL
« Reply #6 on: August 05, 2007 »
It's a real pain in the ass coding for those people who disable vsync on thier cards. I have never understood why people do it.
A delta timer can really mess up the way that your smooth scroller looks, but as Rbraz says, your program should have this fall back if it needs it.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: VBL sync & OpenGL
« Reply #7 on: August 05, 2007 »
It's a real pain in the ass coding for those people who disable vsync on thier cards. I have never understood why people do it.
A delta timer can really mess up the way that your smooth scroller looks, but as Rbraz says, your program should have this fall back if it needs it.

I believe its because in double buffered mode, turning off vsync means your rendering thread never stalls so you get higher fps at the cost of "tearing" across the screen - acceptable to many people.

You know how obsessed some people get with fps.
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: VBL sync & OpenGL
« Reply #8 on: August 15, 2007 »
I guess there is nothing you can really do when people turn off the VSync at the driver level. Drivers overwrite the settings you may set in you app and then you only depend on the specific user settings.

The delta timer is not a great solution either becuase there is very little guarantee (even with high precision timers). If you want things to be on sync with the VBL, then the VBL should lead the dance....
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: VBL sync & OpenGL
« Reply #9 on: August 15, 2007 »
You said it better than I could Stormbringer.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: VBL sync & OpenGL
« Reply #10 on: August 15, 2007 »
I don't have any preference really, I tend not to write anything to depend an vsync. It varies from pc to pc anyway so there's no point in relying on it for timing and anyone with it switched off can't care too much about tearing.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: VBL sync & OpenGL
« Reply #11 on: August 15, 2007 »
It's just about impossible to write an oldschool pixel scroller for a machine with vsync turned off though. Some things simply must be vsync dependent or some glitches do happen that spoil the experience. It doesn't apply to 3D accelerated stuff but it totally ruins oldschool coded intros.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: VBL sync & OpenGL
« Reply #12 on: August 15, 2007 »
AAAAARRRRGGGHHHH! bloody ADSL connection died while posting the message! here we go again...

Shockwave is totaly right!

Nevertheless, it has nothing to do with old-school coding at all. It is related to the type of visual content.

Try this: turn on you TV and switch to CNN for instance. Look at the bottom of the screen: they have a scroll text with the latest headlines. This scroll is in sync with the VBL of the video signal. Why? simply because if it's not, it would look weird, be unreadable and give strong headaches to viewers.

The reason is that the display technique has to be in harmony of the eye-brain perception mechanisms, otherwise the experience is very bad.

For 3D scenes, it's different because the eye/brain interpred the visuals differently and the VBL sync is not so important. But for 2D tranlational motion (scrolling, 2d starfield, etc), it has to be in sync with the VBL

Best

Stormbringer
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: VBL sync & OpenGL
« Reply #13 on: August 15, 2007 »
I think it can be dealt with, maybe not perfectly but still pretty smooth. Say it's run on 1 pc with a refresh of 60Hz and another with 120Hz, that's a 2* difference in the speed of the scroller which imo would be pretty bad and that's not mentioning anything with vsync off or timing with anything else/music going on too. Oldschool demos were written to be run on machines with the same spec meaning everything always ran at the same speed regardless of who ran it and afaic that should still be the case.
« Last Edit: August 15, 2007 by Stonemonkey »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: VBL sync & OpenGL
« Reply #14 on: August 16, 2007 »
I think it can be dealt with, maybe not perfectly but still pretty smooth.

The perfect solution is for people running the demo to enable Vsync to be controlled by the application. The coder can then set the sync rate in his app. 

It's a fair point you make Stonemonkey, but oldschool intros don't work well if they are delta timed.. The odd glitch spoils the experience.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: VBL sync & OpenGL
« Reply #15 on: August 16, 2007 »
Quote
The perfect solution is for people running the demo to enable Vsync to be controlled by the application. The coder can then set the sync rate in his app.

It's not always possible for the app to have control over the sync rate, for example I have a fairly old IBM LCD monitor that only displays at 60Hz and attempting to change any of the adapter settings relating to frame rate screws it up.
« Last Edit: August 16, 2007 by Stonemonkey »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: VBL sync & OpenGL
« Reply #16 on: August 16, 2007 »
Well in your case then you are limited to 60fps, having non standard hardware to code for is a problem but I am sorry, I have yet to see a real oldschool demo with something like bobs and a sinescroll running perfectly with no glitches if it's delta timed.

The closest I have seen anyone get to that is Keops with his stuff and that's not pixel bashing, it's using hardware accelerated 3D with sub-pixel accuracy.

If anyone can show me delta timing working in a tinyptc environment to smoothly move lots of 2D graphics around with no glitches at all I'd be really impressed.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: VBL sync & OpenGL
« Reply #17 on: August 17, 2007 »
In my CDI demo remake I use GDI to do the copy to the screen, and I do it every 1/50th of a second (PAL refresh rate) no matter what the refresh of the screen for that extra genuine look :)

Jim
<edit>50ms -> 1/50th
« Last Edit: August 18, 2007 by Jim »
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: VBL sync & OpenGL
« Reply #18 on: August 17, 2007 »
Nice solution Jim, one very good thing about that is if you're using any feedback from the previous frame, it'll never look any different from machine to machine.

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: VBL sync & OpenGL
« Reply #19 on: August 17, 2007 »
@Jim: yes if you render "manually" in memory and just use GDI tu update the screen buffer, yes it works! But high precision timers are not reliable on old computers (but again who cares ???)

Then if this is the solution, what's the point in having OpenGL with hardware acceleration and so-called standard extensions if they're not that standard or if the app cannot drive the VBL?

Moreover 60Hz is more than enough for old-school prods and should be enough for almost everything of that kind. 60Hz is supposed to be supported by (almost) all computers now. Working with the VBL should be the solution, but the app should be able to enable it, whatever the driver says... IMHO

Best,

Stormbringer
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart