Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Timing of swapBuffers  (Read 2605 times)
0 Members and 1 Guest are viewing this topic.
Offline DwRedmill

Junior Newbie





« Posted 2010-11-02 09:50:20 »

How can I determine exactly when thw GLDrawable.swapBuffers() command actually swaps the buffers?
Is there a way of waiting for the swapBuffers() to complete?

I have a simple program which rotates a viewpoint by 1 degree every time display() is called. Thus a complete 360 degree revolution should take 360 calls to display(). With a 60Hz refresh rate I would expect this to take 6s assuming the rendering can be done in less than 1/60th of a sec. However, the scene rotates much faster especially when the window is small. This would indicate that display() is called more frequently and that swapBuffers() is called at a rate higher than the refresh rate. I've tried bot the default automatic buffer swapping and disabling this to do a manual swap. PS. I'm using Windows XP.

Offline ryanm

Senior Devvie


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #1 - Posted 2010-11-02 10:55:52 »

A better solution would be to divorce the rate of rotation from your frame-rate.
For example, you want to rotate 360 degrees in 6 seconds, that's a rate of 60 degrees per second. Measure the time difference in seconds between calls to your rendering code, multiply it be the rotation-per-second figure and add that to the rotation angle.
This'll give you a consistent speed of rotation, no matter what the frame-rate is.
Offline cylab

JGO Ninja


Medals: 55



« Reply #2 - Posted 2010-11-02 11:25:55 »

How can I determine exactly when thw GLDrawable.swapBuffers() command actually swaps the buffers?
Is there a way of waiting for the swapBuffers() to complete?

gl.setSwapInterval(1)

Quote
void setSwapInterval(int interval)

Provides a platform-independent way to specify the minimum swap interval for buffer swaps. An argument of 0 disables sync-to-vertical-refresh completely, while an argument of 1 causes the application to wait until the next vertical refresh until swapping buffers. The default, which is platform-specific, is usually either 0 or 1. This function is not guaranteed to have an effect, and in particular only affects heavyweight onscreen components.

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DwRedmill

Junior Newbie





« Reply #3 - Posted 2010-11-02 12:41:47 »

gl.setSwapInterval(1)

I've already tried that with both both 1 and 0 and observed no difference.
Offline DwRedmill

Junior Newbie





« Reply #4 - Posted 2010-11-02 12:50:53 »

A better solution would be to divorce the rate of rotation from your frame-rate.
For example, you want to rotate 360 degrees in 6 seconds, that's a rate of 60 degrees per second. Measure the time difference in seconds between calls to your rendering code, multiply it be the rotation-per-second figure and add that to the rotation angle.
This'll give you a consistent speed of rotation, no matter what the frame-rate is.
But I still wouldn't know the actual frame rate and frame timings. My aim is to use real time captured data to control the viewpoint. 
It is important to know 1) the latency between capture and display time, 2) any variations in this latency, 3) what the frame rate is and if any frames are dropped.
Offline cylab

JGO Ninja


Medals: 55



« Reply #5 - Posted 2010-11-02 12:56:38 »

I've already tried that with both both 1 and 0 and observed no difference.
Then your driver does not implement/expose this functionality in it's GL implementation or ignores it due to speed/quality settings in your drivers control panel. Or maybe you are doing it at the wrong place in your code (it usually should be in init()).

Mathias - I Know What [you] Did Last Summer!
Offline Mike

« JGO Spiffy Duke »


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #6 - Posted 2010-11-02 13:26:32 »

However, even though you vsync the app it might be running in less or more fps.

This would mean that someone with a 120hz screen would potentially spin the cube in 3s and someone with a slow computer might spin it in 40 seconds. What are you trying to achive? If it is a smooth rotation you should look into what ryanm said.

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline DwRedmill

Junior Newbie





« Reply #7 - Posted 2010-11-02 14:57:24 »

What are you trying to achive?
The spinning world is only a toy example. Yes I could get a smooth consitent spin rate using other methods.

I think what I really want to know is precisely when a rendered frame is displayed (swapped into the visible buffer).
At 60Hz refresh rate, this could be somewhere between 0 and 16ms (1/60th second) after the render is completed and swapBuffers is called. This uncertainty in latency is a potential concearn for applications where achieving a consitent and minimal latency, and knowing what these latency variations are is important.

 
Offline princec

« JGO Spiffy Duke »


Medals: 421
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2010-11-02 16:45:50 »

Well, that's why you need vsync.

Cas Smiley

Offline DwRedmill

Junior Newbie





« Reply #9 - Posted 2010-11-15 14:20:25 »

The problem may be due to the graphics hardware not supporting vsync.
New computer with a decent graphics card has solved the probolem.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (27 views)
2014-11-22 12:13:56

xFryIx (69 views)
2014-11-13 12:34:49

digdugdiggy (48 views)
2014-11-12 21:11:50

digdugdiggy (42 views)
2014-11-12 21:10:15

digdugdiggy (36 views)
2014-11-12 21:09:33

kovacsa (60 views)
2014-11-07 19:57:14

TehJavaDev (64 views)
2014-11-03 22:04:50

BurntPizza (62 views)
2014-11-03 18:54:52

moogie (77 views)
2014-11-03 06:22:04

CopyableCougar4 (77 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!