share/sync: revive (as a fallback)
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 11 Oct 2009 11:37:59 +0000 (11:37 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 11 Oct 2009 11:37:59 +0000 (11:37 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@3096 78b8d119-cf0a-0410-b17c-f493084dd1d7

Makefile
share/sync.c [new file with mode: 0644]
share/sync.h [new file with mode: 0644]
share/video.c

index 444b94c..b45bcb0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -208,6 +208,7 @@ BALL_OBJS := \
        share/fs_jpg.o      \
        share/fs_rwops.o    \
        share/fs_ov.o       \
+       share/sync.o        \
        ball/hud.o          \
        ball/game_common.o  \
        ball/game_client.o  \
@@ -270,6 +271,7 @@ PUTT_OBJS := \
        share/fs_ov.o       \
        share/dir.o         \
        share/array.o       \
+       share/sync.o        \
        putt/hud.o          \
        putt/game.o         \
        putt/hole.o         \
diff --git a/share/sync.c b/share/sync.c
new file mode 100644 (file)
index 0000000..9a34825
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2003 Robert Kooima
+ *
+ * NEVERBALL is  free software; you can redistribute  it and/or modify
+ * it under the  terms of the GNU General  Public License as published
+ * by the Free  Software Foundation; either version 2  of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
+ * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
+ * General Public License for more details.
+ */
+
+#include <SDL_syswm.h>
+#include "glext.h"
+
+/*---------------------------------------------------------------------------*/
+#if defined(_WIN32)
+
+void sync_init(void)
+{
+    return;
+}
+
+/*---------------------------------------------------------------------------*/
+#elif defined(__APPLE__)
+
+#include <OpenGL/OpenGL.h>
+
+void sync_init(void)
+{
+    long swap = 1;
+    CGLSetParameter(CGLGetCurrentContext(),  kCGLCPSwapInterval, &swap);
+}
+
+/*---------------------------------------------------------------------------*/
+#elif SDL_VIDEO_DRIVER_X11
+
+#include <GL/glx.h>
+
+static int search(const char *haystack, const char *needle)
+{
+    const char *c;
+
+    for (; *haystack; haystack++)
+    {
+        for (c = needle; *c && *haystack; c++, haystack++)
+            if (*c != *haystack)
+                break;
+
+        if ((*c == 0) && (*haystack == ' ' || *haystack == '\0'))
+            return 1;
+    }
+
+    return 0;
+}
+
+void sync_init(void)
+{
+    SDL_SysWMinfo info;
+    Display *dpy;
+
+    SDL_VERSION(&info.version);
+
+    if (SDL_GetWMInfo(&info) != 1)
+        return;
+
+    if (info.subsystem != SDL_SYSWM_X11)
+        return;
+
+    dpy = info.info.x11.display;
+
+    info.info.x11.lock_func();
+    {
+        int scr = DefaultScreen(dpy);
+
+        PFNGLXSWAPINTERVALSGIPROC _glXSwapInvervalSGI = NULL;
+
+        if (search(glXQueryExtensionsString(dpy, scr), "GLX_SGI_swap_control"))
+        {
+            if ((_glXSwapInvervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
+                 glXGetProcAddress((const GLubyte *) "glXSwapIntervalSGI")))
+                _glXSwapInvervalSGI(1);
+        }
+    }
+    info.info.x11.unlock_func();
+}
+
+#endif
+
+/*---------------------------------------------------------------------------*/
diff --git a/share/sync.h b/share/sync.h
new file mode 100644 (file)
index 0000000..4afee01
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2003 Robert Kooima
+ *
+ * NEVERBALL is  free software; you can redistribute  it and/or modify
+ * it under the  terms of the GNU General  Public License as published
+ * by the Free  Software Foundation; either version 2  of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
+ * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
+ * General Public License for more details.
+ */
+
+#ifndef SYNC_H
+#define SYNC_H
+
+/*---------------------------------------------------------------------------*/
+
+void sync_init(void);
+
+/*---------------------------------------------------------------------------*/
+
+#endif
index 0e970d7..e1b3ec5 100644 (file)
@@ -17,6 +17,7 @@
 #include "glext.h"
 #include "config.h"
 #include "syswm.h"
+#include "sync.h"
 
 /*---------------------------------------------------------------------------*/
 
@@ -134,6 +135,11 @@ int video_mode(int f, int w, int h)
 
         glReadBuffer(GL_FRONT);
 
+        /* Attempt manual swap control if SDL's is broken. */
+
+        if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &vsync) == -1)
+            sync_init();
+
         return 1;
     }