Hello Guest

vsync-switch at runtime

  • 10 Replies
  • 22085 Views
*

Offline Qudus

  • ***
  • 123
vsync-switch at runtime
« on: June 02, 2008, 23:54:32 »
Toggling vsync doesn't work after the Display has been created. And even if this is not essentially important, there should be a getter for the current v-sync state.

I am using Linux and LWJGL 1.1.4.

Thanks in advance.

Marvin

*

Offline Matzon

  • *****
  • 2242
Re: vsync-switch at runtime
« Reply #1 on: June 03, 2008, 04:53:43 »
there is no way to query the current v-state, afaik - so we can't provide such an api.

*

Offline Qudus

  • ***
  • 123
Re: vsync-switch at runtime
« Reply #2 on: June 03, 2008, 16:13:10 »
there is no way to query the current v-state, afaik - so we can't provide such an api.

I almost expected that. I as I said, it's not that important.

But it should be possible to enable/disable v-sync at runtime. AFAIK it is possible in JOGL.

Marvin

*

Offline Matzon

  • *****
  • 2242
Re: vsync-switch at runtime
« Reply #3 on: June 03, 2008, 16:36:16 »
Code: [Select]
public static void setVSyncEnabled(boolean sync) {
synchronized (GlobalLock.lock) {
setSwapInterval(sync ? 1 : 0);
}
}
Code: [Select]
public static void setSwapInterval(int value) {
implementation.setSwapInterval(value);
}
Code: [Select]
public void setSwapInterval(int value) {
boolean success = nSetSwapInterval(value);
if (!success)
LWJGLUtil.log("Failed to set swap interval");
Util.checkGLError();
}

fwiw, jogl also just calls setSwapInterval(0/1) - I am not sure how it should fail on lwjgl but not jogl  ???

*

Offline Qudus

  • ***
  • 123
Re: vsync-switch at runtime
« Reply #4 on: June 03, 2008, 19:38:54 »
fwiw, jogl also just calls setSwapInterval(0/1) - I am not sure how it should fail on lwjgl but not jogl  ???

I double-checked it on JOGL. And it fails on JOGL, too. Actually you can enable v-sync on both JOGL and LWJGL after it was initially disabled, but you can never disable it again.

Any idea, why?

Marvin

*

Offline Matzon

  • *****
  • 2242
Re: vsync-switch at runtime
« Reply #5 on: June 03, 2008, 20:52:03 »
might be a driver issue?

I can confirm it works for lwjgl. I added the following to org.lwjgl.test.opengl.Gears:
Code: [Select]
private void loop() {
...
while (!Display.isCloseRequested()) {
...

while(Keyboard.next()) {
if(Keyboard.getEventKey() == Keyboard.KEY_1 && Keyboard.getEventKeyState()) {
System.out.println("enable v-sync");
Display.setVSyncEnabled(true);
}
if(Keyboard.getEventKey() == Keyboard.KEY_0 && Keyboard.getEventKeyState()) {
System.out.println("disable v-sync");
Display.setVSyncEnabled(false);
}
}

and this is the output I got:
Quote
java -cp .;bin;res; -Djava.library.path=libs\win32 org.lwjgl.test.opengl.Gears
GL_VENDOR: NVIDIA Corporation
GL_RENDERER: GeForce 8600 GTS/PCI/SSE2
GL_VERSION: 2.1.2

glLoadTransposeMatrixfARB() supported: true
58164 frames in 5.0 seconds = 11632.8
enable v-sync
6745 frames in 5.0 seconds = 1349.0
disable v-sync
49261 frames in 5.0 seconds = 9852.2
enable v-sync
5638 frames in 5.0 seconds = 1127.6
disable v-sync
53884 frames in 5.0 seconds = 10776.8
58972 frames in 5.0 seconds = 11794.4

Mind you, I had to set the nvidia control panel setting for Vertical sync to: Use the 3D application setting.

*

Offline Qudus

  • ***
  • 123
Re: vsync-switch at runtime
« Reply #6 on: June 03, 2008, 22:02:02 »
Mind you, I had to set the nvidia control panel setting for Vertical sync to: Use the 3D application setting.

Of course. Without it, I would not be able to enable/disable v-sync at Display creation time at all.

Why do you get such a high frame rate with v-sync enabled? I assume, your monitor doesn't make over a thousand FPS, does it?

Anyway. I will check it on Windows. Are you using Windows or Linux, btw.?

Marvin

*

Offline Matzon

  • *****
  • 2242
Re: vsync-switch at runtime
« Reply #7 on: June 03, 2008, 22:20:41 »
the error is because it didn't do a full timing loop with vsync on - if I do this I get:
Quote
299 frames in 5.0 seconds = 59.8
298 frames in 5.0 seconds = 59.6
This is on Windows XP SP2

*

Offline Qudus

  • ***
  • 123
Re: vsync-switch at runtime
« Reply #8 on: June 07, 2008, 00:13:49 »
I checked it and it is indeed a linux only problem. I don't know, whether it is a driver issue or something else. But I can live with it. Would be cool, if you could keep this in mind and try it out when you test on a linux machine the next time.

Thanks for your patience.

Marvin

*

Offline Matzon

  • *****
  • 2242
Re: vsync-switch at runtime
« Reply #9 on: June 07, 2008, 05:52:41 »
since I am windows only (I only have linux on vmware, to do releases) I think I'll let elias take a stab at it. I will let him know of this thread.

*

Offline Qudus

  • ***
  • 123
Re: vsync-switch at runtime
« Reply #10 on: June 07, 2008, 11:32:19 »
since I am windows only (I only have linux on vmware, to do releases) I think I'll let elias take a stab at it. I will let him know of this thread.

Thank you very much.

Marvin