Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] window.pollEvent() lagging when Joystick not plugged in  (Read 14978 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #15 on: October 11, 2015, 04:51:22 pm »
How did you switch between OpenGL versions? Different context settings in the application, with the same driver? In any case, this problem doesn't seem to be related to SFML...

And I don't know why you keep saying "vblank sync", it's "VSync" which means "vertical synchronization".
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #16 on: October 11, 2015, 05:02:32 pm »
How did you switch between OpenGL versions? Different context settings in the application, with the same driver? In any case, this problem doesn't seem to be related to SFML...

And I don't know why you keep saying "vblank sync", it's "VSync" which means "vertical synchronization".

I'm checked it in virtual machine which uses OpenGL 2.1.
By the way, it seems that vblank sync has it's own specific in OpenGL.
Here is some info:
http://stackoverflow.com/questions/589064/how-to-enable-vertical-sync-in-opengl
https://www.opengl.org/wiki/Swap_Interval

So, it seems that vblank sync depends on OpenGL implementation.
I'm not sure how it's cross platform support is implemented in SFML.
Does SFML support vblank sync at all on Linux?


mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #17 on: October 11, 2015, 05:11:32 pm »
And I don't know why you keep saying "vblank sync", it's "VSync" which means "vertical synchronization".

Because it's name taken from low level implementation. "vblank" means vertical blank - it's the flag from the videocard which means that the vertical blank signal is currently active. When this flag is active, it's the time after end scanning of previous frame and before begin scanning of the next frame. So, it's the time to change video memory with no tearing effect.
Actually vertical synchronization means waiting for vblank flag=1 (active).

vblank sync is just more clear term which describes what happens exactly - synchronizing with vblank flag from the videocard.
« Last Edit: October 11, 2015, 05:13:39 pm by mkalex777 »

espectra

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #18 on: October 12, 2015, 04:40:50 pm »
May be it's related with OpenGL version, here is my observations:

OpenGL 4.5: vblank sync works OK
OpenGL 2.1: vblank sync didn't works

It's quite strange - the OpenGL driver on my PC only supports 2.1, but apparently for Windows, OpenGL uses a Windows-specific extension to set vsync: the wglSwapIntervalEXT extension. My driver DOES support that and indeed SFML gets the extension and uses it, by setting the swap interval to 1 when setVerticalSyncEnabled() is set to true.

I'm not yet sure if it's actually enabling vsync and preventing tearing, but it definitely seems to NOT be limiting the frame rate to the refresh rate of 60Hz. Same problem with LWJGL, so I doubt it's simply an SFML problem.

I don't know what's going on and googling info is pretty frustrating and not turning up anything useful.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #19 on: October 12, 2015, 05:44:27 pm »
Here is some more details: http://www.d-silence.com/feature.php?id=255

Quote
"There is no Vsync in OpenGL as a command. Most apps use the GLFlush command, sometimes followed by a GLFinish command. The GLFlush command basically says "Ok, what ever commands you have in your buffer, send 'em to the rendering device now, and get it working." It doesn't care where the raster is in the drawing sync, it just goes out and does it. The GLFinish command will then make the app wait until the rendering device has completed all the commands it has been sent up til then. This gives you the fastest feedback, fairly obviously. Now, depending on whether you are double buffering your video displays (ie rendering to the back one while the front one is being displayed) you might want to use a swapbuffers command. This means that you can afford to slap out commands to the rendering device when ever you feel like it, since it's always going to be rendering to an unseen buffer. The SwapBuffers command does what it says, it swaps the buffers between the front and the back. When it actually does this, ie at Vsync or just randomly whenever it can depends on the card you are using. Sometimes you can set the 'wait for Vsync' in the properties dialog for your card, sometimes it has to be set via registry options. It's messy and highly card dependant. Obviously working in a window you don't get any kind of Vsyncing going on."

So, it seems like OpenGL issue, there is no direct way to control vblank sync in OpenGL. It depends on driver implementation...

If you need it, you can use Direct3D for vblank sync and sfml/opengl for rendering. But it's really ugly solution which mixes Direct3D and OpenGL :)

When you use SetVerticalSync in SFML it actually uses first available function from the following list:
- glXSwapIntervalEXT
- glXSwapIntervalMESA
- glXSwapIntervalSGI

If all these functions is not available it just make warning and ignore it.

Probably it will be better to rename SetVerticalSync to SetSwapInterval to avoid confusing. There is no way to control vblank sync with OpenGL.
« Last Edit: October 12, 2015, 06:09:00 pm by mkalex777 »

espectra

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #20 on: October 12, 2015, 06:20:21 pm »
Probably it will be better to rename SetVerticalSync to SetSwapInterval to avoid confusing. There is no way to control vblank sync with OpenGL.

But you tested it on OpenGL 4.1 and reported that it worked, didn't you?

May be it's related with OpenGL version, here is my observations:

OpenGL 4.5: vblank sync works OK
OpenGL 2.1: vblank sync didn't works

This whole thing with vsync & OpenGL is very confusing.  :o

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #21 on: October 12, 2015, 08:59:07 pm »
So, it seems like OpenGL issue, there is no direct way to control vblank sync in OpenGL. It depends on driver implementation...

If you need it, you can use Direct3D for vblank sync and sfml/opengl for rendering. But it's really ugly solution which mixes Direct3D and OpenGL :)
Asking for "vsync" is a request to the driver. There is no guarantee it will (or can) be honored.
You need to ensure that a) your logic updates are decoupled from your rendering. b) your rendering is independent of your framerate. c) realize that you can't get "vsync" everywhere (does it even make sense for modern lcd panels rhat don't actually have a vertical retrace like old CRT monitors?).
Vsync makes sense if you have a tearing problem. Don't think of it as a "fix framerate limit" thing. If you need to fix (somewhat) your framerate, you need to implement sleeps that make you render at roughly the framerate you want (and handle the inacuracies). Don't rely on vsync for that.

