Profiling OpenGL ES App
Nick Wrote:Might you be willing to share some of that code. I've been reading over the link Frank posted but for some reason I can't seem to wrap my head around how to do that using Objective-C.
The trick I use when working with Objective-C is to avoid it as much as possible

Here's my "get time" function (there are a few discussions on using "mach time" if you search the forum):
Code:
double CurrentTime(void)
{
static double conversion = 0.0;
if( conversion == 0.0 )
{
mach_timebase_info_data_t info = {0,0};
kern_return_t err = mach_timebase_info(&info);
if (!err) {
conversion = 1e-9 * (double)info.numer/(double)info.denom;
}
}
return conversion * (double)mach_absolute_time();
}And here's my run-frame function, minus some fluff:
Code:
double gameRunFrame(void)
{
static double currentTime = 0.0;
static double accumulator = 0.0;
static double drawTime = 0.0;
static double drawDelta = 0.0;
double newTime, deltaTime;
newTime = CurrentTime();
deltaTime = newTime - currentTime;
if (deltaTime > kGameFrameMaxDelta) {
deltaTime = kGameFrameMaxDelta;
} else if (deltaTime <= 0.0) {
deltaTime = 0.0;
drawTime = 0.0;
drawDelta = 0.0;
}
currentTime = newTime;
if (gameState != kGameStatePaused) {
gameTime += deltaTime;
accumulator += deltaTime;
while (accumulator >= kGameFrameStepInterval) {
accumulator -= kGameFrameStepInterval;
gameStep(kGameFrameStepInterval);
}
}
drawDelta += deltaTime;
if (currentTime > drawTime) {
drawTime = currentTime + kGameFrameDrawInterval;
deltaTime = drawDelta;
drawDelta = 0.0;
return deltaTime;
}
return -1.0;
}That gameRunFrame function is called from the NSTimer callback in my EAGLView class:
Code:
- (void)runFrame {
double dt = gameRunFrame();
if (dt >= 0.0) {
gameDrawFrame(dt);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
}Hopefully the other functions (gameStep, gameDrawFrame) are self explanatory. I keep gameTime exposed globally since it's handy to have around everywhere, ditto for gameState. My typical settings for the frame constants are:
Code:
#define kGameFrameIntervalNormal 1.0/120.0
#define kGameFrameIntervalIdle 1.0/10.0
#define kGameFrameStepInterval 1.0/60.0
#define kGameFrameDrawInterval 1.0/33.0
#define kGameFrameMaxDelta 1.0/10.0So - kGameFrameIntervalNormal is the timer frequency, kGameFrameIntervalIdle is the timer frequency when the app is "idle" (the app delegate decides when to use that). kGameFrameStepInterval is the guaranteed frequency for physics/logic steps and kGameFrameDrawInterval is the maximum frame rate (not guaranteed). Note that I set kGameFrameDrawInterval 10% higher than I actually need it, since you still get some blocking issues with the timer at 120Hz. kGameFrameMaxDelta is there to ensure simulations won't explode when the renderer is bogging - if the game hits that limit it won't be realtime, but at least it won't freeze up or go totally wacky.
I should also note that I don't bother doing any drawing interpolation on the iPhone, since physics updates are never fewer than screen updates. This greatly simplifies gameRunFrame and gameDrawFrame.
| Messages In This Thread |
|
Profiling OpenGL ES App - Nick - Feb 15, 2009, 09:11 PM
Profiling OpenGL ES App - Nick - Feb 15, 2009, 09:31 PM
Profiling OpenGL ES App - Frank C. - Feb 15, 2009, 10:15 PM
Profiling OpenGL ES App - Nick - Feb 15, 2009, 10:58 PM
Profiling OpenGL ES App - Nosredna - Feb 16, 2009, 08:54 AM
Profiling OpenGL ES App - AnotherJake - Feb 16, 2009, 10:22 AM
Profiling OpenGL ES App - Nosredna - Feb 16, 2009, 11:16 AM
Profiling OpenGL ES App - Nick - Feb 16, 2009, 02:30 PM
Profiling OpenGL ES App - Frank C. - Feb 16, 2009 03:12 PM
Profiling OpenGL ES App - AnotherJake - Feb 16, 2009, 03:16 PM
Profiling OpenGL ES App - AnotherJake - Feb 16, 2009, 03:37 PM
Profiling OpenGL ES App - Frank C. - Feb 16, 2009, 04:28 PM
Profiling OpenGL ES App - Nick - Feb 16, 2009, 04:34 PM
Profiling OpenGL ES App - Frank C. - Mar 8, 2009, 03:45 PM
Profiling OpenGL ES App - imikedaman - Mar 8, 2009, 09:13 PM
Profiling OpenGL ES App - AnotherJake - Mar 9, 2009, 08:08 AM
Profiling OpenGL ES App - dave1 - Apr 17, 2009, 02:06 PM
Profiling OpenGL ES App - riruilo - Jan 19, 2010, 07:52 AM
Profiling OpenGL ES App - warmi - Jan 19, 2010, 09:29 AM
Profiling OpenGL ES App - riruilo - Jan 19, 2010, 11:31 AM
Profiling OpenGL ES App - Frank C. - Jan 19, 2010, 08:50 PM
|
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Profiling the non-OpenGL parts of my game | monteboyd | 10 | 3,026 |
Oct 25, 2012 04:03 PM Last Post: monteboyd |
|

