4 * Display message posting, context buffer swapping.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define G_LOG_DOMAIN "freeglut-display"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
38 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
41 * Marks the current window to have the redisplay performed when possible...
43 void FGAPIENTRY glutPostRedisplay( void )
46 * Is there a current window set?
48 freeglut_assert_ready; freeglut_assert_window;
51 * Just mark the window as one that we need to redisplay...
53 fgStructure.Window->State.Redisplay = TRUE;
57 * Swaps the buffers for the current window (if any)
59 void FGAPIENTRY glutSwapBuffers( void )
62 * As long as we've got a current window set...
64 freeglut_assert_ready; freeglut_assert_window;
67 * Have the mouse cursor and/or the menus drawn for the current window
73 * Make sure the current context is flushed
78 * If it's single-buffered, we shouldn't be here.
80 if ( ! fgStructure.Window->Window.DoubleBuffered ) return ;
82 #if TARGET_HOST_UNIX_X11
84 * Issue the glXSwapBuffers call and be done with it
86 glXSwapBuffers( fgDisplay.Display, fgStructure.Window->Window.Handle );
88 #elif TARGET_HOST_WIN32
90 * Swap the window's buffers
92 SwapBuffers( fgStructure.Window->Window.Device );
96 /* GLUT_FPS env var support */
97 if (fgState.FPSInterval) {
98 GLint t = glutGet(GLUT_ELAPSED_TIME);
100 if (fgState.SwapTime == 0)
101 fgState.SwapTime = t;
102 else if (t - fgState.SwapTime > fgState.FPSInterval) {
103 float time = 0.001f * (t - fgState.SwapTime);
104 float fps = (float) fgState.SwapCount / time;
105 fprintf(stderr, "freeglut: %d frames in %.2f seconds = %.2f FPS\n",
106 fgState.SwapCount, time, fps);
107 fgState.SwapTime = t;
108 fgState.SwapCount = 0;
114 * Mark appropriate window to be displayed
116 void FGAPIENTRY glutPostWindowRedisplay( int windowID )
120 freeglut_assert_ready;
123 * Try looking for the window
125 window = fgWindowByID( windowID );
130 freeglut_return_if_fail( window != NULL );
133 * Otherwise mark the window for being redisplayed
135 window->State.Redisplay = TRUE;
138 /*** END OF FILE ***/