Moving X11-specific code from "freeglut_display.c" into its own file
[freeglut] / src / Common / freeglut_display.c
1 /*\r
2  * freeglut_display.c\r
3  *\r
4  * Display message posting, context buffer swapping.\r
5  *\r
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.\r
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>\r
8  * Creation date: Fri Dec 3 1999\r
9  *\r
10  * Permission is hereby granted, free of charge, to any person obtaining a\r
11  * copy of this software and associated documentation files (the "Software"),\r
12  * to deal in the Software without restriction, including without limitation\r
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
14  * and/or sell copies of the Software, and to permit persons to whom the\r
15  * Software is furnished to do so, subject to the following conditions:\r
16  *\r
17  * The above copyright notice and this permission notice shall be included\r
18  * in all copies or substantial portions of the Software.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
26  */\r
27 \r
28 #include <GL/freeglut.h>\r
29 #include "freeglut_internal.h"\r
30 \r
31 \r
32 /* Function prototypes */\r
33 extern void fgPlatformGlutSwapBuffers( SFG_PlatformDisplay *pDisplayPtr, SFG_Window* CurrentWindow );\r
34 \r
35 \r
36 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */\r
37 \r
38 /*\r
39  * Marks the current window to have the redisplay performed when possible...\r
40  */\r
41 void FGAPIENTRY glutPostRedisplay( void )\r
42 {\r
43     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPostRedisplay" );\r
44     if ( ! fgStructure.CurrentWindow )\r
45         {\r
46       fgError ( " ERROR:  Function <%s> called"\r
47                 " with no current window defined.", "glutPostRedisplay" ) ;\r
48         }\r
49 \r
50     fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;\r
51 }\r
52 \r
53 /*\r
54  * Swaps the buffers for the current window (if any)\r
55  */\r
56 void FGAPIENTRY glutSwapBuffers( void )\r
57 {\r
58     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSwapBuffers" );\r
59     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSwapBuffers" );\r
60 \r
61     /*\r
62      * "glXSwapBuffers" already performs an implicit call to "glFlush". What\r
63      * about "SwapBuffers"?\r
64      */\r
65     glFlush( );\r
66     if( ! fgStructure.CurrentWindow->Window.DoubleBuffered )\r
67         return;\r
68 \r
69     fgPlatformGlutSwapBuffers( &fgDisplay.pDisplay, fgStructure.CurrentWindow );\r
70 \r
71     /* GLUT_FPS env var support */\r
72     if( fgState.FPSInterval )\r
73     {\r
74         GLint t = glutGet( GLUT_ELAPSED_TIME );\r
75         fgState.SwapCount++;\r
76         if( fgState.SwapTime == 0 )\r
77             fgState.SwapTime = t;\r
78         else if( t - fgState.SwapTime > fgState.FPSInterval )\r
79         {\r
80             float time = 0.001f * ( t - fgState.SwapTime );\r
81             float fps = ( float )fgState.SwapCount / time;\r
82             fprintf( stderr,\r
83                      "freeglut: %d frames in %.2f seconds = %.2f FPS\n",\r
84                      fgState.SwapCount, time, fps );\r
85             fgState.SwapTime = t;\r
86             fgState.SwapCount = 0;\r
87         }\r
88     }\r
89 }\r
90 \r
91 /*\r
92  * Mark appropriate window to be displayed\r
93  */\r
94 void FGAPIENTRY glutPostWindowRedisplay( int windowID )\r
95 {\r
96     SFG_Window* window;\r
97 \r
98     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPostWindowRedisplay" );\r
99     window = fgWindowByID( windowID );\r
100     freeglut_return_if_fail( window );\r
101     window->State.Redisplay = GL_TRUE;\r
102 }\r
103 \r
104 /*** END OF FILE ***/\r