First group of patches: Adds single-buffered rendering (or its emulation) in Windows.
[freeglut] / freeglut-1.3 / freeglut_display.c
1 /*
2  * freeglut_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 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #define  G_LOG_DOMAIN  "freeglut-display"
33
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
36
37
38 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
39
40 /*
41  * Marks the current window to have the redisplay performed when possible...
42  */
43 void FGAPIENTRY glutPostRedisplay( void )
44 {
45     /*
46      * Is there a current window set?
47      */
48     freeglut_assert_ready; freeglut_assert_window;
49
50     /*
51      * Just mark the window as one that we need to redisplay...
52      */
53     fgStructure.Window->State.Redisplay = TRUE;
54 }
55
56 /*
57  * Swaps the buffers for the current window (if any)
58  */
59 void FGAPIENTRY glutSwapBuffers( void )
60 {
61     /*
62      * As long as we've got a current window set...
63      */
64     freeglut_assert_ready; freeglut_assert_window;
65
66     /*
67      * Have the mouse cursor and/or the menus drawn for the current window
68      */
69     fgDisplayMenu();
70     fgDisplayCursor();
71
72     /*
73      * Make sure the current context is flushed
74      */
75     glFlush();
76
77     /*
78      * If it's single-buffered, we shouldn't be here.
79      */
80     if ( ! fgStructure.Window->Window.DoubleBuffered ) return ;
81
82 #if TARGET_HOST_UNIX_X11
83     /*
84      * Issue the glXSwapBuffers call and be done with it
85      */
86     glXSwapBuffers( fgDisplay.Display, fgStructure.Window->Window.Handle );
87
88 #elif TARGET_HOST_WIN32
89     /*
90      * Swap the window's buffers
91      */
92     SwapBuffers( fgStructure.Window->Window.Device );
93
94 #endif
95 }
96
97 /*
98  * Mark appropriate window to be displayed
99  */
100 void FGAPIENTRY glutPostWindowRedisplay( int windowID )
101 {
102     SFG_Window* window;
103
104     freeglut_assert_ready;
105
106     /*
107      * Try looking for the window
108      */
109     window = fgWindowByID( windowID );
110
111     /*
112      * If failed, return
113      */
114     freeglut_return_if_fail( window != NULL );
115
116     /*
117      * Otherwise mark the window for being redisplayed
118      */
119     window->State.Redisplay = TRUE;
120 }
121
122 /*** END OF FILE ***/