1 | /* |
2 | * fg_display.c |
3 | * |
4 | * Display message posting, context buffer swapping. |
5 | * |
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 |
9 | * |
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: |
16 | * |
17 | * The above copyright notice and this permission notice shall be included |
18 | * in all copies or substantial portions of the Software. |
19 | * |
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. |
26 | */ |
27 | |
28 | #include <GL/freeglut.h> |
29 | #include "fg_internal.h" |
30 | |
31 | |
32 | /* Function prototypes */ |
33 | extern void fgPlatformGlutSwapBuffers( SFG_PlatformDisplay *pDisplayPtr, SFG_Window* CurrentWindow ); |
34 | |
35 | |
36 | /* -- INTERFACE FUNCTIONS -------------------------------------------------- */ |
37 | |
38 | /* |
39 | * Marks the current window to have the redisplay performed when possible... |
40 | */ |
41 | void FGAPIENTRY glutPostRedisplay( void ) |
42 | { |
43 | FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPostRedisplay" ); |
44 | if ( ! fgStructure.CurrentWindow ) |
45 | { |
46 | fgError ( " ERROR: Function <%s> called" |
47 | " with no current window defined." , "glutPostRedisplay" ) ; |
48 | } |
49 | |
50 | fgStructure.CurrentWindow->State.WorkMask |= GLUT_DISPLAY_WORK; |
51 | } |
52 | |
53 | /* |
54 | * Swaps the buffers for the current window (if any) |
55 | */ |
56 | void FGAPIENTRY glutSwapBuffers( void ) |
57 | { |
58 | FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSwapBuffers" ); |
59 | FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSwapBuffers" ); |
60 | |
61 | /* |
62 | * "glXSwapBuffers" already performs an implicit call to "glFlush". What |
63 | * about "SwapBuffers"? |
64 | */ |
65 | glFlush( ); |
66 | if( ! fgStructure.CurrentWindow->Window.DoubleBuffered ) |
67 | return; |
68 | |
69 | fgPlatformGlutSwapBuffers( &fgDisplay.pDisplay, fgStructure.CurrentWindow ); |
70 | |
71 | /* GLUT_FPS env var support */ |
72 | if( fgState.FPSInterval ) |
73 | { |
74 | GLint t = glutGet( GLUT_ELAPSED_TIME ); |
75 | fgState.SwapCount++; |
76 | if( fgState.SwapTime == 0 ) |
77 | fgState.SwapTime = t; |
78 | else if( t - fgState.SwapTime > fgState.FPSInterval ) |
79 | { |
80 | float time = 0.001f * ( t - fgState.SwapTime ); |
81 | float fps = ( float )fgState.SwapCount / time; |
82 | fprintf( stderr, |
83 | "freeglut: %d frames in %.2f seconds = %.2f FPS\n" , |
84 | fgState.SwapCount, time, fps ); |
85 | fgState.SwapTime = t; |
86 | fgState.SwapCount = 0; |
87 | } |
88 | } |
89 | } |
90 | |
91 | /* |
92 | * Mark appropriate window to be displayed |
93 | */ |
94 | void FGAPIENTRY glutPostWindowRedisplay( int windowID ) |
95 | { |
96 | SFG_Window* window; |
97 | |
98 | FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPostWindowRedisplay" ); |
99 | window = fgWindowByID( windowID ); |
100 | freeglut_return_if_fail( window ); |
101 | window->State.WorkMask |= GLUT_DISPLAY_WORK; |
102 | } |
103 | |
104 | /*** END OF FILE ***/ |
105 | |