|
|
| Why when using double-buffering U don't need vsync? |
|
Aharon Hillel
Member #3,980
October 2003
|
I have tested my game & noticed its running much smoother without the vsync() call b4 blitting to screen. I did some reading in the forum & understand U all recommend not to use vsync() with doube buffering. OK, I accept this, game running just fine now, but I would like to understand why it's OK ommit the vsync and still get good result? anyone? Here's my game loop (this runs OK): frame_computed = TRUE; // Time_for_frame = TRUE in timer function. |
|
miran
Member #2,407
June 2002
|
Vsync is used to get rid of the screen tearing effect that occurs when the game updates the screen with a different rate than is the physical refresh rate of the monitor. So if you disable vsync the game may look smoother because the frame rate won't be clipped to the refresh rate of the monitor but you will get tearing, especially if the display changes a lot between frames. So you should have an option to disable/enable vsync in your game so that people who want maximum FPS will be able to disable it... -- |
|
Chris Katko
Member #1,881
January 2002
|
Also, I'm not 100% positive on this. But I'm pretty sure that using vsync, in the worst case scenario, you can only get half the actual framerate of the monitors refresh rate. Which is why some things are much smoother without vsnyc (but obviously are prone to tearing.) -----sig: |
|
gillius
Member #119
April 2000
|
That's wrong Et. If your monitor is running with a refresh rate of 60hz, the ideal game situtation is to run the game at 60fps, waiting for vsync. There is no better looking solution as frames always appear in whole, and always are evenly spaced. With vsync off you will see tearing. If FPS is higher than refresh the tearing gets worse if you see more than 2 frames in a refresh. If FPS is lower than refresh you get tearing without using vsync, and when using vsync you'll get unevenly spaced frames. Sometimes having a solid 30 fps rate (vsync timed) is better than having a 35 or 40 rate, because frames are evenly spaced. The next step is 15 fps, but 15 fps is so enough that it is worth having uneven frames to get 20 or 25 fps. Gillius |
|
Chris Katko
Member #1,881
January 2002
|
Wait, yeah. I got that confused with the reason we use triple buffering. -----sig: |
|
gillius
Member #119
April 2000
|
Yep using triple buffering allows you to generate frames as fast as possible without "wasting" time for vsync to complete. But it still makes sure that you don't render more frames than refreshes. Gillius |
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote: If FPS is higher than refresh the tearing gets worse if you see more than 2 frames in a refresh.
Not possible. You can write more than one frame to video memory per refresh, but the monitor will only display one. Thats what the refresh is for. now the tearing is when the monitor refreshes in the middle of you drawing the screen. ugly. -- |
|
Billybob
Member #3,136
January 2003
|
Ok, with double buffering, you are drawing to a buffer, and then fling the buffer to the screen. This removes flicker, because you don't see anything getting drawn. I think that ties into vsync. If you fling the buffer over to the screen in one big go, it's less likely you'll catch the screen at a "bad time" and form tearing...I think...thus it's better not to vsync, cause that'll just slow your prog up and accually cause uneven frame rates, since there is no way your prog will ever match the timing of vsync. Also, you are limiting frame rates yourself, so if you were to vsync, you'd mess that up a bit, since your timing wont be equal to vsync's timing. One last note for 3D games: If your game runs at 60fps without vsync, please don't vsync. It'll slow your game down(reducing the number of polys you can fling), and since you're already at 60fps, you aren't likely to cause tearing. If you're game is running higher than that, add more polys adn enjoy your no-vsync-ness
|
|
gillius
Member #119
April 2000
|
It is possible Tom. If your refresh is 60 and you were rendering at 180, the top 1/3rd of your screen will be frame 1, the middle third frame 2, and the bottom third frame 3. William, vsync won't slow the game down if you are using triple buffering. And if you are running on a video card entirely in hardware you should take advantage of hardware page flipping, since the APIs do it for you anyway. Gillius |
|
Thomas Fjellstrom
Member #476
June 2000
|
gillius said: It is possible Tom. If your refresh is 60 and you were rendering at 180, the top 1/3rd of your screen will be frame 1, the middle third frame 2, and the bottom third frame 3.
I said: You can write more than one frame to video memory per refresh, but the monitor will only display one. I should have extended that to say "but the monitor will only display one whole frame". BUT I figured Quote: now the tearing is when the monitor refreshes in the middle of you drawing the screen. ugly. that covered for that little bit of misunderstanding... guess not. -- |
|
Derezo
Member #1,666
April 2001
|
vsync() often screws up on my system. I've read elsewhere in the forums that allegro's vsync() isn't very accurate. I don't know the full truth behind that, but this tells me that whoever mentioned that was right. [edit: I should also note that I haven't used vsync() since 4.0] "He who controls the stuffing controls the Universe" |
|
gnolam
Member #2,030
March 2002
|
Same for me - but the problem with vsync() for me is that it fscks up the screen update frequency... it stutters like hell whenever I try to use it, so I avoid it wherever possible and let my video card drivers worry about it instead. I usually add a command line option or similar for the people who want to use Allegro's vsync() though... -- |
|
Aharon Hillel
Member #3,980
October 2003
|
What door have I opened? Good discussion. From reading the comments I conclude the following: |
|
dudaskank
Member #561
July 2000
|
Quote: When not using vsync() it's better to run your game with fps < 60 (assuming that most monitors nowadays refreash at 60++ speed), because if your fps < MONITOR refreash rate it is most likely that U won't get flickering The ideal will be fps = refresh rate, but with high resolutions this can be hard to reach. But more than this isn't interesting. It's because the video can't show all the frames, so you waste your cpu doing unnecessary memory copies and causing some unwanted effects. The advantage of vsync() is that you don't need to use a timer, if your system is fast enough to blit the image. The program will run at constant speed (fps=refresh rate) ^__^ Toque a balada do amor inabalável, eterna love song de nós dois |
|
miran
Member #2,407
June 2002
|
Quote: The advantage of vsync() is that you don't need to use a timer That's not an advantage. Using vsync() is probably the worst way to control the frame rate of a game... -- |
|
MiquelFire
Member #3,110
January 2003
|
The reason it's worse is because not everyone's refresh rate is 60. On some systems, it could be 120 or so. --- |
|
Derezo
Member #1,666
April 2001
|
Yeah, don't use vsync() to control the game speed. DirectX drivers allow you to force refresh rates. So you have no idea what refresh rate you're going to get. There's request_refresh_rate() which may override the DirectX setting (or may not, I don't know)... but even so, if the computer is too slow to keep up with the video, the logic will lag with it, and defeating half the purpose of controlling game speed. "He who controls the stuffing controls the Universe" |
|
gillius
Member #119
April 2000
|
Timing by vsync is OK assuming you are using a system like the one I posted before that allowed for adaptive "dt" frame lengths between an interval. If you can lock your logic rate exactly to your FPS then you are being as efficient as possible. Unfortunately when using the Allegro timer system, this is not possible, at least without emperical nature in the code -- having to guess the current FPS based on an average, and using that as dt. If you can use a high-performance counter, then what you do is use vsync, and as long as your dt's are reasonable, then lock your game to vsync. When dt's become bad, you need to sleep (extremely high FPS) or frameskip (extremely low FPS). How high is high depends mostly on preference, and how low is low depeonds on how you've coded your game logic (usually it is your collision detection or integration method that drives this choice) Gillius |
|
Sirocco
Member #88
April 2000
|
As a side note, in my recent projects I always have a in-game hotkey to toggle vsync regardless of whether or not the user wants it enabled by default. Handy ^.^ --> |
|
Thomas Fjellstrom
Member #476
June 2000
|
"allegro's" vsync is handled by the card where ever possible.. Otherwise, its a timer and some code. -- |
|
kikabo
Member #3,679
July 2003
|
Just to even the numbers up a bit, Ofcourse you have to take into account the screen refresh rate to keep game logic constant but it's not any harder than anything else. Timers are a neat solution, make readable code and steer newbies away from a potential mess. If I was advising anyone to use a method I would advise using timers but I wouldn't say 'never' to framebased - so far at least |
|
Andrei Ellman
Member #3,434
April 2003
|
I've noticed that when running one of my programs in Linux (Debian) that uses vsync to prevent shearing, there is a very visible shearing artifact which looks like a line between two frames (above the line is one frame and below the line is another). This line appears to be stable, but slowly moves up the screen, which means that the internal vsync timer is slightly faster than the monitor's actual refresh rate. The program has the ability to be configured so that waiting for vsync is turned off. When I turned it off, the shearing changed. It was now all over the place, but because it moved around, it wasn't as noticable than a line that stayed in almost the same place. However, in Windows, vsync seems to work fine, and when I turn off vsync, the same thing happens when I turn it off in the Linux version (although I only tested the Linux version on one machine and I did not test the Windows version on that machne, so it may be the hardware and not Linux). Apparently, some cards have the ability to generate an interrupt whenever the electron beam of the monitor reaches the end of the frame (the start of the "vertical blank"). Alas, not all cards suppport this, and as a substitute, a slightly inaccurate timer has to be used. Considering how long ago it has been since the days of 16-bit "home computers" such as the ST and Amiga (where vertical-blank interrupts were part of the hardware), it still amazes me to see that even today, there is no standardized way that works accross all graphics cards of preventing shearing on a PC. Vertical Blank Interrupts should have been supported as standard in all graphics cards ages ago. AE. -- |
|
|