Hello Charles,
Sorry for being late to answer but my matters took me a little longer than I'd planned. And I also needed time to prepare for the conversation refreshening what was forgotten in the past three years.
So let's start with a Happy Easter to you and the OxygenBasic community!
Now to the subject matter. Everything that I have to say is based on my own experience and a hell of a lot of trial and error. Be assured that I've turned over a pile of relevant literature and web data learning my lessons the hard way.
Part I: Sleep() ConsiderationsWhile the idea of using Sleep() to control your framerate may seem attractive, it has several serious drawbacks:
1. Besides timing
per se you have to deal with similar inherent inaccuracy of Sleep(), which effectively doubles the number of disturbing factors in your rendering loop.
2. For heavily populated and textured scenes, Sleep()'s resolution may need to go down arithmetically to a sub-tick level within the rigid 60 (or 30) FPS constrains imposed by VSYNC. This isn't however possible. The default resolution of Sleep() is 16 ticks for an NT-based kernel and it can only be changed using a call to
timeBeginPeriod(n) which resides in Winmm.dll. (Be sure to use a matching call to
timeEndPeriod(n) while experimenting or your system clock potentially being used by other concurrent processes may be compromised till the very end of the current session!)
The finest setting of
n in this call is 1 tick and you can't go any lower. 1 tick is however very nice for other applications not related to OpenGL, isn't it?
3. An excellent Windows OpenGL implementation by nVidia (you have an nVidia video card, haven't you?) is a multi-threaded application that has its own timing facilities and optimum strategies targeting the fastest (and smoothest) rendering on a given HW platform.
For example, if you open up your nVidia Control Center, you may find the following setting there (that's my Vista setup with the latest nVidia drivers installed):
As you see, OpenGL can spawn (of course depending on your CPU) up to 4 additional threads to
pre-calculate and pre-render in advance up to 4 frames of your video flow. Clear enough, it can do it only if the remaining time slice so permits. Meddling with Sleep() in the program code may severely compromize OpenGL's abilities to self-control.
There may appear other unexpected bottlenecks in OpenGL depending on whether it has sufficient time to perform all the tasks scheduled for the current time- and render-frame for the given system settings and a particular rendering strategy (immediate mode, display lists, VBO's, shaders) and its dependencies.
So Sleep() is too rough an instrument to slice OpenGL with
except some very rare cases where its current implementation is not flexible enough to give us what we need. Such cases are usually labeled with "upgrade your hardware" verdict.
ConclusionSubsequent Parts will follow depending on how our discussion is going to develop. All my illustrations and explanations (but not the source code, sorry) will be based on i) the most stringent conditions our XANEngine has ever faced, and ii) on the real-world data from the Resident Evil 5: Lost in Nightmares (Playstation 2) game package.
You can download a freeware version of
Resident Evil 5 Benchmark Edition for desktop PC's to see how poor your computer hardware really is by Capcom Ltd.'s standards:
I remember I was so dissatisfied with their verdict that I accepted my French friend's invitation to join him in the XANEngine project without hesitation to show the Japs how terribly wrong they were with their miserable attempts to lure us into buying their overpriced Playstations.