home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / MesaDLL / glut_swap.cpp < prev    next >
C/C++ Source or Header  |  2002-12-14  |  2KB  |  68 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994, 1997.  */
  3.  
  4. /* This program is freely distributable without licensing fees
  5.    and is provided without guarantee or warrantee expressed or
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <stdio.h>
  9. #include "glutint.h"
  10.  
  11. GLint __glutFPS = 0;
  12. GLint __glutSwapCount = 0;
  13. GLint __glutSwapTime = 0;
  14.  
  15. /* CENTRY */
  16. void GLUTAPIENTRY
  17. glutSwapBuffers(void)
  18. {
  19.   GLUTwindow *window = __glutCurrentWindow;
  20.  
  21.   if (window->renderWin == window->win) {
  22.     if (__glutCurrentWindow->treatAsSingle) {
  23.       /* Pretend the double buffered window is single buffered,
  24.          so treat glutSwapBuffers as a no-op. */
  25.       return;
  26.     }
  27.   } else {
  28.     if (__glutCurrentWindow->overlay->treatAsSingle) {
  29.       /* Pretend the double buffered overlay is single
  30.          buffered, so treat glutSwapBuffers as a no-op. */
  31.       return;
  32.     }
  33.   }
  34.  
  35.   /* For the MESA_SWAP_HACK. */
  36.   window->usedSwapBuffers = 1;
  37.  
  38.   SWAP_BUFFERS_LAYER(__glutCurrentWindow);
  39.  
  40.   /* I considered putting the window being swapped on the
  41.      GLUT_FINISH_WORK work list because you could call
  42.      glutSwapBuffers from an idle callback which doesn't call
  43.      __glutSetWindow which normally adds indirect rendering
  44.      windows to the GLUT_FINISH_WORK work list.  Not being put
  45.      on the list could lead to the buffering up of multiple
  46.      redisplays and buffer swaps and hamper interactivity.  I
  47.      consider this an application bug due to not using
  48.      glutPostRedisplay to trigger redraws.  If
  49.      glutPostRedisplay were used, __glutSetWindow would be
  50.      called and a glFinish to throttle buffering would occur. */
  51.  
  52.   if (__glutFPS) {
  53.      GLint t = glutGet(GLUT_ELAPSED_TIME);
  54.      __glutSwapCount++;
  55.      if (__glutSwapTime == 0)
  56.         __glutSwapTime = t;
  57.      else if (t - __glutSwapTime > __glutFPS) {
  58.         float time = 0.001 * (t - __glutSwapTime);
  59.         float fps = (float) __glutSwapCount / time;
  60.         fprintf(stderr, "GLUT: %d frames in %.2f seconds = %.2f FPS\n",
  61.                 __glutSwapCount, time, fps);
  62.         __glutSwapTime = t;
  63.         __glutSwapCount = 0;
  64.      }
  65.   }
  66. }
  67. /* ENDCENTRY */
  68.