From fde2054e0dde32f04596d7f20fba7f9aeba3dbdd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 2 Apr 2013 15:42:50 +0200 Subject: [PATCH 1/1] Make the state names capital-first --- gltest.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/gltest.cpp b/gltest.cpp index c66ab32..ed45ac6 100644 --- a/gltest.cpp +++ b/gltest.cpp @@ -52,8 +52,8 @@ static const GLfloat boxWidth = 0.045f; 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() @@ -93,7 +93,7 @@ protected: // initailize profiler framect = 0; memset(stateTime, 0, sizeof(stateTime)); - curState = -1; + curState = NumProfilerStates; lastDisplay = lastProfile = getTime(); } @@ -113,9 +113,9 @@ protected: 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; @@ -123,7 +123,7 @@ protected: 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); } @@ -137,7 +137,7 @@ protected: void renderGL() { ////////////////////////////////////////////// - profilerTick(statePreRender); + profilerTick(StatePreRender); double time = getTime(); // anim double passedTime = time-lastFrame; @@ -154,7 +154,7 @@ protected: } lastFrame = time; ////////////////////////////////////////////// - profilerTick(stateClear); + profilerTick(StateClear); if (overdraw) { // clear manually glBegin(GL_QUADS); @@ -166,14 +166,14 @@ protected: 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); @@ -183,11 +183,11 @@ protected: getBackend()->swapBuffers(); } ////////////////////////////////////////////// - profilerTick(statePostRender); + profilerTick(StatePostRender); glFlush(); ++framect; ////////////////////////////////////////////// - profilerTick(stateOutsideRender); + profilerTick(StateOutsideRender); } virtual void handleKeyPress(KeySym key) @@ -207,8 +207,9 @@ private: 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) -- 2.30.2