frame rate issue

i have a problem with my jogl aplication and im not sure if the problem lies within my own code or in jogl itself

on my pc and the two other pc’s ive tested it it gives a constant 60 frame a second smooth animation but every now and again my framerate falls to Exactly 30 fps and then a couple of seconds later it wil jump back to 60. the weirdest thing is that during this few seconds the framerate stays Exactly 30 no matter what is being rendered. i tried it on both ATI and NVIDIA cards

You usually see this when you’ve enabled v-sync (vertical sync) for your video card and then the timing is off slightly for when a frame is ready versus when the display is ready to display it. When this occurs the frame is delayed a refresh before it is displayed (which explains the exact multiples of the refresh rate), and in double buffered rendering the front and back buffers can’t be swapped while waiting for the display.

The solution is called triple buffering, and unfortunately there aren’t many (any?) tutorials on how to implement it with OpenGL nor do I have that knowledge.

thnx a lot now i at least understand whats causing it and i think il be able to take it from here by googling it

There is no standard OpenGL API call to enable triple-buffering, however, if you go and look in your display driver properties, quite a few drivers now have an option to enable it, so it’ll be down to your user to make this performance tweak. Triple buffering only helps in a few borderline cases mind you, and comes at the cost of a fair chunk of VRAM, the use of which might actually slow down your application further if it’s texture upload bound.

Cas :slight_smile:

I’d hardly say that it uses a fair chunk of memory, it’s only a single extra back buffer, width x height x bit-depth, which would be roughly comparable to a single additional texture without mipmaps.

Depending on your resolution and the amount of VRAM you’ve got that might amount to having to do another big texture swap every frame which might even be slower in certain circumstances (although I admit it’s unlikely on anything vaguely recent, there are a lot of cards out there with pretty limited VRAM still in circulation). Just an idle thought really.

Cas :slight_smile:

enabling tripple buffering in CCC is not making any difference for me. it might be that my rendering is just very unoptimized, ive put alot of time into the engine but i have no idea realy if what im doing is right since i cant realy find good opengl tutorials that goes past the basics, ive implemented VBO, scene graphing, lighting, textures, decoupled rendering and physics and im blending between physic steps etc. but ive pretty much just ‘guessed’ the code since good more advanced tutorials is scarce (or maybe i just suck at finding them). so i guess il have to work through everything again can any1 maybe suggest a good place to read up on optimizing stuff. i dont even know if im using the right terms since im actualy a bussines programmer and i just do this for a hobby

  1. Try Animator with setRunAsFastAsPossible to true (or FPSAnimator with higher FPS and scheduleAtFixedRate to true). Then do Thread.sleep(…) yourself.

  2. You may have selected a display mode that locks it at a certain FPS. Try it windowed instead of fullscreen.

  3. Maybe the garbage collector is lowering FPS?

When you have a valid GL object, call setSwapInterval(0) to disable vsync. I’ve had to do this on windows machines to get the framerate above 60.

Actually I consider this a disputable advice, since disabling vsync will introduce tearing and the benefits of higher framerates than 60 fps are at least controversal.

It’s handy for performance benchmarking though.

Cas :slight_smile:

I agree, but it is a possible solution, and most games give the option to disable vsync. So now he knows how, too. :slight_smile: