configure: allow C{,XX}FLAGS override
[mesa.git] / src / glut / glx / glut_swap.c
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 (__glutPPMFile) {
22 __glutWritePPMFile();
23 }
24
25 if (window->renderWin == window->win) {
26 if (__glutCurrentWindow->treatAsSingle) {
27 /* Pretend the double buffered window is single buffered,
28 so treat glutSwapBuffers as a no-op. */
29 return;
30 }
31 } else {
32 if (__glutCurrentWindow->overlay->treatAsSingle) {
33 /* Pretend the double buffered overlay is single
34 buffered, so treat glutSwapBuffers as a no-op. */
35 return;
36 }
37 }
38
39 /* For the MESA_SWAP_HACK. */
40 window->usedSwapBuffers = 1;
41
42 SWAP_BUFFERS_LAYER(__glutCurrentWindow);
43
44 /* I considered putting the window being swapped on the
45 GLUT_FINISH_WORK work list because you could call
46 glutSwapBuffers from an idle callback which doesn't call
47 __glutSetWindow which normally adds indirect rendering
48 windows to the GLUT_FINISH_WORK work list. Not being put
49 on the list could lead to the buffering up of multiple
50 redisplays and buffer swaps and hamper interactivity. I
51 consider this an application bug due to not using
52 glutPostRedisplay to trigger redraws. If
53 glutPostRedisplay were used, __glutSetWindow would be
54 called and a glFinish to throttle buffering would occur. */
55
56 if (__glutFPS) {
57 GLint t = glutGet(GLUT_ELAPSED_TIME);
58 __glutSwapCount++;
59 if (__glutSwapTime == 0)
60 __glutSwapTime = t;
61 else if (t - __glutSwapTime > __glutFPS) {
62 float time = 0.001 * (t - __glutSwapTime);
63 float fps = (float) __glutSwapCount / time;
64 fprintf(stderr, "GLUT: %d frames in %.2f seconds = %.2f FPS\n",
65 __glutSwapCount, time, fps);
66 __glutSwapTime = t;
67 __glutSwapCount = 0;
68 }
69 }
70 }
71 /* ENDCENTRY */