Updated : tried direct approach (context.makeCurrent() / paint / context.release() and canvas.swapBuffers() in a loop) : 350 fps in a frame, 35 fps in FF, 350 fps in IE
Like I replied to your JackFlowers thread, I got ~350fps in FireFox, which was about the same for me in IE. (I used FireFox 1.5 and the 1.5.0_06 JVM)… So maybe the problem is FireFox 1.4 related?
Actually I can reproduce this problem. I see 150 FPS in IE and only 20 FPS in Mozilla 1.7.6. This is with J2SE 1.5.0_06 on Windows XP SP1 with NVidia graphics hardware.
My best guess at this point would be architectural differences between the Java Plug-Ins for IE and Mozilla. I don’t know a lot about how the Plug-In works but know that there are effectively two different code bases due to how the different browsers work. I thought that at one time the Mozilla plug-in actually ran out-of-process or something similar. Maybe that’s changed. I do think it is strange that a pure Java2D applet could get extremely high frame rates while JOGL applets would be slow. I don’t think JOGL’s locking or repainting code would be the problem especially if the same code runs fine in IE but anything’s possible.
I’ll ask some people more familiar with the Plug-In to take a look at this next week. In the meantime if you have a chance to do any instrumentation of the JOGLAppletLauncher to see where all of the time is going (makeCurrent()? swapBuffers()? release()?) that would be helpful.
Try moving the swapBuffers() call before release(). That should eliminate the time for swapBuffers since it avoids making the context current again. This is how the JOGL internals are structured.
There are only two operations that could be taking the time here: locking the surface wtih the JAWT and actually doing the wglMakeCurrent call. My guess would be that somehow locking the surface is taking more time in the plug-in, though I can’t guess why.
Could you also print out whenever GLContext.makeCurrent() returns CONTEXT_CURRENT_NEW? That should happen exactly once but I’d like to ensure it isn’t happening every frame.
Tried moving swapBuffers before release()… this caused either a hang or an exception depending on context.setSynchronized(true/false)
The stack trace shows that the swapBuffer invokes maybedosinglethreadworkaround which sends the request swap to another thread.
I’ve also tried with -Dopengl.1thread=false, it solved the exception, but the delay was worse for swapBuffers (around 30 ms).
And last test : the makeCurrent() returns CONTEXT_CURRENT_NEW only once at the beginning.
Oh, and I’ve also checked the EventQueue.invokeAndWait(Runnable) with a dummy runnable (not GL related), and I can perform 100 calls in 6 ms, so this is not the origin of the problem.
Sorry about that. I should have realized that would happen. That might be considered a bug. However I’m leery of adding too much mechanism in this area.
[quote]I’ve also tried with -Dopengl.1thread=false, it solved the exception, but the delay was worse for swapBuffers (around 30 ms).
[/quote]
That -D or calling Threading.disableSingleThreading() would be the only way to work around the issue. I’m very surprised that swapBuffers would be taking this long.
Thanks for verifying that.
[quote]Oh, and I’ve also checked the EventQueue.invokeAndWait(Runnable) with a dummy runnable (not GL related), and I can perform 100 calls in 6 ms, so this is not the origin of the problem.
[/quote]
Thanks for checking this as well.
I think more instrumentation is needed in the WindowsGLContext and WindowsOnscreenGLContext implementations to see exactly where all of the time is going. I’ll try to get to this within the next couple of days and get some people more familiar with the internals of the Java Plug-In to look at a test case. BTW, do you have a particular small applet which exhibits the problem? Is it reproducible with the standard Gears applet if the call to GL.setSwapInterval(1) is removed?
Thanks for the test case. I wrote another one based on it (attached) using just the normal GLEventListener mechanism and put some profiling stuff deeper into JOGL. It looks like all of the time is going in to the low-level call to the WINGDI routine SwapBuffers(). I have no idea why this would have different behavior from one Java Plug-In environment to another. It’s very obvious that when run inside the appletviewer or IE’s plug-in SwapBuffers takes basically zero time, but when in the Mozilla/Firefox plug-in it’s taking on the order of 9 ms/frame. WGL_EXT_swap_control is reported as available in all situations, the chosen pixel format is exactly the same, etc. The thing that’s most confusing to me is that SwapBuffers is a very low-level call which doesn’t even generate a Windows event, and since the plug-in is essentially just a wrapper around a normal JVM, how could any differences in the Windows event dispatching between the two plug-ins make any difference? Anyway, now that I have an instrumented test case I’ll contact the plug-in team next week and try to figure out what’s going on.
We have done some further investigation of this problem internally and it’s pretty mystifying. My co-worker’s two machines with NVidia cards (one with older drivers, one with current drivers) do not exhibit the problem. My old office machine with a GeForce FX 5800 Ultra did, so it’s not something like running low on VRAM (which might be the case on the notebook where the problem also occurs). We eliminated things like the Firefox version as variables. I’ve been in discussions with co-workers who work on the Java Plug-In and we can’t think of a way that the event dispatch structure of the plug-in can affect the speed in this way. I’m thinking it might be something about how Mozilla sets up the window it hands to Java; I checked though and one thing is that Mozilla doesn’t load DDRAW.DLL, which is the only thing I know of that could cause a driver-level incompatibility with OpenGL resulting in a symptom like this. We’re continuing to look into it and I may post on NVidia’s web site for some help once we’ve characterized it a little better.
Could you please tell us exactly what CPU types and speeds, OS versions, graphics cards and driver versions the slowdown happens with? Maybe we can identify a pattern.
Actually I just went back and reread the Jack Flowers thread so see that it’s happening with both ATI and NVidia hardware.
Looks like we might need to support a way to specify -Dsun.java2d.noddraw=true for applets as well as Java Web Start applications. Unfortunately due to the applet lifecycle model (in the browser) I’m not sure that’s possible.
I’m not sure if this is related, but I’m having problems getting any higher than 60fps in any JOGL applet, FF, IE, Applet Launcher or otherwise. I also do not think it is related to JOGLAppletLauncher either, as I used my own applet launcher, and also tried just using JOGL directly in a Frame.
I used the JGears applet as another test, to make sure it wasn’t my code. Even using the FPSAnimator, I couldn’t get higher than 60fps, another strange symptom is if I try and tell it to run at, for example, 40fps, my FPS come out at around 33.
I’m using jdk1.5.0_06, the poor performance is not related to my PC either: 3.2ghz, 1.5gb ram, 256mb GeForce 6800…
Drop me a line at me@sambro.info if you want me to run any tests/debug.
After more investigation it currently looks to me like the slower performance in Mozilla/Firefox looks a lot like wglSwapIntervalEXT(0) silently failing. I’ve posted on opengl.org describing some of the tests that have been done and asking for any input. Let’s see if there are any responses.