Make the state names capital-first
authorRalf Jung <post@ralfj.de>
Tue, 2 Apr 2013 13:42:50 +0000 (15:42 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 2 Apr 2013 13:42:50 +0000 (15:42 +0200)
gltest.cpp

index c66ab32c40efd5db2460da248ad8772e41672d75..ed45ac677a311bad053024b7421b267e1deb3050 100644 (file)
@@ -52,8 +52,8 @@ static const GLfloat boxWidth = 0.045f;
 static const GLfloat boxSpeed = 1.25f; // per second
 
 // profiler
 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()
 
 // utility functions
 static double getTime()
@@ -93,7 +93,7 @@ protected:
                // initailize profiler
                framect = 0;
                memset(stateTime, 0, sizeof(stateTime));
                // initailize profiler
                framect = 0;
                memset(stateTime, 0, sizeof(stateTime));
-               curState = -1;
+               curState = NumProfilerStates;
                lastDisplay = lastProfile = getTime();
        }
        
                lastDisplay = lastProfile = getTime();
        }
        
@@ -113,9 +113,9 @@ protected:
        
        void profilerTick(ProfilerState nextState)
        {
        
        void profilerTick(ProfilerState nextState)
        {
-               assert (nextState >= 0 && nextState < numProfilerStates);
+               assert (nextState >= 0 && nextState < NumProfilerStates);
                double time = getTime();
                double time = getTime();
-               if (curState >= 0)
+               if (curState >= 0 && curState < NumProfilerStates)
                        stateTime[curState] += time-lastProfile;
                curState = nextState;
                lastProfile = time;
                        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);
                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);
                        }
                                if (i != 0) printf(", ");
                                printf("%s %.1f%%", profilerStateNames[i], stateTime[i]/elapsed*100);
                        }
@@ -137,7 +137,7 @@ protected:
        void renderGL()
        {              
                //////////////////////////////////////////////
        void renderGL()
        {              
                //////////////////////////////////////////////
-               profilerTick(statePreRender);
+               profilerTick(StatePreRender);
                double time = getTime();
                // anim
                double passedTime = time-lastFrame;
                double time = getTime();
                // anim
                double passedTime = time-lastFrame;
@@ -154,7 +154,7 @@ protected:
                }
                lastFrame = time;
                //////////////////////////////////////////////
                }
                lastFrame = time;
                //////////////////////////////////////////////
-               profilerTick(stateClear);
+               profilerTick(StateClear);
                if (overdraw) {
                        // clear manually
                        glBegin(GL_QUADS);
                if (overdraw) {
                        // clear manually
                        glBegin(GL_QUADS);
@@ -166,14 +166,14 @@ protected:
                        glClear(GL_COLOR_BUFFER_BIT);
                }
                //////////////////////////////////////////////
                        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);
                //////////////////////////////////////////////
                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);
                if (copy) {
                        glDrawBuffer(GL_FRONT);
                        glCopyPixels(0, 0, getWidth(), getHeight(), GL_COLOR);
@@ -183,11 +183,11 @@ protected:
                        getBackend()->swapBuffers();
                }
                //////////////////////////////////////////////
                        getBackend()->swapBuffers();
                }
                //////////////////////////////////////////////
-               profilerTick(statePostRender);
+               profilerTick(StatePostRender);
                glFlush();
                ++framect;
                //////////////////////////////////////////////
                glFlush();
                ++framect;
                //////////////////////////////////////////////
-               profilerTick(stateOutsideRender);
+               profilerTick(StateOutsideRender);
        }
        
        virtual void handleKeyPress(KeySym key)
        }
        
        virtual void handleKeyPress(KeySym key)
@@ -207,8 +207,9 @@ private:
        GLfloat boxPos, boxDirection;
        // FPS, profiler
        double lastDisplay, lastProfile;                 
        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)
 };
 
 int main(int argc, char ** argv)