vsync-switch at runtime

Started by Qudus, June 02, 2008, 23:54:32

Previous topic - Next topic

Qudus

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

Matzon

there is no way to query the current v-state, afaik - so we can't provide such an api.

Qudus

Quote from: Matzon 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.

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

Matzon

public static void setVSyncEnabled(boolean sync) {
		synchronized (GlobalLock.lock) {
			setSwapInterval(sync ? 1 : 0);
		}
	}

public static void setSwapInterval(int value) {
		implementation.setSwapInterval(value);
	}

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  ???

Qudus

Quote from: Matzon on June 03, 2008, 16:36:16
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

Matzon

might be a driver issue?

I can confirm it works for lwjgl. I added the following to org.lwjgl.test.opengl.Gears:
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:
Quotejava -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.

Qudus

Quote from: Matzon on June 03, 2008, 20:52:03
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

Matzon

the error is because it didn't do a full timing loop with vsync on - if I do this I get:
Quote299 frames in 5.0 seconds = 59.8
298 frames in 5.0 seconds = 59.6
This is on Windows XP SP2

Qudus

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

Matzon

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.

Qudus

Quote from: Matzon 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.

Thank you very much.

Marvin