espectra

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #22 on: October 12, 2015, 09:53:03 pm »
Asking for "vsync" is a request to the driver. There is no guarantee it will (or can) be honored.
You need to ensure that a) your logic updates are decoupled from your rendering. b) your rendering is independent of your framerate. c) realize that you can't get "vsync" everywhere (does it even make sense for modern lcd panels rhat don't actually have a vertical retrace like old CRT monitors?).
Vsync makes sense if you have a tearing problem. Don't think of it as a "fix framerate limit" thing. If you need to fix (somewhat) your framerate, you need to implement sleeps that make you render at roughly the framerate you want (and handle the inacuracies). Don't rely on vsync for that.

This is good info! Thanks.

About the "modern lcd" not having vsync, that's an interesting topic. Aren't most displays actually LED displays these days?

Anyway, regardless of whether vsync works on my notebook's built-in display, I've never really seen tearing on it.

However, when testing on a friend's desktop PC with external LED display, I've seen some obvious tearing happening with the same test program.

Since I kind of enjoy understanding the technical stuff like this, I'd like to learn what's going on between testing the program on my notebook and on a desktop. For instance, the Intel media control panel on my notebook has a Vertical Sync option which can be set to "Application Settings" or "On". I don't know if that applies to DirectX only or also OpenGL, since it basically hides some of that underlying detail from the user (older versions of the Intel Graphics drivers seemed to show OpenGL settings explicitly...)

I wonder if we could come up with a simple test case that includes the features you mentioned (decoupled logic and rendering, framerate independent rendering) to show how the setting of vsync (wglSwapIntervalEXT) affects everything?

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #23 on: October 12, 2015, 11:16:50 pm »

But you tested it on OpenGL 4.1 and reported that it worked, didn't you?


it works because driver doing it with glXSwapIntervalEXT(1), but if you call it it doesn't means that you will have vblank sync, it depends on driver desire.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #24 on: October 12, 2015, 11:20:24 pm »
Asking for "vsync" is a request to the driver. There is no guarantee it will (or can) be honored.

There is no way to ask OpenGL driver for vblank sync. When you call SetVerticalSync(true) it actually enable SwapInterval. Vblank may be used with SwapInterval and may not be used. It not depends on support vblank sync in videocard driver. It depends on OpenGL driver.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #25 on: October 12, 2015, 11:25:39 pm »
Vsync makes sense if you have a tearing problem. Don't think of it as a "fix framerate limit" thing.

No. Vsync allows to get equal render intervals with minimum delay between render frame and swap frame. In that way it improves smoothness of movements.
Actually you can eliminate tearing effect with using buffered rendering, but if you want to make smooth movements with equals intervals it will be too hard without vblank sync.
SFML SetVerticalSync eliminates tearing effect, but it actually doesn't deal with vblank sync.
« Last Edit: October 12, 2015, 11:27:39 pm by mkalex777 »

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #26 on: October 12, 2015, 11:33:11 pm »
does it even make sense for modern lcd panels rhat don't actually have a vertical retrace like old CRT monitors?

Yes, it has real sense for all modern LCD with no exception, because all they receive video signal in the same way as it works with CRT. They may use digital signals instead of analog and short vblank but it still exists  ;)
« Last Edit: October 12, 2015, 11:35:08 pm by mkalex777 »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #27 on: October 12, 2015, 11:36:14 pm »
...You don't need 4 posts in the matter of 15 minutes. You can post multiple replies in a single post.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [SOLVED] window.pollEvent() lagging when Joystick not plugged in
« Reply #28 on: October 13, 2015, 03:04:59 am »
...You don't need 4 posts in the matter of 15 minutes. You can post multiple replies in a single post.

Sorry, other forums automatically merge posts with short interval, so I get used to it :)

 

anything