X-Git-Url: https://git.ralfj.de/gltest.git/blobdiff_plain/21689b45f8d7e28bd6be565758bec0205abb8416..79f0d8c1561efc7221621e2024d08f8fd6061204:/gltest.cpp diff --git a/gltest.cpp b/gltest.cpp index 0cae932..fbe79a8 100644 --- a/gltest.cpp +++ b/gltest.cpp @@ -34,8 +34,8 @@ static const GLfloat boxWidth = 0.045f; static const GLfloat boxSpeed = 1.25f; // per second // profiler -enum ProfilerState { statePreRender, stateDraw, statePresent, statePostRender, stateOutsideRender, numProfilerStates }; -static const char *profilerStateNames[numProfilerStates] = { "Pre-Render", "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() @@ -45,15 +45,19 @@ static double getTime() return tp.tv_sec + 1e-9 * tp.tv_nsec; } -static void drawRect(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +static void rectVertices(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) { - glVertex2f(x1, y1); glVertex2f(x2, y1); glVertex2f(x2, y2); glVertex2f(x1, y2); + glVertex2f(x1, y1); + glVertex2f(x2, y1); + glVertex2f(x2, y2); + glVertex2f(x1, y2); } // the window class TearTestWindow : public GLWindow { public: - TearTestWindow(bool overdraw, bool copy) : GLWindow(XOpenDisplay(0), createGLBackend()), overdraw(overdraw), copy(copy), boxPos(0), boxDirection(1) + TearTestWindow(bool overdraw, bool copy, int sleep_time) : GLWindow(XOpenDisplay(0), createGLBackend()), + overdraw(overdraw), copy(copy), sleep_time(sleep_time), boxPos(0), boxDirection(1) {} void setSwapInterval(int i) { @@ -132,20 +136,24 @@ protected: } lastFrame = time; ////////////////////////////////////////////// - profilerTick(stateDraw); + profilerTick(stateClear); if (overdraw) { - glBegin(GL_QUADS); // clear manually + glBegin(GL_QUADS); glColor3f(0.0f, 0.0f, 0.0f); - drawRect(0, 0, 1, 1); + rectVertices(0, 0, 1, 1); + glEnd(); } else { glClear(GL_COLOR_BUFFER_BIT); - glBegin(GL_QUADS); } + ////////////////////////////////////////////// + profilerTick(stateDraw); + glBegin(GL_QUADS); glColor3f(0.8f, 1.0f, 0.75f); - drawRect(boxPos, 0, boxPos+boxWidth, 1); + rectVertices(boxPos, 0, boxPos+boxWidth, 1); glEnd(); + usleep(sleep_time*1000); ////////////////////////////////////////////// profilerTick(statePresent); if (copy) { @@ -175,16 +183,16 @@ protected: private: bool overdraw, copy; + int sleep_time; + // animation control double lastFrame; GLfloat boxPos, boxDirection; - // FPS + // FPS, profiler double lastDisplay, lastProfile; int framect, curState; double stateTime[numProfilerStates]; }; - - int main(int argc, char ** argv) { // program options handling @@ -194,6 +202,7 @@ int main(int argc, char ** argv) ("swap-interval,i", po::value(), "set swap interval") ("copy,c", "copy to front buffer (instead of performing a buffer swap)") ("overdraw,o", "overdraw previous image (instead of calling glClear)") + ("sleep,s", po::value()->default_value(0), "Number of milliseconds to sleap in each frame (in the drawing phase)") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -205,7 +214,7 @@ int main(int argc, char ** argv) } // actual program - TearTestWindow w(vm.count("overdraw"), vm.count("copy")); + TearTestWindow w(vm.count("overdraw"), vm.count("copy"), vm["sleep"].as()); w.open(800, 600); if (vm.count("swap-interval")) w.setSwapInterval(vm["swap-interval"].as());