Merged lockstep branch.
[neverball] / share / sync.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #include "glext.h"
16
17 /*---------------------------------------------------------------------------*/
18 #ifndef __APPLE__
19
20 static int search(const char *haystack, const char *needle)
21 {
22     const char *c;
23
24     for (; *haystack; haystack++)
25     {
26         for (c = needle; *c && *haystack; c++, haystack++)
27             if (*c != *haystack)
28                 break;
29
30         if ((*c == 0) && (*haystack == ' ' || *haystack == '\0'))
31             return 1;
32     }
33
34     return 0;
35 }
36
37 #endif
38 /*---------------------------------------------------------------------------*/
39 #ifdef __linux__
40
41 #include <GL/glx.h>
42
43 void sync_init(void)
44 {
45     Display *dpy = glXGetCurrentDisplay();
46     int      scr = DefaultScreen(dpy);
47
48     PFNGLXSWAPINTERVALSGIPROC _glXSwapInvervalSGI = NULL;
49
50     if (search(glXQueryExtensionsString(dpy, scr), "GLX_SGI_swap_control"))
51     {
52         if ((_glXSwapInvervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
53              glXGetProcAddress((const GLubyte *) "glXSwapIntervalSGI")))
54             _glXSwapInvervalSGI(1);
55     }
56 }
57
58 #endif
59 /*---------------------------------------------------------------------------*/
60 #ifdef _WIN32
61
62 void sync_init(void)
63 {
64 /* TODO: Sit down at a Windows machine and make this work.
65     PFNWGLSWAPINTERVALEXTPROC _wglSwapInvervalEXT = NULL;
66
67     if (search(wglGetExtensionsString(), "WGL_EXT_swap_control"))
68     {
69         if ((_wglSwapInvervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
70              wglGetProcAddress((const GLubyte *) "wglSwapIntervalEXT")))
71             _wglSwapInvervalEXT(1);
72     }
73 */
74 }
75
76 #endif
77 /*---------------------------------------------------------------------------*/
78 #ifdef __APPLE__
79
80 #include <OpenGL/OpenGL.h>
81
82 void sync_init(void)
83 {
84     long swap = 1;
85     CGLSetParameter(CGLGetCurrentContext(),  kCGLCPSwapInterval, &swap);
86 }
87
88 #endif
89 /*---------------------------------------------------------------------------*/