static const GLfloat boxSpeed = 1.25f; // per second
// profiler
-enum ProfilerState { statePreRender, stateClear, stateDraw, statePresent, statePostRender, stateOutsideRender, numProfilerStates };
-static const char *profilerStateNames[numProfilerStates] = { "Pre-Render", "Clearing", "Drawing", "Presenting", "Post-Render", "Outside renderer"};
+enum ProfilerState { StatePreRender, StateClear, StateDraw, StatePresent, StatePostRender, StateOutsideRender, NumProfilerStates };
+static const char *profilerStateNames[NumProfilerStates] = { "Pre-Render", "Clearing", "Drawing", "Presenting", "Post-Render", "Outside renderer"};
// utility functions
static double getTime()
// initailize profiler
framect = 0;
memset(stateTime, 0, sizeof(stateTime));
- curState = -1;
+ curState = NumProfilerStates;
lastDisplay = lastProfile = getTime();
}
void profilerTick(ProfilerState nextState)
{
- assert (nextState >= 0 && nextState < numProfilerStates);
+ assert (nextState >= 0 && nextState < NumProfilerStates);
double time = getTime();
- if (curState >= 0)
+ if (curState >= 0 && curState < NumProfilerStates)
stateTime[curState] += time-lastProfile;
curState = nextState;
lastProfile = time;
const double elapsed = time-lastDisplay;
if (elapsed >= 3) {
printf("%.1f fps, time spent: ", framect/elapsed);
- for (int i = 0; i < numProfilerStates; ++i) {
+ for (int i = 0; i < NumProfilerStates; ++i) {
if (i != 0) printf(", ");
printf("%s %.1f%%", profilerStateNames[i], stateTime[i]/elapsed*100);
}
void renderGL()
{
//////////////////////////////////////////////
- profilerTick(statePreRender);
+ profilerTick(StatePreRender);
double time = getTime();
// anim
double passedTime = time-lastFrame;
}
lastFrame = time;
//////////////////////////////////////////////
- profilerTick(stateClear);
+ profilerTick(StateClear);
if (overdraw) {
// clear manually
glBegin(GL_QUADS);
glClear(GL_COLOR_BUFFER_BIT);
}
//////////////////////////////////////////////
- profilerTick(stateDraw);
+ profilerTick(StateDraw);
glBegin(GL_QUADS);
glColor3f(0.8f, 1.0f, 0.75f);
rectQuad(boxPos, 0, boxPos+boxWidth, 1);
glEnd();
usleep(sleep_time*1000);
//////////////////////////////////////////////
- profilerTick(statePresent);
+ profilerTick(StatePresent);
if (copy) {
glDrawBuffer(GL_FRONT);
glCopyPixels(0, 0, getWidth(), getHeight(), GL_COLOR);
getBackend()->swapBuffers();
}
//////////////////////////////////////////////
- profilerTick(statePostRender);
+ profilerTick(StatePostRender);
glFlush();
++framect;
//////////////////////////////////////////////
- profilerTick(stateOutsideRender);
+ profilerTick(StateOutsideRender);
}
virtual void handleKeyPress(KeySym key)
GLfloat boxPos, boxDirection;
// FPS, profiler
double lastDisplay, lastProfile;
- int framect, curState;
- double stateTime[numProfilerStates];
+ int framect;
+ ProfilerState curState;
+ double stateTime[NumProfilerStates];
};
int main(int argc, char ** argv)