Insight about bizarre performance behavior?
I'm not sure this is the best place to post this, but it's not a "beginner" issue (I wouldn't think).
I wrote a simple MC-like game engine that renders a world of ground and trees. I can configure the rendered part of the world to be any power of two, typically 128 - 1024 blocks.
If I set the world-size and other metrics to some value and run the game, I get perhaps 88 fps most times, and occasionally 170 fps, and very rarely 260 fps.
The difference is confounding me; it has something to do with GPU state, as I have ruled out the following:
* World geometry (size, scale)
* Number of pixels shaded
* Other work on the GPU
The geometry is all static (I have removed all dynamics while I sort this problem out). Here are some other details:
* The scene includes two textures: a skybox and a mip-mapped texture-atlas (manual mip-map images)
* World geometry is fully meshed (1,000 to 60,000 quads, rendered as separate indexed triangles from VBO/Index buffer combo)
* Language is Java, using JOGL as an interface to OpenGL
* No lighting logic; "shade" value provided per-vertex from ambient occlusion algorithm
Try as I might, I can find no reason why one run gets 80fps, and the next more than 3 times that, using the same geometry and other settings. It is as if there were an alignment problem with the VBO data most of the time.
Things I have tried:
* Limit world to use a single [sub] texture
* Eliminate all trees and render just a flat world (meshing reduces this to very few quads, yet performance problem persist most of the time)
* Try different FPS calculators (my own, one from a book, etc.)
Does anybody have any suggestions why the program runs so fast some times and so slow others? Ignoring my environment and OpenGL API library, what things might cause this to occur?
I very much appreciate any insight. I am thus far stumped on this one.
Oh, I should mention I am using frustum occlusion, but that has nearly zero impact on the frame rate. If I render the world in strictly linear order (as a 2-dimensional array), the FPS numbers are the same looking across the world from all four corners.
Oh, and these numbers are on my 6-core PC with a Radeon 5870, but I get similar results on an Alienware dual nVidia GTX 590 box (though the numbers are higher), and several others.
I found the problem. Using JOGL, I was using a NEWT window and calling windowRepaint(...) on every frame to force an update. It turns out this method is safe to call within the display method because it uses AWT, so evidently most of the time the AWT monster was stalling the update.
I switched to calling display() manually from outside the render loop and my frame rates are now between 313 (with a huge world) and 1400 (with smallish one).